Struct zero_packet::packet::parser::PacketParser

source ·
pub struct PacketParser<'a> {
    pub ethernet: Option<EthernetParser<'a>>,
    pub arp: Option<ArpParser<'a>>,
    pub ipv4: Option<IPv4Parser<'a>>,
    pub tcp: Option<TcpParser<'a>>,
    pub udp: Option<UdpParser<'a>>,
    pub icmp: Option<IcmpParser<'a>>,
}
Expand description

A zero-copy packet parser.

Fields§

§ethernet: Option<EthernetParser<'a>>§arp: Option<ArpParser<'a>>§ipv4: Option<IPv4Parser<'a>>§tcp: Option<TcpParser<'a>>§udp: Option<UdpParser<'a>>§icmp: Option<IcmpParser<'a>>

Implementations§

source§

impl<'a> PacketParser<'a>

source

pub fn parse(packet: &'a [u8]) -> Result<Self, &'static str>

Parses a raw Ethernet frame.

Is strict about what input it accepts.

source

pub fn parse_arp(&mut self, data: &'a [u8]) -> Result<(), &'static str>

Parses a ARP header.

ARP was originally designed for Ethernet, IPv4 and MAC addresses.

Theoretically, it can also be used with other combinations of protocols.

source

pub fn parse_ipv4(&mut self, data: &'a [u8]) -> Result<(), &'static str>

Parses a IPv4 header.

source

pub fn parse_icmp(&mut self, data: &'a [u8]) -> Result<(), &'static str>

Parses a ICMP packet.

source

pub fn parse_tcp(&mut self, data: &'a [u8]) -> Result<(), &'static str>

Parses a TCP header.

source

pub fn parse_udp(&mut self, data: &'a [u8]) -> Result<(), &'static str>

Parses a UDP header.

source

pub fn verify_checksums(&self) -> Result<(), &'static str>

Verifies the checksums of the headers.

source

pub fn header_len(&self) -> usize

Returns the total length of all headers.

Trait Implementations§

source§

impl<'a> Debug for PacketParser<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for PacketParser<'a>

§

impl<'a> RefUnwindSafe for PacketParser<'a>

§

impl<'a> Send for PacketParser<'a>

§

impl<'a> Sync for PacketParser<'a>

§

impl<'a> Unpin for PacketParser<'a>

§

impl<'a> UnwindSafe for PacketParser<'a>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.