3

I am new to programming on the Mac. I want to always insure that all network interfaces managed by my program have an MAC address for the GW in the ARP cache. To do this, I want to programmatically send an ARP request to the GW if I detect it's MAC address is missing.

There doesn't seem to be support on Mac OS X for raw sockets on the AF_PACKET/PF_PACKET address family and protocol. Is there another way to do this in C++? For example, is there an API that can be used to send an ARP request?

Doug Richardson
  • 10,483
  • 6
  • 51
  • 77
SoquelDude
  • 111
  • 1
  • 5

1 Answers1

1

If you need to be sure that each host has the right ARP entry associated to the default gateway you can set a static ARP entry. A static ARP entry remain forever in the ARP table, therefore you don't need to send periodically ARP request.

arp -s "IP_GW" "MAC_GW" -i "DEVICE YOU WANT TO SET, E.G: en0"

Anyway you can send ARP request using the C library "libnet" (available also for Windows and Linux). This is a lower level library, you need to handle at byte level packets and their headers. To create an ARP request you have to use:

libnet_autobuild_arp()
libnet_autobuild_ethernet()

Here you can find a libnet tutorial.

Doug Richardson
  • 10,483
  • 6
  • 51
  • 77
alfogrillo
  • 519
  • 5
  • 15