| Description | The arp_cache_mac function determines whether the ARP table has an IP address entry for the requested MAC (ethernet) address. If an entry does not exist, the function forces the TCPnet system to resolve and cache the IP address into the internal ARP table buffer. To resolve the IP address, the TCPnet system sends an inverse arp request to the network. The argument hwadr points to a buffer containing the six octets of the MAC address to be resolved. The arp_cache_mac function is in the RL-TCPnet library. The prototype is defined in rtl.h. note - Only the ethernet network interface needs to use the arp_cache_mac function. There is no ARP protocol for the PPP and SLIP network interfaces.
|
| Example |
#include <Net_Config.h>
BOOL mac_cached;
void get_host_ip (void) {
static const U8 rem_MAC[6] = {0x00,0x11,0x43,0xA4,0xFE,0x40};
REMOTEM rm;
if (mac_cached == __TRUE) {
/* Done, host has been resolved. */
return;
}
if (arp_cache_mac (rem_MAC) == __FALSE) {
/* Wait, 'rem_MAC' address not resolved yet. */
return;
}
mac_cached == __TRUE;
/* OK get the IP address for 'rem_MAC'. */
mem_set (rm.IpAdr, 0, IP_ADRLEN);
mem_copy (rm.HwAdr, rem_MAC, ETH_ADRLEN);
arp_get_info (&rm);
printf ("IP address is %d.%d.%d.%d\n",rm.IpAdr[0],rm.IpAdr[1]
rm.IpAdr[2],rm.IpAdr[3]);
}
void main (void) {
/* Main Thread of the TCPnet */
init_TcpNet ();
mac_cached = __FALSE;
while (1) {
timer_poll ();
main_TcpNet ();
get_host_ip ();
}
}
|