*
* \note This ARP implementation only supports Ethernet.
*/
-
+
/**
* \file
* Implementation of the ARP Address Resolution Protocol.
uip_arp_timer(void)
{
struct arp_entry *tabptr = NULL;
-
+
++arptime;
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
tabptr = &arp_table[i];
/* Check if the source IP address of the incoming packet matches
the IP address in this ARP table entry. */
if(uip_ipaddr_cmp(ipaddr, &tabptr->ipaddr)) {
-
+
/* An old entry found, update this and return. */
memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
tabptr->time = arptime;
uip_arp_ipin(void)
{
uip_len -= sizeof(struct uip_eth_hdr);
-
+
/* Only insert/update an entry if the source IP address of the
incoming IP packet comes from a host on the local network. */
if((IPBUF->srcipaddr[0] & uip_netmask[0]) !=
return;
}
uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));
-
+
return;
}
#endif /* 0 */
return;
}
uip_len = 0;
-
+
switch(BUF->opcode) {
case HTONS(ARP_REQUEST):
/* ARP request. If it asked for our address, we send out a
table, since it is likely that we will do more communication
with this host in the future. */
uip_arp_update(&BUF->sipaddr, &BUF->shwaddr);
-
+
BUF->opcode = HTONS(ARP_REPLY);
memcpy(BUF->dhwaddr.addr, BUF->shwaddr.addr, 6);
memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);
-
+
uip_ipaddr_copy(&BUF->dipaddr, &BUF->sipaddr);
uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr);
uip_arp_out(void)
{
struct arp_entry *tabptr = NULL;
-
+
/* Find the destination IP address in the ARP table and construct
- the Ethernet header. If the destination IP addres isn't on the
+ the Ethernet header. If the destination IP address isn't on the
local network, we use the default router's IP address instead.
If not ARP table entry is found, we overwrite the original IP
/* Else, we use the destination IP address. */
uip_ipaddr_copy(&ipaddr, &IPBUF->destipaddr);
}
-
+
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
tabptr = &arp_table[i];
if(uip_ipaddr_cmp(&ipaddr, &tabptr->ipaddr)) {
memset(BUF->dhwaddr.addr, 0x00, 6);
memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
-
+
uip_ipaddr_copy(&BUF->dipaddr, &ipaddr);
uip_ipaddr_copy(&BUF->sipaddr, &uip_hostaddr);
BUF->opcode = HTONS(ARP_REQUEST); /* ARP request. */
BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];
-
+
uip_len = sizeof(struct arp_hdr);
return;
}
memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);
}
memcpy(IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
-
+
IPBUF->ethhdr.type = HTONS(UIP_ETHTYPE_IP);
uip_len += sizeof(struct uip_eth_hdr);
/** @} */
/** @} */
+