Struct ArpPacket

Source
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

Source

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.

Source

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.

Source

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
Source

pub fn from_slice(slice: &[u8]) -> Result<ArpPacket, LenError>

Reads an ARP packet from a slice.

Source

pub const fn hw_addr_size(&self) -> u8

Length (in octets) of a hardware address (e.g. 6 for Ethernet).

Source

pub const fn protocol_addr_size(&self) -> u8

Length (in octets) of internetwork addresses (e.g. 4 for IPv4 or 16 for IPv6).

Source

pub const fn sender_hw_addr(&self) -> &[u8]

Sender hardware address (e.g. MAC address).

Source

pub const fn sender_protocol_addr(&self) -> &[u8]

Sender protocol address (e.g. IPv4 address).

Source

pub const fn target_hw_addr(&self) -> &[u8]

Target hardware address (e.g. MAC address).

Source

pub const fn target_protocol_addr(&self) -> &[u8]

Target protocol address (e.g. IPv4 address).

Source

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).

Source

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).

Source

pub fn packet_len(&self) -> usize

Serialized length of this ARP packet.

Source

pub fn to_bytes(&self) -> ArrayVec<u8, { ArpPacket::MAX_LEN }>

Returns the serialized header.

Source

pub fn write<T: Write + Sized>(&self, writer: &mut T) -> Result<(), Error>

Writes the header to the given writer.

Source

pub fn read<T: Read + Seek + Sized>(reader: &mut T) -> Result<ArpPacket, Error>

Available on crate feature std only.
Source

pub fn try_eth_ipv4(&self) -> Result<ArpEthIpv4Packet, ArpEthIpv4FromError>

Returns an ArpEthIpv4Packet if the current packet is an ethernet & IPv4 ARP packet.

Trait Implementations§

Source§

impl Clone for ArpPacket

Source§

fn clone(&self) -> ArpPacket

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ArpPacket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<ArpEthIpv4Packet> for ArpPacket

Source§

fn from(value: ArpEthIpv4Packet) -> Self

Converts to this type from the input type.
Source§

impl From<ArpPacket> for NetHeaders

Source§

fn from(value: ArpPacket) -> Self

Converts to this type from the input type.
Source§

impl Hash for ArpPacket

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ArpPacket

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<ArpPacket> for ArpEthIpv4Packet

Source§

type Error = ArpEthIpv4FromError

The type returned in the event of a conversion error.
Source§

fn try_from(value: ArpPacket) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for ArpPacket

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.