Doing ARP and Inverse ARP on Linux 2.6.21 (glibc 2.3.5)

mat_geek picture mat_geek · Jan 21, 2009 · Viewed 10.5k times · Source

I need to store persistent reference to third party device on an arbitrary IP network where the IP address of the devices may be static or randomly assigned by DHCP. I don't control the devices on the network and I can't rely on DNS and other ad-hoc networking protocols existing or working with the devices.

So I have been instructed to investigate using hardware addresses and ARP. This will work but I don't want to duplicate code. The kernel must manage an ARP table. On Windows you can access it using GetIpNetTable etc.

I am hoping there is an API to answer these two questions:

  • How do I translate from IP to MAC address? (ARP)
  • How do I translate from MAC to IP address? (InARP)

If not then I may have to do it more manually:

  • How do I read the kernel's ARP table?
  • How do I add an entry if I have the determined a mapping myself?

Answer

Khb picture Khb · Jan 21, 2009

/proc/net/arp

K