#[repr(C)]pub struct ArpHdr {
pub htype: [u8; 2],
pub ptype: [u8; 2],
pub hlen: u8,
pub plen: u8,
pub oper: [u8; 2],
pub sha: [u8; 6],
pub spa: [u8; 4],
pub tha: [u8; 6],
pub tpa: [u8; 4],
}Expand description
Represents an Address Resolution Protocol (ARP) header.
The ARP header is typically found after the Ethernet header and is used to map a network protocol address (like an IPv4 address) to a hardware address (like a MAC address).
Fields§
§htype: [u8; 2]Hardware type (HTYPE): Specifies the network link protocol type. E.g., Ethernet is 1.
ptype: [u8; 2]Protocol type (PTYPE): Specifies the internetwork protocol for which the ARP request is intended. For IPv4, this has the value 0x0800.
hlen: u8Hardware address length (HLEN): Length in bytes of a hardware address. Ethernet addresses size is 6.
plen: u8Protocol address length (PLEN): Length in bytes of a logical address. IPv4 addresses size is 4.
oper: [u8; 2]Operation (OPER): Specifies the operation that the sender is performing: 1 for request, 2 for reply.
sha: [u8; 6]Sender hardware address (SHA): The hardware address of the sender.
spa: [u8; 4]Sender protocol address (SPA): The protocol address of the sender.
tha: [u8; 6]Target hardware address (THA): The hardware address of the intended receiver. This field is ignored in an ARP request.
tpa: [u8; 4]Target protocol address (TPA): The protocol address of the intended receiver.
Implementations§
Source§impl ArpHdr
impl ArpHdr
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new ArpHdr with all fields initialized to zero.
This is an alias for ArpHdr::default().
Sourcepub fn set_hlen(&mut self, hlen: u8)
pub fn set_hlen(&mut self, hlen: u8)
Sets the hardware address length field.
§Arguments
hlen- A u8 value for the hardware address length.
Sourcepub fn set_plen(&mut self, plen: u8)
pub fn set_plen(&mut self, plen: u8)
Sets the protocol address length field.
§Arguments
plen- A u8 value for the protocol address length.
Sourcepub fn set_oper(&mut self, oper: u16)
pub fn set_oper(&mut self, oper: u16)
Sets the operation field.
§Arguments
oper- A 2-byte array representing the operation (e.g., request or reply).
Sourcepub fn set_sha(&mut self, hardware_address: [u8; 6])
pub fn set_sha(&mut self, hardware_address: [u8; 6])
Sets the sender hardware address (SHA) field.
§Arguments
hardware_address- A 6-byte array representing the sender’s hardware address.
Sourcepub fn set_spa(&mut self, protocol_address: [u8; 4])
pub fn set_spa(&mut self, protocol_address: [u8; 4])
Sets the sender protocol address (SPA) field.
§Arguments
protocol_address- A 4-byte array representing the sender’s protocol address.