Problem with ioctl(...) & raw socket???

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm trying to use the code fragment below in a simple experiment to
attach a raw socket to a network device (card) and read the incoming
MAC packets (frames).  But all I get is: Line: 41, Error: Invalid
argument, on the call to ioctl(...).  I assume this is in reference to
the request argument: SIOCSIFNAME.  Having looked thru
/usr/include/bits/ioctls.h there doesn't appear to be a valid
alternative (even though I've tried quite a few with the same result).


Thanks, John


struct ifreq ifrequest;

    if ( sock = socket( PF_PACKET, SOCK_RAW, htons( ETH_P_IP ) ) == -1)
        fprintf( stderr, "Line: %i, Error: %s\n", __LINE__, strerror(
        return -1;

/* binding device to raw socket */
    strncpy( ifrequest.ifr_name, "eth0", sizeof( ifrequest.ifr_name ));

    if ( ioctl( sock, SIOCSIFNAME, &ifrequest  ) == -1)
        fprintf( stderr, "Line: %i, Error: %s\n", __LINE__, strerror(
        return -1;

Re: Problem with ioctl(...) & raw socket???

instead of SIOCSIFNAME use SIOCGIFFLAGS to get the interface flags.
to set interface flags use SIOCSIFFLAGS
check up this link..

Site Timeline