|
| arp_cache_ip| Summary | |
#include <rtl.h>
BOOL arp_cache_ip (
U8* ipadr, /* Pointer to buffer containing the 4 octets of the IP address. */
U8 type ); /* Specifies whether the IP address is fixed or temporary. */
| | Description | | The arp_cache_ip function determines whether the ARP table has a MAC (ethernet) address entry for the requested IP Address. If an entry does not exist, the function forces the TcpNet system to resolve and cache the MAC address into the internal ARP table buffer. The argument ipadr points to a buffer containing the four octets of the dotted decimal IP address to be resolved. The argument type specifies whether the IP address is fixed or temporary. This consequently determines whether or not the TcpNet system automatically refreshes the IP address entry in the ARP cache. | Type | Description |
|---|
| ARP_TEMP_IP | The IP address is temporary, and thus TCPnet removes the IP address entry from the ARP cache after a timeout. | | ARP_FIXED_IP | The IP address is fixed, and thus TCPnet's ARP module automatically refreshes the IP address entry after the timeout. |
The arp_cache_ip 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_ip function. There is no ARP protocol for the PPP and SLIP network interfaces.
- The arp_cache_ip function is primarily useful before sending the first UDP packet. The function is not necessary before sending TCP packets because the TCP module can retransmit the packet if the remote machine did not receive the packet.
| | Return Value | | The arp_cache_ip function returns __TRUE when both of the following conditions are satisfied:- The requested IP address is resolved.
- The ARP table contains an entry for the IP address and its MAC address.
Otherwise, the function returns __FALSE. | | Example | |
#include <rtl.h>
BOOL ip_cached;
void send_data (void) {
static const U8 rem_IP[4] = {192,168,0,100};
if (ip_cached == __FALSE) {
if (arp_cache_ip (rem_IP, ARP_FIXED_IP) == __FALSE) {
/* Wait, 'rem_IP' address not resolved yet. */
return;
}
ip_cached == __TRUE;
.
/* OK send UDP data packet here. */
.
}
}
void main (void) {
/* Main Thread of the TcpNet */
init_TcpNet ();
ip_cached = __FALSE;
while (1) {
timer_poll ();
main_TcpNet ();
send_data ();
}
}
|
|
|