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



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).

Suggestions?

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(
errno));
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(
errno));
return -1;
}

.



Relevant Pages