Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# ARP Protocol Library (arp.c)
[Network Library]

## Detailed Description

     #include "net/arp.h"

Description
  To send anything over ethernet (or most any other physical network) a packet must be addressed to a physical network node address, often called a MAC/hardware/ethernet address. This MAC address identifies a specific interface (like the ethernet card in your computer) on the network. ARP (Address Resolution Protocol) assists in mapping IP addresses to the MAC addresses required to actually get data to its destination. In other words, an IP address is not enough to send information over ethernet. You need the MAC address of the network interface/card that "owns" that IP address. ARP maintains a table mapping IP addresses to MAC addresses. This table can be filled by both listening to traffic on the network, as well as making specific ARP requests if an IP<->MAC mapping is not in the table.

Note:
  This code is currently below version 1.0, and therefore is considered to be lacking in some functionality or documentation, or may not be fully tested. Nonetheless, you can expect most functions to work.

## Defines
#define | ARP_TABLE_SIZE 8
#define | ARP_CACHE_TIME_TO_LIVE 100
## Functions
void | arpInit (void)
void | arpSetAddress (struct netEthAddr *myeth, uint32_t myip)
void | arpArpIn (unsigned int len, struct netEthArpHeader *packet)
void | arpIpIn (struct netEthIpHeader *packet)
void | arpIpOut (struct netEthIpHeader *packet, uint32_t phyDstIp)
void | arpTimer (void)
int | arpMatchIp (uint32_t ipaddr)
void | arpPrintHeader (struct netArpHeader *packet)
| Print diagnotic information about ARP packet.
void | arpPrintTable (void)
| Print diagnotic information about ARP cache.

## Function Documentation

void arpArpIn | ( | unsigned int | len,
|  | struct netEthArpHeader * | packet
| ) |

| Processes incoming ARP packets. This function is to be called when an ARP type packet has arrived over the network. If the packet type is an ARP request for us, an ARP reply will be generated and sent. Definition at line 54 of file arp.c.

void arpInit | ( | void |  | ) |

| Initialize ARP system. Clears ARP table and prepares it for use. This is typically done once at program initialization. Definition at line 36 of file arp.c.

void arpIpIn | ( | struct netEthIpHeader * | packet | ) |

| Process incoming IP packets to harvest IP<->MAC relationships. This function should be called when IP packets are received over the network. It does nothing more than harvest the IP<->MAC address relationships from the ethernet and IP header of the packet. The packet is not changed nor processed. Nothing is sent on the network. Use of this command is not required, but it is a good way to automatically fill the ARP table with information about nodes that are active on the network. Warning: On very busy or heavily populated netorks, this can quickly fill the ARP table with unnecessary entries, and/or cause some CPU load. Definition at line 92 of file arp.c.

void arpIpOut | ( | struct netEthIpHeader * | packet,
|  | uint32_t | phyDstIp
| ) |

| Process outgoing IP packet to fill in ethernet header information. To be sent on a network, an IP packet must have the correct ethernet header information appended to the front. This function will fill in this information. A physical destination IP address argument is needed to support sending to a gateway (i.e. when a packet is destined for a node that is not on this network, IP addressing is as usual, but we phyiscally send the packet to the gateway's ethernet address/interface). Warning: Technically, if an IP<->MAC address mapping is not in the ARP table, then the IP packet should be held while an ARP request is made, and the reply received. However, in single-threaded ram-limited embedded systems, such a holdup is unacceptable. This function instead sends the packet as an ethernet broadcast if a mapping cannot be found. Definition at line 124 of file arp.c.

int arpMatchIp | ( | uint32_t | ipaddr | ) |

| Check if this IP address is present in the ARP cache. Internal function. If IP address is found, function returns index of entry. If not found, returns -1. Definition at line 169 of file arp.c.

void arpSetAddress | ( | struct netEthAddr * | myeth,
|  | uint32_t | myip
| ) |

| Set IP and Ethernet hardware/MAC address. This must be done before valid replies can be generated for ARP requests. Typically done once at program initialization. Definition at line 47 of file arp.c.

void arpTimer | ( | void |  | ) |

| Periodic ARP cache maintenance. This function is to be called once per second and will slowly expire old ARP cache entries. Definition at line 156 of file arp.c.