LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   How to specify ether type with raw socket (https://www.linuxquestions.org/questions/linux-networking-3/how-to-specify-ether-type-with-raw-socket-777221/)

sinacbe 12-21-2009 09:04 AM

How to specify ether type with raw socket
 
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


All times are GMT -5. The time now is 02:27 AM.