• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NDRV sockets and IP packets
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NDRV sockets and IP packets


  • Subject: NDRV sockets and IP packets
  • From: Johan Moreels <email@hidden>
  • Date: Fri, 7 Aug 2009 09:42:31 +0200

Hi,
we implement an experimental protocol on top of Ethernet that interworks with IP. In Linux we use raw sockets to capture and send packets on the network interface. In Mac OS X I try to use NDRV sockets to do the same. I use the following piece of code

...
    fd = socket(AF_NDRV, SOCK_RAW, 0); // Create RAW socket
    if (fd == -1)
      return errh->error("%s: socket: %s", ifname.c_str(), strerror(errno));

    sockaddr sa;

    memset(&sa, 0, sizeof(sa));
    sa.sa_family=AF_NDRV;
    strcpy(sa.sa_data,ifname.c_str());

    int res = bind(fd, (struct sockaddr *)&sa, sizeof(sa)); // Bind socket to interface
    if (res != 0) {
      close(fd);
      return errh->error("%s: bind: %s", ifname.c_str(), strerror(errno));
    }

    struct ndrv_protocol_desc SelectedPacketList; // Prepare list of Ethertypes we want to receive
    struct ndrv_demux_desc *pDesc;
    SelectedPacketList.version=NDRV_PROTOCOL_DESC_VERS;
    SelectedPacketList.protocol_family=NDRV_DEMUXTYPE_ETHERTYPE;
    SelectedPacketList.demux_count=3;

    pDesc=(struct ndrv_demux_desc *)malloc(3*sizeof(struct ndrv_demux_desc));
    if(pDesc == NULL)
      return errh->error("%s: Could not allocate memory for protocol: %s", ifname.c_str(), strerror(errno));

    SelectedPacketList.demux_list=pDesc;
    memset(pDesc, 0, 3*sizeof(struct ndrv_demux_desc));

    pDesc[0].type=NDRV_DEMUXTYPE_ETHERTYPE;
    pDesc[0].length=sizeof(pDesc[0].data.ether_type);
    pDesc[0].data.ether_type=htons(0x86a0);
    pDesc[1].type=NDRV_DEMUXTYPE_ETHERTYPE;
    pDesc[1].length=sizeof(pDesc[1].data.ether_type);
    pDesc[1].data.ether_type=htons(0x86a1);
    pDesc[2].type=NDRV_DEMUXTYPE_ETHERTYPE;
    pDesc[2].length=sizeof(pDesc[2].data.ether_type);
    pDesc[2].data.ether_type=htons(0x86a2);

    // Register wanted Ethertypes on the socket

    if(setsockopt(fd,SOL_NDRVPROTO,NDRV_SETDMXSPEC,&SelectedPacketList, sizeof(struct ndrv_protocol_desc)) < 0)
      return errh->error("%s: cannot specify protocol: %s",ifname.c_str(), strerror(errno));
...

This works for the ETHERTYPEs that are registered but no IP or ARP packets are received. However IP and ARP packets can be send out using this socket. 
I tried to add them in the filter I get an EBUSY error as a result of the setsockopt call.
What is wrong?

Johan
_____________________________
Johan Moreels
Senior Research Engineer
tel: (+32) 3 240 4210
gsm: (+32) 477 500088
e-mail: email@hidden

Alcatel-Lucent Bell N.V.
Bell Labs
Copernicuslaan 50
2018 Antwerpen
Belgium
Fortis 220-0002334-42
VAT BE 0404 621 642 Register of Legal Entities Antwerp

This message (including any attachments) contains confidential information intended for a specific individual and purpose, and is protected by law.  If you are not the intended recipient, you should delete this message.  Any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited without the prior consent of its author.





 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NDRV sockets and IP packets
      • From: Vincent Lubet <email@hidden>
  • Prev by Date: luanchd bonjour service advertising
  • Next by Date: Re: luanchd bonjour service advertising
  • Previous by thread: Re: luanchd bonjour service advertising
  • Next by thread: Re: NDRV sockets and IP packets
  • Index(es):
    • Date
    • Thread