diff --git a/src/include/netif/etharp.h b/src/include/netif/etharp.h index b918febe..dcccf6ba 100644 --- a/src/include/netif/etharp.h +++ b/src/include/netif/etharp.h @@ -198,6 +198,7 @@ struct etharp_q_entry { void etharp_tmr(void); s8_t etharp_find_addr(struct netif *netif, const ip4_addr_t *ipaddr, struct eth_addr **eth_ret, const ip4_addr_t **ip_ret); +u8_t etharp_get_entry(u8_t i, ip4_addr_t **ipaddr, struct netif **netif, struct eth_addr **eth_ret); err_t etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr); err_t etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q); err_t etharp_request(struct netif *netif, const ip4_addr_t *ipaddr); diff --git a/src/netif/etharp.c b/src/netif/etharp.c index 43fda673..7b062c9c 100644 --- a/src/netif/etharp.c +++ b/src/netif/etharp.c @@ -650,6 +650,32 @@ etharp_find_addr(struct netif *netif, const ip4_addr_t *ipaddr, return -1; } +/** + * Possibility to iterate over stable ARP table entries + * + * @param i entry number, 0 to ARP_TABLE_SIZE + * @param ipaddr return value: IP address + * @param netif return value: points to interface + * @param eth_ret return value: ETH address + * @return 1 on valid index, 0 otherwise + */ +u8_t +etharp_get_entry(u8_t i, ip4_addr_t **ipaddr, struct netif **netif, struct eth_addr **eth_ret) +{ + LWIP_ASSERT("ipaddr != NULL", ipaddr != NULL); + LWIP_ASSERT("netif != NULL", netif != NULL); + LWIP_ASSERT("eth_ret != NULL", eth_ret != NULL); + + if((i < ARP_TABLE_SIZE) && (arp_table[i].state >= ETHARP_STATE_STABLE)) { + *ipaddr = &arp_table[i].ipaddr; + *netif = arp_table[i].netif; + *eth_ret = &arp_table[i].ethaddr; + return 1; + } else { + return 0; + } +} + #if ETHARP_TRUST_IP_MAC /** * Updates the ARP table using the given IP packet.