|
NetBurner 3.5.8
PDF Version |
Address Resolution Protocol implementation and cache management. More...
Classes | |
| struct | ARP |
| Address Resolution Protocol packet structure. More... | |
Typedefs | |
| typedef ARP * | PARP |
| Pointer to ARP packet structure. | |
Functions | |
| void | ShowArp () |
| Display the current ARP cache contents to the standard output. | |
| void | fShowArp (FILE *fp) |
| Display the current ARP cache contents to a specified file stream. | |
| BOOL | GetArpMacFromIp (IPADDR4 ip, MACADR &ma) |
| Check if an IP address is in the ARP cache and retrieve its MAC address. | |
| void | sendGratuitousArp (int interfaceNumber, IPADDR4 ip) |
| Send a Gratuitous ARP to announce interface presence and IP address. | |
| BOOL | IsMyAddressUsedArpDetect (uint16_t timeout, int interface=0) |
| Detect if the interface's IP address is already in use on the network. | |
| int | GetProperInterface4 (IPADDR4 dst) |
| Get the appropriate network interface for routing to a destination IP. | |
| void | processArp (PoolPtr p, PEFRAME pF) |
| Process incoming ARP packets (internal use only). | |
| void | AddCheckArp (MACADR *ma, IPADDR4 ip, int ifnum) |
| Add or update ARP cache entry (internal use only). | |
| void | DeleteArpFromIp (IPADDR4 ip) |
| Delete ARP cache entry by IP address (internal use only). | |
| void | RouteOut (PEFRAME pf, IPADDR4 ip, PoolPtr p) |
| Route packet to destination (internal use only). | |
| void | RouteOutVia (PEFRAME pf, IPADDR4 ipfrom, IPADDR4 ipto, PoolPtr p, int intf) |
| Route packet via specific interface (internal use only). | |
| void | AgeArp () |
| Age out old ARP cache entries (internal use only). | |
| void | AddStaticArp (MACADR *ma, IPADDR4 ip, int ifnum) |
| Add static ARP entry (internal use only). | |
| void | InitializeArp () |
| Initialize ARP subsystem (internal use only). | |
Variables | |
| beuint16_t | ARP::hard_Type |
| Hardware type (1 for Ethernet). | |
| beuint16_t | ARP::prot_Type |
| Protocol type (0x0800 for IPv4). | |
| uint8_t | ARP::hard_size |
| Hardware address length (6 for MAC). | |
| uint8_t | ARP::prot_size |
| Protocol address length (4 for IPv4). | |
| beuint16_t | ARP::op_code |
| Operation: 1=Request, 2=Reply. | |
| MACADR | ARP::sender_phy |
| Sender MAC address. | |
| IPADDR4 | ARP::sender_Ip |
| Sender IP address. | |
| MACADR | ARP::target_phy |
| Target MAC address. | |
| IPADDR4 | ARP::target_Ip |
| Target IP address. | |
Address Resolution Protocol implementation and cache management.
#include< arp.h>
The Address Resolution Protocol (ARP) is a fundamental network protocol that maps Internet Protocol (IP) addresses to physical Media Access Control (MAC) addresses on local Ethernet networks. ARP enables devices to discover the hardware address of another device on the same network segment when only the IP address is known.
When a device needs to communicate with another device on the local network:
NetBurner maintains an ARP cache that stores recently resolved IP-to-MAC address mappings. This cache:
| Function | Purpose | Use Case |
|---|---|---|
| ShowArp() | Display cache | Debugging, diagnostics |
| GetArpMacFromIp() | Query cache | Check if address is resolved |
| sendGratuitousArp() | Announce presence | After IP change or boot |
| IsMyAddressUsedArpDetect() | Detect conflicts | IP conflict detection |
Device Not in Cache:
IP Address Conflict:
Stale Cache Entries:
| void fShowArp | ( | FILE * | fp | ) |
#include <arp.h>
Display the current ARP cache contents to a specified file stream.
Similar to ShowArp() but outputs to a specified FILE pointer instead of the standard output. This allows ARP cache contents to be written to:
| fp | Pointer to FILE stream for output. Must be a valid, open FILE pointer (from fopen(), fdopen(), etc.) |
#include <arp.h>
Check if an IP address is in the ARP cache and retrieve its MAC address.
Queries the local ARP cache to determine if a mapping exists for the specified IP address. If found, the corresponding MAC address is returned via the reference parameter.
This function ONLY checks the cache - it does not send ARP requests over the network. If the entry is not in the cache, you may need to send a packet (such as a ping) to the target IP to trigger ARP resolution first.
| ip | IP address to look up in the ARP cache | |
| [out] | ma | Reference to MACADR structure that will receive the MAC address if found. Only modified if the function returns TRUE. |
| int GetProperInterface4 | ( | IPADDR4 | dst | ) |
#include <arp.h>
Get the appropriate network interface for routing to a destination IP.
Determines which network interface should be used to reach a specific IPv4 destination address based on routing table and interface configuration.
| dst | Destination IPv4 address to route to |
| BOOL IsMyAddressUsedArpDetect | ( | uint16_t | timeout, |
| int | interface = 0 ) |
#include <arp.h>
Detect if the interface's IP address is already in use on the network.
Performs ARP-based IP address conflict detection by sending ARP probes and listening for replies. This is used to detect if another device on the network is already using the interface's configured IP address.
This function is critical for:
| timeout | Maximum time to wait for replies, in seconds. Typical values are 1-5 seconds. Longer timeouts provide more reliable detection but delay startup. |
| interface | Network interface number to check (default = 0 for primary interface). Use GetFirstInterface() for the default interface. |
| void sendGratuitousArp | ( | int | interfaceNumber, |
| IPADDR4 | ip ) |
#include <arp.h>
Send a Gratuitous ARP to announce interface presence and IP address.
Sends a gratuitous ARP request/reply to inform all devices on the local network about this interface's IP-to-MAC address mapping. This updates the ARP caches of all devices on the network segment.
Gratuitous ARP should be sent whenever:
| interfaceNumber | Network interface number (0 for primary interface, use GetFirstInterface() for the default interface) |
| ip | IP address to announce. Should be the interface's currently configured IP address. Must be a valid, non-zero IP address. |
| void ShowArp | ( | ) |
#include <arp.h>
Display the current ARP cache contents to the standard output.
Displays all entries in the ARP cache to the stdio serial port (typically the debug serial port). Each entry shows the IP address, MAC address, interface number, and entry status.
This function is useful for debugging network connectivity issues, verifying ARP resolution, and monitoring which devices are in the cache.
Where flags may be:
| uint8_t ARP::hard_size |
Hardware address length (6 for MAC).
Hardware address length (HLEN). For Ethernet (MAC) this is 6 bytes.
| beuint16_t ARP::hard_Type |
Hardware type (1 for Ethernet).
Hardware type (HTYPE). For Ethernet this is 1. Network byte order (big-endian).
| beuint16_t ARP::op_code |
| uint8_t ARP::prot_size |
Protocol address length (4 for IPv4).
Protocol address length (PLEN). For IPv4 this is 4 bytes.
| beuint16_t ARP::prot_Type |
Protocol type (0x0800 for IPv4).
Protocol type (PTYPE). For IPv4 this is 0x0800. Network byte order (big-endian).
| IPADDR4 ARP::sender_Ip |
Sender IP address.
Sender protocol (IP) address. The IPv4 address of the device sending this ARP packet.
| MACADR ARP::sender_phy |
Sender MAC address.
Sender hardware (MAC) address. The MAC address of the device sending this ARP packet.
| IPADDR4 ARP::target_Ip |
Target IP address.
Target protocol (IP) address. The IPv4 address being queried (in requests) or resolved (in replies).