Ethernet2Header

Struct Ethernet2Header 

Source
pub struct Ethernet2Header {
    pub dst: MACAddress,
    pub src: MACAddress,
    pub ether_type: EtherType,
}
Expand description

An EthernetII header as described in IEEE 802.3

use ethernet::Ethernet2Header;
use ether_type::EtherType;

let bytes = [
    0x00, 0x80, 0x41, 0xff, 0xf0, 0x0d, // dst
    0x00, 0x80, 0x41, 0xba, 0xbe, 0xff, // src
    0x86, 0xdd // EtherType
];
let eth2header = Ethernet2Header::from_fixed_bytes(bytes);
assert_eq!(eth2header, Ethernet2Header{
    dst: [0x00, 0x80, 0x41, 0xff, 0xf0, 0x0d].into(),
    src: [0x00, 0x80, 0x41, 0xba, 0xbe, 0xff].into(),
    ether_type: EtherType::IPv6
});
assert_eq!(eth2header.to_fixed_bytes(), bytes);

Fields§

§dst: MACAddress

Destination

§src: MACAddress

Source

§ether_type: EtherType

EtherType of the payload

Implementations§

Source§

impl Ethernet2Header

Source

pub const HEADER_LENGTH: usize = 14usize

The header length in bytes.

Useful if you want to define a fixed array.

Source

pub fn from_bytes(bytes: &[u8]) -> Option<Self>

Conveniece method, which calls scroll internally.

This method can only fail if the provided data was too short.

§Returns
  • Some If the data was long enough.
  • None If the data was too short.
Source

pub fn from_fixed_bytes(bytes: [u8; 14]) -> Self

Deserialize the struct from a fixed array.

Allows skipping internal checks.

Source

pub fn to_bytes(self, buf: &mut [u8]) -> Option<()>

Conveniece method, which calls scroll internally.

This method can only fail if the provided data was too short.

§Returns
  • Some If the buffer was long enough.
  • None If the buffer was too short.
Source

pub fn to_fixed_bytes(self) -> [u8; 14]

Serializes the struct into a fixed array.

This method is infallible.

Trait Implementations§

Source§

impl Clone for Ethernet2Header

Source§

fn clone(&self) -> Ethernet2Header

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 Ethernet2Header

Source§

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

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

impl PartialEq for Ethernet2Header

Source§

fn eq(&self, other: &Ethernet2Header) -> 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 SizeWith for Ethernet2Header

Source§

fn size_with(_ctx: &()) -> usize

Source§

impl TryFromCtx<'_> for Ethernet2Header

Source§

type Error = Error

Source§

fn try_from_ctx(from: &[u8], _ctx: ()) -> Result<(Self, usize), Self::Error>

Source§

impl TryIntoCtx for Ethernet2Header

Source§

type Error = Error

Source§

fn try_into_ctx(self, buf: &mut [u8], _ctx: ()) -> Result<usize, Self::Error>

Source§

impl Copy for Ethernet2Header

Source§

impl Eq for Ethernet2Header

Source§

impl StructuralPartialEq for Ethernet2Header

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.