Expand description
Address Resolution Protocol implementation for IPV4.
ARP is not a distinct network abstraction layer, but is still required for most networks to function because socket abstractions frequently require an ARP request and response to be completed before sending data even if the router is actually going to be handling the association between MAC addresses and IP addresses, so resolving the target’s MAC address is not explicitly necessary.
This is a noisy process, but on a statically-addressed network, it will ideally only occur once during network initialization or if a host resets its network drivers and needs to re-connect. In practice, most systems send out ARP requests periodically, with the period varying from seconds to hours.
This process is not useful on a statically-addressed network, but on a mixed statically-and-dynamically-addressed network, it can help in the case where the target device does exist on the network, but has not yet sent a packet and does not have an entry in the router/switch’s MAC address table. In that case, the broadcasted ARP request will still reach that device and produce a response, which will be noted by the router/switch and allow its MAC address table entry to be populated.
It can also be useful for networks with not-smart network switches where the hosts have to self-assemble the addressing space, because ARP allows each host on the network to poll the others to check if an address is already taken before assigning that address to itself. The success of that method requires that all devices on the network be configured to respond to ARP requests, or to listen for conflicts and resolve them proactively, which is not necessarily the case.
In any case, most network stacks that we might interact with seem to refuse to function without it.
use catnip::*;
let msg = ArpPayload::new(
MacAddr::new([1, 2, 3, 4, 5, 6]),
IpV4Addr::new([7, 8, 9, 10]),
MacAddr::new([11, 12, 13, 14, 15, 16]),
IpV4Addr::new([17, 18, 19, 20]),
ArpOperation::Request,
);
// Serialize
let bytes: [u8; ArpPayload::BYTE_LEN] = msg.to_be_bytes();
// Deserialize
let msg_parsed = ArpPayload::read_bytes(&bytes);
assert_eq!(msg, msg_parsed);Structs§
- ArpPayload
- An ARP request or response with IPV4 addresses and standard MAC addresses. Assumes 6-byte standard MAC addresses and 4-byte IPV4 addresses; this function can’t be as general as the parser. because we need to know the size of the output at compile time. See https://en.wikipedia.org/wiki/Address_Resolution_Protocol.
Enums§
- ArpOperation
- ARP request or response flag values
- Protocol
Type - Protocol Type flags are the same as EtherType but must be reimplemented to avoid run-time recursion. See https://en.wikipedia.org/wiki/EtherType.