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

This is a discussion on Problem with ioctl(...) & raw socket??? - Security ; 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 ...

+ Reply to Thread
Results 1 to 2 of 2

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

  1. 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;
    }


  2. 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..
    http://www.zone-h.org/files/13/sniffer2.txt


+ Reply to Thread