Thread: Specific ether type with raw socket under linux

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    1

    Specific ether type with raw socket under linux

    Hello,
    I'm trying to specify ether type when opening a raw socket. I've already done it under Windows and MacOSX but dunno how to do it under Linux.
    Under MacOSX, I'm using:
    Code:
    struct ndrv_protocol_desc desc;
    struct ndrv_demux_desc demux_desc[1];
    
    /*... some code to create the socket and bind the socket to the selected network interface ...*/
    
    bzero(&desc, sizeof(desc));
    bzero(&demux_desc, sizeof(demux_desc));
    
    desc.version = NDRV_PROTOCOL_DESC_VERS;
    desc.protocol_family = NDRV_DEMUXTYPE_ETHERTYPE;
    desc.demux_count = (u_int32_t)1;
    desc.demux_list = (struct ndrv_demux_desc*)&demux_desc;
    
    demux_desc[0].type = NDRV_DEMUXTYPE_ETHERTYPE;
    demux_desc[0].length = sizeof(demux_desc[0].data.ether_type);
    demux_desc[0].data.ether_type = MY_ETHER_TYPE;
    if (setsockopt( fd, SOL_NDRVPROTO, NDRV_SETDMXSPEC, (caddr_t)&desc, sizeof(desc))) {
      /*failed, perform some cleanup and leave function*/
    }
    /*succeed, get mac address and other stuff then leave function*/
    What would be the equivalent under Linux ?

    Thanks,

    SinaC

  2. #2
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875

    ndrv.h?

    Mate this looks like something that is Apple-specific; I (and probably anybody) can get you there using BSD sockets (which AFAIK OS/X supports) and is more portable than the Apple-specific API it seems like you are using...Google for Beej's Networking how-to and you will find a method that will/should work on both platforms but probably not Windows w/o a lot of #ifdefs to block out the platform-specific code...but now we are talking about a whole other discipline in code, cross-platform development which could fill volumes...

    Peace and Happy Holidays...

    J.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to pass a matrix/array from main to a function
    By Inukami in forum C Programming
    Replies: 7
    Last Post: 12-09-2009, 09:03 PM
  2. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  3. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  4. Dynamic array of pointers
    By csisz3r in forum C Programming
    Replies: 8
    Last Post: 09-25-2005, 02:06 PM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM