The ARP protocol is documented in RFC 826, and is how an an IP number gets connected to the correct 48 bit hardware address. Most Operating Systems use the arp to manipulate the ARP table manually. For instance, it's possible to dump your machines ARP table using the -a. If you are finding that your tftpd sends packets to your client, but they never arrive, chances are your ARP table is missing an entry for your client.
To request the hardware ethernet address for a given IP number, an ARPOP_REQUEST is broadcast to the subnet. The reply comes from a machine that knows the hardware ethernet address for that IP nukber as an ARPOP_REPLY. This hardware ethernet address is then added to the internal ARP table maintained by Nilo.
Example 5-1. Arp Table
prompt> arp -a nilo.welcomehome.org (192.203.188.1) at 00:00:C0:A3:56:C7 [ether] on eth0 |
Example 5-2. ARP Request Packet Fields
typedef struct arprequest { u_int16_t hwtype; u_int16_t protocol; int8_t hwlen; int8_t protolen; u_int16_t opcode; u_int8_t shwaddr[6]; u_int8_t sipaddr[4]; u_int8_t thwaddr[6]; u_int8_t tipaddr[4]; } arp_t; |
These are the fields of the ARP packet.
This is a 16 bit value that represents the hardware type. This must be ARPHRD_ETHER. (value 0x1)
This is a 16 bit value that represents the protocol type. For Nilo, this must be set to ETHERTYPE_IP. (0x800)
This is an 8 bit value that represents the hardware address length. Currently for IP4, this must be 6.
This is an 8 bit value that represents the protocol address length. Currently for IP4, this must be 4.
This is a 16 bit value that represents the ARP opcode. Currently these are limited to ARPOP_REQUEST (0x1) and ARPOP_REPLY(0x2).
This is a 48 bit value that represents the sender's hardware address. In our case, this is Nilo's hardware address.
This is a 32 bit value that represents the sender's IP address.
This is a 48 bit value that represents the target's hardware address. The target in our case is the TFTP server.
This is a 32 bit value that represents the the target's IP address. The target in our case is the TFTP server.
The source file arp.c contains the functions for making ARP packets, and for manipulating Nilo's own internal ARP table.
This functions adds the hardware address to the specified ARP table entry. Proper values for the entry are, ARP_CLIENT, ARP_SERVER, and ARP_GATEWAY.
void
add_to_cache
(ip4_t
ipaddr, u_int8_t
hwaddr, enum arp_entry
entry);This is the IP number to add to Nilo's internal ARP table.
This is the 48 bit ethernet hardware number to add to Nilo's internal ARP table.
This is the entry index, and must be one of either ARP_CLIENT, ARP_SERVER, or ARP_GATEWAY.