pub struct ArpPacket {
pub hw_addr_type: ArpHardwareId,
pub proto_addr_type: EtherType,
pub operation: ArpOperation,
/* private fields */
}
Expand description
“Address Resolution Protocol” Packet.
Fields§
§hw_addr_type: ArpHardwareId
Network link protocol type (e.g. ArpHardwareId::ETHERNET
).
proto_addr_type: EtherType
Protocol for which the ARP request is intended (e.g. EtherType::IPV4
).
operation: ArpOperation
Specifies the operation that the sender is performing
Implementations§
Source§impl ArpPacket
impl ArpPacket
Sourcepub const MAX_LEN: usize = 1_028usize
pub const MAX_LEN: usize = 1_028usize
Maximum length of an ARP packet in bytes/octets.
This number is calculated by taking the maximum values
that hw_addr_size
(255/u8::MAX) & proto_addr_size
(255/u8::MAX)
can take and calculate the maximum packet size from that.
Sourcepub const fn new(
hw_addr_type: ArpHardwareId,
proto_addr_type: EtherType,
operation: ArpOperation,
sender_hw_addr: &[u8],
sender_protocol_addr: &[u8],
target_hw_addr: &[u8],
target_protocol_addr: &[u8],
) -> Result<ArpPacket, ArpNewError>
pub const fn new( hw_addr_type: ArpHardwareId, proto_addr_type: EtherType, operation: ArpOperation, sender_hw_addr: &[u8], sender_protocol_addr: &[u8], target_hw_addr: &[u8], target_protocol_addr: &[u8], ) -> Result<ArpPacket, ArpNewError>
Create a new ARP packet with the given values.
Sourcepub const unsafe fn new_unchecked(
hw_addr_type: ArpHardwareId,
proto_addr_type: EtherType,
operation: ArpOperation,
sender_hw_addr: &[u8],
sender_protocol_addr: &[u8],
target_hw_addr: &[u8],
target_protocol_addr: &[u8],
) -> ArpPacket
pub const unsafe fn new_unchecked( hw_addr_type: ArpHardwareId, proto_addr_type: EtherType, operation: ArpOperation, sender_hw_addr: &[u8], sender_protocol_addr: &[u8], target_hw_addr: &[u8], target_protocol_addr: &[u8], ) -> ArpPacket
Create a new ARP packet with the given values without checking hardware & protocol address sizes.
§Safety
The caller must guarantee that
sender_hw_addr
&target_hw_addr
have the same length and the length must be smaller or equal than 255.sender_protocol_addr
&target_protocol_addr
have the same length and the length must be smaller or equal than 255.
The guarantees the caller must fulfill are equal to the following preconditions:
sender_hw_addr.len() == target_hw_addr.len()
sender_hw_addr.len() <= 255
target_hw_addr.len() <= 255
sender_protocol_addr.len() == target_protocol_addr.len()
sender_protocol_addr.len() <= 255
target_protocol_addr.len() <= 255
Sourcepub fn from_slice(slice: &[u8]) -> Result<ArpPacket, LenError>
pub fn from_slice(slice: &[u8]) -> Result<ArpPacket, LenError>
Reads an ARP packet from a slice.
Sourcepub const fn hw_addr_size(&self) -> u8
pub const fn hw_addr_size(&self) -> u8
Length (in octets) of a hardware address (e.g. 6 for Ethernet).
Sourcepub const fn protocol_addr_size(&self) -> u8
pub const fn protocol_addr_size(&self) -> u8
Length (in octets) of internetwork addresses (e.g. 4 for IPv4 or 16 for IPv6).
Sourcepub const fn sender_hw_addr(&self) -> &[u8] ⓘ
pub const fn sender_hw_addr(&self) -> &[u8] ⓘ
Sender hardware address (e.g. MAC address).
Sourcepub const fn sender_protocol_addr(&self) -> &[u8] ⓘ
pub const fn sender_protocol_addr(&self) -> &[u8] ⓘ
Sender protocol address (e.g. IPv4 address).
Sourcepub const fn target_hw_addr(&self) -> &[u8] ⓘ
pub const fn target_hw_addr(&self) -> &[u8] ⓘ
Target hardware address (e.g. MAC address).
Sourcepub const fn target_protocol_addr(&self) -> &[u8] ⓘ
pub const fn target_protocol_addr(&self) -> &[u8] ⓘ
Target protocol address (e.g. IPv4 address).
Sourcepub const fn set_hw_addrs(
&mut self,
sender_hw_addr: &[u8],
target_hw_addr: &[u8],
) -> Result<(), ArpHwAddrError>
pub const fn set_hw_addrs( &mut self, sender_hw_addr: &[u8], target_hw_addr: &[u8], ) -> Result<(), ArpHwAddrError>
Set the sender & target hardware addresses (e.g. MAC address).
Sourcepub const fn set_protocol_addrs(
&mut self,
sender_protocol_addr: &[u8],
target_protocol_addr: &[u8],
) -> Result<(), ArpProtoAddrError>
pub const fn set_protocol_addrs( &mut self, sender_protocol_addr: &[u8], target_protocol_addr: &[u8], ) -> Result<(), ArpProtoAddrError>
Set the sender & target protocol addresses (e.g. IPv4 address).
Sourcepub fn packet_len(&self) -> usize
pub fn packet_len(&self) -> usize
Serialized length of this ARP packet.
Sourcepub fn write<T: Write + Sized>(&self, writer: &mut T) -> Result<(), Error>
pub fn write<T: Write + Sized>(&self, writer: &mut T) -> Result<(), Error>
Writes the header to the given writer.
pub fn read<T: Read + Seek + Sized>(reader: &mut T) -> Result<ArpPacket, Error>
std
only.Sourcepub fn try_eth_ipv4(&self) -> Result<ArpEthIpv4Packet, ArpEthIpv4FromError>
pub fn try_eth_ipv4(&self) -> Result<ArpEthIpv4Packet, ArpEthIpv4FromError>
Returns an ArpEthIpv4Packet
if the current packet
is an ethernet & IPv4 ARP packet.