c++cnetwork-programmingarplibnet

LibNet read ARP response?


Is it possible to read ARP responses with Libnet? I'm looking specifically for a cross-platform library to read ARP sockets written in C/C++ ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​


Solution

  • libnet is a library for portable packet construction and injection. The consumption and decapsulation has to be done elsewhere. I suggest libtrace or libpcap to help with that business.

    libnet is primarily useful if you want to build and inject ARP packets. To see how this is done, have a look at some sample ARP code. Additionally, once packets are snarfed from the wire/air/file, libnet can be helpful for its rolodex of portable packet header definitions. In your case, you'd want to have a look at struct libnet_arp_hdr. You can cast your captured packet into an ARP header by doing something like:

        ...
        struct libnet_arp_hdr *arp_h;
    
        buf = capturepacket();
        ...
        arp_h = (struct libnet_arp_hdr *)buf + LIBNET_ETH_H;
        ...
        switch (arp_h->ar_op)
        {
            case ARPOP_REQUEST:
                ...