[][src]Struct jnet::ipv4::Packet

pub struct Packet<BUFFER, CHECKSUM> where
    BUFFER: AsSlice<Element = u8>, 
{ /* fields omitted */ }

IPv4 packet

Methods

impl<B> Packet<B, Valid> where
    B: AsSlice<Element = u8> + Truncate<u16>, 
[src]

pub fn parse(bytes: B) -> Result<Self, B>[src]

Parses bytes into an IPv4 packet

impl<B, C> Packet<B, C> where
    B: AsSlice<Element = u8>, 
[src]

pub fn get_version(&self) -> u8[src]

Returns the version field of the header

pub fn get_ihl(&self) -> u8[src]

Returns the IHL (Internet Header Length) field of the header

pub fn get_dscp(&self) -> u8[src]

Returns the DSCP (Differentiated Services Code Point) field of the header

pub fn get_ecn(&self) -> u8[src]

Returns the ECN (Explicit Congestion Notification) field of the header

pub fn get_total_length(&self) -> u16[src]

Returns the total length field of the header

pub fn len(&self) -> u16[src]

Returns the length (header + data) of this packet

This returns the same value as the get_total_length method

pub fn get_identification(&self) -> u16[src]

Returns the identification field of the header

pub fn get_df(&self) -> bool[src]

