LwIP ARP

Hello, I am trying to get MAC address from a known IP address device. LwIP allows to query the device for its address and then search the ARP table for particular address:

arp_query = etharp_query(&alteraTseNetif, &alteraTseNetif.gw, NULL); arp_find = etharp_find_addr(&alteraTseNetif, &alteraTseNetif.gw, &ret_eth_addr, &ret_ip_addr);

As You can see, I am trying to get the MAC address of my gateway. The first command sends gratuitous ARP, then ARP request and finaly, the stack receives ARP reply (returns ERR_OK, which means no errors) - everything is OK here.

Then I issue a search using etharp_find_addr(), which returns me -1. Let's check what's inside:

s8_t etharp_find_addr(struct netif *netif, ip_addr_t *ipaddr, struct eth_addr **eth_ret, ip_addr_t **ip_ret) {

s8_t i;

LWIP_ASSERT("eth_ret != NULL && ip_ret != NULL", eth_ret != NULL && ip_ret != NULL); LWIP_UNUSED_ARG(netif);

i = find_entry(ipaddr, ETHARP_FLAG_FIND_ONLY);

if((i >= 0) && arp_table[i].state == ETHARP_STATE_STABLE) { *eth_ret = &arp_table[i].ethaddr; *ip_ret = &arp_table[i].ipaddr; return i; } return -1; }

I see that I receive table index i=0, which is fine, but the table state is not ETHARP_STATE_STABLE. I've checked that no matter what I try, I always get ETHARP_STATE_PENDING, which returns me MAC 00:00:00:00:00:00.

How can I find the MAC address of the requested IP? I believe I am on the right way, but I don't know how to move state from pending to stable. Any ideas? Thank You.

Sincerely, Tomas Daujotas

Reply to
scrts
Loading thread data ...

Have you searched the lwIP mailing list archive? It is an extremely valuable resource for these matters, and the lwIP mailing list has lots of lwIP experts that would answer your question easily.

Regards, Richard.

  • formatting link
    Designed for Microcontrollers. More than 7000 downloads per month.
Reply to
FreeRTOS info

Yes, I did. I've also posted the same question there. However, I've just solved my dumb mistake by myself. It is required to run ethernetif_input() to process packets, since the ARP leaves the entry as pending waiting for reply. Reply is sent, but wasn't processed. The code should look like this: arp_query = etharp_query(&alteraTseNetif, &alteraTseNetif.gw, NULL); /* wait here some time for reply to be received */ arp_find = etharp_find_addr(&alteraTseNetif, &alteraTseNetif.gw, &ret_eth_addr, &ret_ip_addr);

I've placed arp_find into a while() keeping ethernetif_input() inside to process packets until reply is received and now everything works fine.

Reply to
scrts

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.