Struct IPv4Reader

Source
pub struct IPv4Reader<'a> {
    pub bytes: &'a [u8],
}
Expand description

Reads IPv4 header fields.

Fields§

§bytes: &'a [u8]

Implementations§

Source§

impl<'a> IPv4Reader<'a>

Source

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

Creates a new IPv4Reader from the given slice.

Source

pub fn version(&self) -> u8

Returns the version field.

Source

pub fn ihl(&self) -> u8

Returns the IHL field.

Source

pub fn dscp(&self) -> u8

Returns the DSCP field.

Source

pub fn ecn(&self) -> u8

Returns the ECN field.

Source

pub fn total_length(&self) -> u16

Returns the total length field.

Includes the entire packet (header and payload).

Source

pub fn id(&self) -> u16

Returns the identification field.

Source

pub fn flags(&self) -> u8

Returns the flags field.

Source

pub fn fragment_offset(&self) -> u16

Returns the fragment offset field.

Source

pub fn ttl(&self) -> u8

Returns the TTL field.

Source

pub fn protocol(&self) -> u8

Returns the protocol field.

Source

pub fn src_ip(&self) -> &[u8]

Returns a reference to the source IP address field.

Source

pub fn dest_ip(&self) -> &[u8]

Returns a reference to the destination IP address field.

Source

pub fn checksum(&self) -> u16

Returns the checksum field.

Source

pub fn header_len(&self) -> usize

Returns the indicated header length in bytes.

Source

pub fn header(&self) -> Result<&'a [u8], &'static str>

Returns a reference to the header.

May fail if the indicated header length exceeds the allocated buffer.

Source

pub fn payload(&self) -> Result<&'a [u8], &'static str>

Returns a reference to the payload.

May fail if the indicated header length exceeds the allocated buffer.

Source

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

Verifies the checksum field.

Trait Implementations§

Source§

impl Debug for IPv4Reader<'_>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> ParseReader<'a> for IPv4Reader<'a>

Source§

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

Parses an IPv4 packet from a byte slice.

Validates the IPv4 version, header length, total length, and checksum fields.

Source§

impl<'a> PartialEq for IPv4Reader<'a>

Source§

fn eq(&self, other: &IPv4Reader<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> VerifyReader<'a> for IPv4Reader<'a>

Source§

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

Verifies the checksum of an encapsulated protocol in an IPv4 packet.

Computes the pseudo-header checksum and verifies it with the encapsulated payload.

Source§

impl<'a> StructuralPartialEq for IPv4Reader<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for IPv4Reader<'a>

§

impl<'a> RefUnwindSafe for IPv4Reader<'a>

§

impl<'a> Send for IPv4Reader<'a>

§

impl<'a> Sync for IPv4Reader<'a>

§

impl<'a> Unpin for IPv4Reader<'a>

§

impl<'a> UnwindSafe for IPv4Reader<'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>,

Source§

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

Source§

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.