Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question Problem with ioctl IFFFLAGS


    I am trying to get interface's flags .Have a problem with following code :
    Code:
    #define DEVICE             "eth0"
    
    s = socket(AF_PACKET, SOCK_RAW, ETH_P_ALL);
    
    struct ifreq _req;
    memset(&_req, 0 , sizeof(ifreq));
    
    strncpy(ifr.ifr_name, DEVICE, IFNAMSIZ);
    	if (ioctl(s, SIOCGIFINDEX, &ifr) == -1) {
    		perror("SIOCGIFINDEX");
    		exit(1);
    	}
    . After executing this , i dont get interface flags ,the DEVICE interface go to state down and doesnot work(*1) & i need to restart PC.

    (*1) - Doesnot work even after
    Code:
     sudo ifconfig eth0 up
    . What am i doing wrong. thx
    Last edited by xionovermazes; 09-02-2016 at 01:25 AM.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    14,038
    -->
    I see _req declared, but not ifr. In you strncpy() function, should you be using _req.ifr_name and &_req?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •