Skip to main content

Packet

Trait Packet 

Source
pub trait Packet<'a> {
    // Required methods
    fn mbuf(&self) -> &Mbuf;
    fn header_len(&self) -> usize;
    fn next_header_offset(&self) -> usize;
    fn next_header(&self) -> Option<usize>;
    fn parse_from(outer: &'a impl Packet<'a>) -> Result<Self, PacketParseError>
       where Self: Sized;

    // Provided method
    fn parse_to<T: Packet<'a>>(&'a self) -> Result<T, PacketParseError>
       where Self: Sized { ... }
}
Expand description

Represents a single packet.

Required Methods§

Source

fn mbuf(&self) -> &Mbuf

Reference to the underlying packet buffer.

Source

fn header_len(&self) -> usize

Offset from the beginning of the header to the start of the payload.

Source

fn next_header_offset(&self) -> usize

Offset from the beginning of the packet buffer to the start of the payload.

Source

fn next_header(&self) -> Option<usize>

Next level IANA protocol number.

Source

fn parse_from(outer: &'a impl Packet<'a>) -> Result<Self, PacketParseError>
where Self: Sized,

Parses a Packet from the outer encapsulating Packet’s payload.

Provided Methods§

Source

fn parse_to<T: Packet<'a>>(&'a self) -> Result<T, PacketParseError>
where Self: Sized,

Parses the Packet’s payload as a new Packet of type T.

Returns the concrete PacketParseError if parsing fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<'a> Packet<'a> for Ethernet<'a>

Source§

impl<'a> Packet<'a> for Ipv4<'a>

Source§

impl<'a> Packet<'a> for Ipv6<'a>

Source§

impl<'a> Packet<'a> for Mbuf

Source§

impl<'a> Packet<'a> for Tcp<'a>

Source§

impl<'a> Packet<'a> for Udp<'a>