Performing ARP and reverse ARP on Linux 2.6.21 (glibc 2.3.5)

I need to keep a permanent link to a third-party device on an arbitrary IP network, where the IP address of the devices can be statically or randomly assigned by DHCP. I do not control devices on the network, and I cannot rely on DNS or other ad-hoc network protocols that exist or work with devices.

Therefore, I was tasked with investigating the use of hardware addresses and ARP. This will work, but I do not want to duplicate the code. The kernel must manage the ARP table. On Windows, you can access it using GetIpNetTable , etc.

I hope 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 to read kernel ARP table?
  • How to add a record if I have defined the mapping myself?
+3
source share
3 answers

/ Proc / net / agr

TO

+1
source

ARP tables tend to be quite local and short-lived. If you study the protocol, real MAC addresses are usually provided only if this IP address is on the local subnet. Otherwise, the packet is redirected to the local router, which is then responsible for forwarding it.

"arp -g" Windows "arp -a" UNIX, , , , - , .

, DNS, , , .

"ARP" .

+1

ARP:
( "/usr/bin/arp -option_of_choice" ); , . - .

/usr/include/linux/sockios.h - SIOCGARP, SIOCDARP SIOCSARP. ioctls, ARP Linux. , ioctls fd. : SIOCGARP
, . , C.

RARP:
linux rarp: " . 2.3 ​​Linux       RARP. RARP- . ftp://ftp.demen-     tia.org/pub/net-tools "
rarpd .

+1
source

All Articles