EthHdr

Struct EthHdr 

Source
#[repr(C, packed(1))]
pub struct EthHdr { pub dst_addr: [u8; 6], pub src_addr: [u8; 6], pub ether_type: u16, }
Expand description

Ethernet header structure that appears at the beginning of every Ethernet frame. This structure represents the standard IEEE 802.3 Ethernet header format.

Fields§

§dst_addr: [u8; 6]

Destination MAC address.

§src_addr: [u8; 6]

Source MAC address.

§ether_type: u16

Protocol which is encapsulated in the payload of the frame. Indicates what type of data follows the Ethernet header (e.g., IPv4, IPv6, ARP)

Implementations§

Source§

impl EthHdr

Source

pub const LEN: usize = 14usize

Source

pub fn ether_type(&self) -> Result<EtherType, u16>

Attempts to convert the raw ether_type field into an EtherType enum. Returns either the corresponding EtherType variant or the raw value if unknown.

§Returns
  • Ok(EtherType) if a known protocol type
  • Err(u16) if an unknown protocol type (returns the raw value)
Source

pub fn new(dst_addr: [u8; 6], src_addr: [u8; 6], eth_type: EtherType) -> Self

Creates a new Ethernet header with the specified addresses and protocol type

§Parameters
  • dst_addr: The destination MAC address
  • src_addr: The source MAC address
  • ether_type_enum: The protocol type encapsulated in the payload
§Returns

A new EthHdr structure initialized with the given values

Trait Implementations§

Source§

impl Clone for EthHdr

Source§

fn clone(&self) -> EthHdr

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 EthHdr

Source§

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

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

impl Copy for EthHdr

Auto Trait Implementations§

§

impl Freeze for EthHdr

§

impl RefUnwindSafe for EthHdr

§

impl Send for EthHdr

§

impl Sync for EthHdr

§

impl Unpin for EthHdr

§

impl UnwindSafe for EthHdr

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.