ioctl() call with a raw socket???

Discussion in 'Linux Networking' started by john.chludzinski, Mar 29, 2006.

  1. 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;
    }
     
    john.chludzinski, Mar 29, 2006
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.