Forum Discussion
Altera_Forum
Honored Contributor
13 years agoYou must force an MAC resolve first, this can be accomplished by sending an UDP or ICMP packet to the address you are trying to resolve. How we are doing this is by sending ping packets to the host we want to resolve.
Here is the peace of code we use to resolve the mac address of the destination: while (mac->mac == 0 && --nRetries)
{
// avoid context switching which could result in ARP entry cleanup and cause invalid data while memcoping
portENTER_CRITICAL();
// if result is positive we found a match
if (etharp_find_addr(netif_default, &ip_req, ð_mac, &ip_ret) >= 0)
memcpy(mac->bytes, eth_mac->addr, MAC_ADDRESS_SIZE);
// enable interrupts back on
portEXIT_CRITICAL();
// only sleep if we don't have a MAC yet
if (mac->mac == 0) {
lwip_ping_target_data(ipaddr, 1, 1, (u8_t*)"hello", (sizeof("hello") - 1));
Sleep(100);
}
}