ArpHdr

Struct ArpHdr 

Source
#[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: u8

Hardware address length (HLEN): Length in bytes of a hardware address. Ethernet addresses size is 6.

§plen: u8

Protocol 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

Source

pub const LEN: usize = 28usize

The size of the ARP header in bytes.

Source

pub fn new() -> Self

Creates a new ArpHdr with all fields initialized to zero. This is an alias for ArpHdr::default().

Source

pub fn htype(&self) -> u16

Returns the hardware type field.

Source

pub fn set_htype(&mut self, htype: u16)

Sets the hardware type field.

§Arguments
  • htype - A 2-byte array representing the hardware type.
Source

pub fn ptype(&self) -> u16

Returns the protocol type field.

Source

pub fn set_ptype(&mut self, ptype: u16)

Sets the protocol type field.

§Arguments
  • ptype - A 2-byte array representing the protocol type.
Source

pub fn hlen(&self) -> u8

Returns the hardware address length field.

Source

pub fn set_hlen(&mut self, hlen: u8)

Sets the hardware address length field.

§Arguments
  • hlen - A u8 value for the hardware address length.
Source

pub fn plen(&self) -> u8

Returns the protocol address length field.

Source

pub fn set_plen(&mut self, plen: u8)

Sets the protocol address length field.

§Arguments
  • plen - A u8 value for the protocol address length.
Source

pub fn oper(&self) -> u16

Returns the operation field.

Source

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

pub fn sha(&self) -> [u8; 6]

Returns the sender hardware address (SHA) field.

Source

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

pub fn spa(&self) -> [u8; 4]

Returns the sender protocol address (SPA) field.

Source

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

pub fn tha(&self) -> [u8; 6]

Returns the target hardware address (THA) field.

Source

pub fn set_tha(&mut self, hardware_address: [u8; 6])

Sets the target hardware address (THA) field.

§Arguments
  • hardware_address - A 6-byte array representing the target’s hardware address.
Source

pub fn tpa(&self) -> [u8; 4]

Returns the target protocol address (TPA) field.

Source

pub fn set_tpa(&mut self, protocol_address: [u8; 4])

Sets the target protocol address (TPA) field.

§Arguments
  • protocol_address - A 4-byte array representing the target’s protocol address.

Trait Implementations§

Source§

impl Clone for ArpHdr

Source§

fn clone(&self) -> ArpHdr

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ArpHdr

Source§

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

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

impl Default for ArpHdr

Source§

fn default() -> ArpHdr

Returns the “default value” for a type. Read more
Source§

impl Copy for ArpHdr

Auto Trait Implementations§

§

impl Freeze for ArpHdr

§

impl RefUnwindSafe for ArpHdr

§

impl Send for ArpHdr

§

impl Sync for ArpHdr

§

impl Unpin for ArpHdr

§

impl UnwindSafe for ArpHdr

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