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: MACAddressDestination
src: MACAddressSource
ether_type: EtherTypeEtherType of the payload
Implementations§
Source§impl Ethernet2Header
impl Ethernet2Header
Sourcepub const HEADER_LENGTH: usize = 14usize
pub const HEADER_LENGTH: usize = 14usize
The header length in bytes.
Useful if you want to define a fixed array.
Sourcepub fn from_bytes(bytes: &[u8]) -> Option<Self>
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
SomeIf the data was long enough.NoneIf the data was too short.
Sourcepub fn from_fixed_bytes(bytes: [u8; 14]) -> Self
pub fn from_fixed_bytes(bytes: [u8; 14]) -> Self
Deserialize the struct from a fixed array.
Allows skipping internal checks.
Sourcepub fn to_bytes(self, buf: &mut [u8]) -> Option<()>
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
SomeIf the buffer was long enough.NoneIf the buffer was too short.
Sourcepub fn to_fixed_bytes(self) -> [u8; 14]
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
impl Clone for Ethernet2Header
Source§fn clone(&self) -> Ethernet2Header
fn clone(&self) -> Ethernet2Header
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Ethernet2Header
impl Debug for Ethernet2Header
Source§impl PartialEq for Ethernet2Header
impl PartialEq for Ethernet2Header
Source§impl TryFromCtx<'_> for Ethernet2Header
impl TryFromCtx<'_> for Ethernet2Header
Source§impl TryIntoCtx for Ethernet2Header
impl TryIntoCtx for Ethernet2Header
impl Copy for Ethernet2Header
impl Eq for Ethernet2Header
impl StructuralPartialEq for Ethernet2Header
Auto Trait Implementations§
impl Freeze for Ethernet2Header
impl RefUnwindSafe for Ethernet2Header
impl Send for Ethernet2Header
impl Sync for Ethernet2Header
impl Unpin for Ethernet2Header
impl UnwindSafe for Ethernet2Header
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more