Added etharp_find_addr(), finds eth/IP address pair by interface ptr and IP address.

This commit is contained in:
christiaans 2006-08-08 15:10:42 +00:00
parent 9b11c4670d
commit 469012b544
3 changed files with 47 additions and 0 deletions

View File

@ -26,6 +26,10 @@ HISTORY
* [Enter new changes just after this line - do not remove this line]
++ New features:
2006-08-08 Christiaan Simons
* etharp.{c,h}: added etharp_find_addr() to read
(stable) ethernet/IP address pair from ARP table
2006-07-14 Christiaan Simons
* mib_structs.c: added
@ -48,6 +52,9 @@ HISTORY
optional LWIP_PLATFORM_HTONS(), LWIP_PLATFORM_HTONL() macros.
++ Bug fixes:
2006-08-07 Christiaan Simons
* api_msg.c: Flushing TCP output in do_close() (bug #15926).
2006-06-27 Christiaan Simons
* api_msg.c: Applied patch for cold case (bug #11135).

View File

@ -113,8 +113,11 @@ PACK_STRUCT_END
#define ETHTYPE_ARP 0x0806
#define ETHTYPE_IP 0x0800
void etharp_init(void);
void etharp_tmr(void);
s8_t etharp_find_addr(struct netif *netif, struct ip_addr *ipaddr,
struct eth_addr **eth_ret, struct ip_addr **ip_ret);
void etharp_ip_input(struct netif *netif, struct pbuf *p);
void etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr,
struct pbuf *p);

View File

@ -98,6 +98,7 @@ struct etharp_entry {
struct eth_addr ethaddr;
enum etharp_state state;
u8_t ctime;
struct netif *netif;
};
static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}};
@ -124,6 +125,7 @@ etharp_init(void)
arp_table[i].p = NULL;
#endif
arp_table[i].ctime = 0;
arp_table[i].netif = NULL;
}
}
@ -378,6 +380,8 @@ update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *e
/* mark it stable */
arp_table[i].state = ETHARP_STATE_STABLE;
/* record network interface */
arp_table[i].netif = netif;
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: updating stable entry %"S16_F"\n", (s16_t)i));
/* update address */
@ -416,6 +420,39 @@ update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *e
return ERR_OK;
}
/**
* Finds (stable) ethernet/IP address pair from ARP table
* using interface and IP address index.
* @note the addresses in the ARP table are in network order!
*
* @param netif points to interface index
* @param ipaddr points to the (network order) IP address index
* @param eth_ret points to return pointer
* @param ip_ret points to return pointer
* @return table index if found, -1 otherwise
*/
s8_t
etharp_find_addr(struct netif *netif, struct ip_addr *ipaddr,
struct eth_addr **eth_ret, struct ip_addr **ip_ret)
{
s8_t i;
i = 0;
while (i < ARP_TABLE_SIZE)
{
if ((arp_table[i].state == ETHARP_STATE_STABLE) &&
(arp_table[i].netif == netif) &&
ip_addr_cmp(ipaddr, &arp_table[i].ipaddr) )
{
*eth_ret = &arp_table[i].ethaddr;
*ip_ret = &arp_table[i].ipaddr;
return i;
}
i++;
}
return -1;
}
/**
* Updates the ARP table using the given IP packet.
*