Returns the DF (Don't Fragment) field of the header

pub fn get_mf(&self) -> bool[src]

Returns the MF (More Fragments) field of the header

pub fn get_fragment_offset(&self) -> u16[src]

Returns the Fragment Offset field of the header

pub fn get_ttl(&self) -> u8[src]

Returns the TTL (Time To Live) field of the header

pub fn get_protocol(&self) -> Protocol[src]

Returns the protocol field of the header

pub fn get_source(&self) -> Addr[src]

Returns the Source (IP address) field of the header

pub fn get_destination(&self) -> Addr[src]

Returns the Destination (IP address) field of the header

pub fn header(&self) -> &[u8][src]

Immutable view into the header

pub fn payload(&self) -> &[u8][src]

Immutable view into the payload

pub fn as_bytes(&self) -> &[u8][src]

Returns the byte representation of this packet

impl<B, C> Packet<B, C> where
    B: AsSlice<Element = u8> + AsMutSlice<Element = u8>, 
[src]

pub fn payload_mut(&mut self) -> &mut [u8][src]

View into the payload

impl<B, C> Packet<B, C> where
    B: AsSlice<Element = u8> + IntoSliceFrom<u8>, 
[src]

pub fn into_payload(self) -> B::SliceFrom[src]

Returns the payload of this frame

impl<B> Packet<B, Invalid> where
    B: AsSlice<Element = u8> + AsMutSlice<Element = u8> + Truncate<u16>, 
[src]

pub fn new(buffer: B) -> Self[src]

Transforms the given buffer into an IPv4 packet

Most of the header will be filled with sensible defaults:

  • Version = 4
  • IHL = 5
  • DSCP = 0
  • ECN = 0
  • Total Length = buffer.len()
  • Identification = 0
  • DF = true
  • MF = false
  • Fragment Offset = 0
  • TTL = 64

The fields that are left unpopulated are:

  • Protocol
  • Checksum
  • Source
  • Destination

Panics

This constructor panics if

  • the given buffer is smaller than MIN_HEADER_SIZE
  • the packet would result in a packet length larger than u16::MAX.

pub fn echo_request<F>(&mut self, f: F) where
    F: FnOnce(&mut Message<&mut [u8], EchoRequest, Invalid>), 
[src]

Fills the payload with an Echo Request ICMP message

pub fn udp<F>(&mut self, f: F) where
    F: FnOnce(&mut Packet<&mut [u8]>), 
[src]

Fills the payload with an UDP packet

pub fn truncate(&mut self, len: u16)[src]

Truncates the payload to the specified length

impl<B> Packet<B, Valid> where
    B: AsSlice<Element = u8> + AsMutSlice<Element = u8> + Truncate<u16>, 
[src]

pub fn truncate(self, len: u16) -> Packet<B, Invalid>[src]

Truncates the payload to the specified length

impl<B> Packet<B, Invalid> where
    B: AsSlice<Element = u8> + AsMutSlice<Element = u8>, 
[src]

pub fn set_version(&mut self, version: u8)[src]

Sets the version field of the header

pub fn set_dscp(&mut self, dscp: u8)[src]

Sets the DSCP (Differentiated Services Code Point) field of the header

pub fn set_ecn(&mut self, ecn: u8)[src]

Sets the ECN (Explicit Congestion Notification) field of the header

pub fn set_identification(&mut self, id: u16)[src]

Sets the identification field of the header

pub fn set_df(&mut self, df: bool)[src]

Sets the DF (Don't Fragment) field of the header

pub fn set_mf(&mut self, mf: bool)[src]

Sets the MF (More Fragments) field of the header

pub fn set_fragment_offset(&mut self, fo: u16)[src]

Sets the Fragment Offset field of the header

pub fn set_ttl(&mut self, ttl: u8)[src]

Sets the TTL (Time To Live) field of the header

pub fn set_protocol(&mut self, proto: Protocol)[src]

Sets the Protocol field of the header

pub fn set_source(&mut self, addr: Addr)[src]

Sets the Source (IP address) field of the header

pub fn set_destination(&mut self, addr: Addr)[src]

Sets the Destination (IP address) field of the header

pub fn update_checksum(self) -> Packet<B, Valid>[src]

Updates the Checksum field of the header

impl<B> Packet<B, Valid> where
    B: AsSlice<Element = u8> + AsMutSlice<Element = u8>, 
[src]

pub fn set_version(self, version: u8) -> Packet<B, Invalid>[src]

Sets the version field of the header

pub fn set_dscp(self, dscp: u8) -> Packet<B, Invalid>[src]

Sets the DSCP (Differentiated Services Code Point) field of the header

pub fn set_ecn(self, ecn: u8) -> Packet<B, Invalid>[src]

Sets the ECN (Explicit Congestion Notification) field of the header

pub fn set_identification(self, id: u16) -> Packet<B, Invalid>[src]

Sets the identification field of the header

pub fn set_df(self, df: bool) -> Packet<B, Invalid>[src]

Sets the DF (Don't Fragment) field of the header

pub fn set_mf(self, mf: bool) -> Packet<B, Invalid>[src]

Sets the MF (More Fragments) field of the header

pub fn set_fragment_offset(self, fo: u16) -> Packet<B, Invalid>[src]

Sets the Fragment Offset field of the header

pub fn set_ttl(self, ttl: u8) -> Packet<B, Invalid>[src]

Sets the TTL (Time To Live) field of the header

pub fn set_protocol(self, proto: Protocol) -> Packet<B, Invalid>[src]

Sets the Protocol field of the header

pub fn set_source(self, addr: Addr) -> Packet<B, Invalid>[src]

Sets the Source (IP address) field of the header

pub fn set_destination(self, addr: Addr) -> Packet<B, Invalid>[src]

Sets the Destination (IP address) field of the header

Trait Implementations

impl<B, C> Debug for Packet<B, C> where
    B: AsSlice<Element = u8>, 
[src]

NOTE excludes the payload

Auto Trait Implementations

impl<BUFFER, CHECKSUM> Unpin for Packet<BUFFER, CHECKSUM> where
    BUFFER: Unpin,
    CHECKSUM: Unpin

impl<BUFFER, CHECKSUM> Send for Packet<BUFFER, CHECKSUM> where
    BUFFER: Send,
    CHECKSUM: Send

impl<BUFFER, CHECKSUM> Sync for Packet<BUFFER, CHECKSUM> where
    BUFFER: Sync,
    CHECKSUM: Sync

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T[src]

type Output = T

Should always be Self