[−][src]Struct jnet::ether::Frame
Layer 2 Ethernet frame
Structure
- MAC destination. 6 bytes
- MAC source. 6 bytes
- Ethertype. 2 bytes
- Payload. 46-1500 bytes (*)
- Frame check sequence. 4 bytes (*)
(*) This frame representation does NOT include the frame check sequence nor (zero) pads the payload to the minimum size of 46 bytes.
Methods
impl<B> Frame<B> where
B: AsSlice<Element = u8>,
[src]
B: AsSlice<Element = u8>,
pub fn new(buffer: B) -> Self
[src]
Creates a new Ethernet frame from the given buffer
pub fn parse(bytes: B) -> Result<Self, B>
[src]
Parses bytes into an Ethernet frame
pub fn get_destination(&self) -> Addr
[src]
Returns the Destination field of the header
pub fn get_source(&self) -> Addr
[src]
Returns the Source field of the header
pub fn get_type(&self) -> Type
[src]
Returns the Type field of the header
pub fn payload(&self) -> &[u8]
[src]
View into the payload
pub fn as_bytes(&self) -> &[u8]
[src]
Returns the byte representation of this frame
pub fn free(self) -> B
[src]
Frees the underlying buffer
pub fn len(&self) -> u16
[src]
Returns the length (header + data) of this frame
impl<B> Frame<B> where
B: AsSlice<Element = u8> + AsMutSlice<Element = u8>,
[src]
B: AsSlice<Element = u8> + AsMutSlice<Element = u8>,
pub fn set_destination(&mut self, addr: Addr)
[src]
Sets the destination field of the header
pub fn set_source(&mut self, addr: Addr)
[src]
Sets the source field of the header
pub fn set_type(&mut self, type_: Type)
[src]
Sets the type field of the header
pub fn payload_mut(&mut self) -> &mut [u8]
[src]
Mutable view into the payload
impl<B> Frame<B> where
B: AsSlice<Element = u8> + IntoSliceFrom<u8>,
[src]
B: AsSlice<Element = u8> + IntoSliceFrom<u8>,
pub fn into_payload(self) -> B::SliceFrom
[src]
Returns the payload of this frame
impl<B> Frame<B> where
B: AsSlice<Element = u8> + AsMutSlice<Element = u8> + Truncate<u8>,
[src]
B: AsSlice<Element = u8> + AsMutSlice<Element = u8> + Truncate<u8>,
pub fn arp<F>(&mut self, f: F) where
F: FnOnce(&mut Packet<&mut [u8]>),
[src]
F: FnOnce(&mut Packet<&mut [u8]>),
Fills the payload with an ARP packet
This method sets the Type field of this frame to ARP, and truncates the length of the frame to fit the ARP packet.
The ARP packet will have its SHA set to the Ethernet frame Source address
impl<B> Frame<B> where
B: AsSlice<Element = u8> + AsMutSlice<Element = u8> + Truncate<u16>,
[src]
B: AsSlice<Element = u8> + AsMutSlice<Element = u8> + Truncate<u16>,
pub fn ipv4<F>(&mut self, f: F) where
F: FnOnce(&mut Packet<&mut [u8], Invalid>),
[src]
F: FnOnce(&mut Packet<&mut [u8], Invalid>),
Fills the payload with an IPv4 packet
This method sets the Type field of this frame to IPv4, recomputes and updates the header checksum of the IPv4 payload, and truncates the length of the frame to fit the IPv4 packet.
pub fn ipv6<F>(&mut self, f: F) where
F: FnOnce(&mut Packet<&mut [u8]>),
[src]
F: FnOnce(&mut Packet<&mut [u8]>),
Fills the payload with an IPv6 packet
Trait Implementations
impl<B> Debug for Frame<B> where
B: AsSlice<Element = u8>,
[src]
B: AsSlice<Element = u8>,
NOTE excludes the payload
impl<BUFFER: Copy> Copy for Frame<BUFFER> where
BUFFER: AsSlice<Element = u8>,
[src]
BUFFER: AsSlice<Element = u8>,
impl<BUFFER: Clone> Clone for Frame<BUFFER> where
BUFFER: AsSlice<Element = u8>,
[src]
BUFFER: AsSlice<Element = u8>,
fn clone(&self) -> Frame<BUFFER>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Auto Trait Implementations
impl<BUFFER> Unpin for Frame<BUFFER> where
BUFFER: Unpin,
BUFFER: Unpin,
impl<BUFFER> Send for Frame<BUFFER> where
BUFFER: Send,
BUFFER: Send,
impl<BUFFER> Sync for Frame<BUFFER> where
BUFFER: Sync,
BUFFER: Sync,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self