Struct etherparse::LaxIpv4Slice

source ·
pub struct LaxIpv4Slice<'a> { /* private fields */ }
Expand description

Slice containing laxly separated IPv4 headers & payload.

Compared to the normal Ipv4Slice this slice allows the payload to be incomplete/cut off and errors to be present in the IpPayload.

The main usecases for “laxly” parsed slices are are:

  • Parsing packets that have been cut off. This is, for example, useful to parse packets returned via ICMP as these usually only contain the start.
  • Parsing packets where the total_len (for IPv4) have not yet been set. This can be useful when parsing packets which have been recorded in a layer before the length field was set (e.g. before the operating system set the length fields).

Implementations§

source§

impl<'a> LaxIpv4Slice<'a>

source

pub fn from_slice( slice: &[u8] ) -> Result<(LaxIpv4Slice<'_>, Option<HeaderSliceError>), HeaderSliceError>

Separates and validates IPv4 headers (including extension headers) & the payload from the given slice with less strict length checks (useful for cut off packet or for packets with unset length fields).

If you want to only receive correct IpPayloads use Ipv4Slice::from_slice instead.

The main usecases for this functions are:

  • Parsing packets that have been cut off. This is, for example, useful to parse packets returned via ICMP as these usually only contain the start.
  • Parsing packets where the total_len (for IPv4) have not yet been set. This can be useful when parsing packets which have been recorded in a layer before the length field was set (e.g. before the operating system set the length fields).
§Differences to Ipv4Slice::from_slice:

There are two main differences:

  • Errors in the expansion headers will only stop the parsing and return an Ok with the successfully parsed parts and the error as optional. Only if an unrecoverable error is encountered in the IP header itself an Err is returned. In the normal Ipv4Slice::from_slice function an Err is returned if an error is encountered in an exteions header.
  • LaxIpv4Slice::from_slice ignores inconsistent total_len values. When the total_len value in the IPv4 header are inconsistant the length of the given slice is used as a substitute.
§What happens in the total_len value is inconsistent?

When the total_length value in the IPv4 header is inconsistent the length of the given slice is used as a substitute. This can happen if the total_length field in the IPv4 header is:

  • Bigger then the given slice (payload cannot fully be seperated).
  • Too small to contain at least the IPv4 header.

Additionally you can check if more data was expected based on the total_len but the given slice was too small by checking if incomplete is set to true in the returned LaxIpPayloadSlice.

You can check if the slice length was used as a substitude by checking if the len_source value in the returned LaxIpPayloadSlice is set to LenSource::Slice. If a substitution was not needed len_source is set to LenSource::Ipv4HeaderTotalLen.

source

pub fn header(&self) -> Ipv4HeaderSlice<'_>

Returns a slice containing the IPv4 header.

source

pub fn extensions(&self) -> Ipv4ExtensionsSlice<'_>

Returns a slice containing the IPv4 extension headers.

source

pub fn payload(&self) -> &LaxIpPayloadSlice<'a>

Returns a slice containing the data after the IPv4 header and IPv4 extensions headers.

source

pub fn payload_ip_number(&self) -> IpNumber

Returns the ip number the type of payload of the IPv4 packet.

This function returns the ip number stored in the last IPv4 header or extension header.

source

pub fn is_payload_fragmented(&self) -> bool

Returns true if the payload is flagged as being fragmented.

Trait Implementations§

source§

impl<'a> Clone for LaxIpv4Slice<'a>

source§

fn clone(&self) -> LaxIpv4Slice<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for LaxIpv4Slice<'a>

source§

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

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

impl<'a> From<LaxIpv4Slice<'a>> for LaxIpSlice<'a>

source§

fn from(value: LaxIpv4Slice<'a>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<LaxIpv4Slice<'a>> for LaxNetSlice<'a>

source§

fn from(value: LaxIpv4Slice<'a>) -> LaxNetSlice<'a>

Converts to this type from the input type.
source§

impl<'a> PartialEq for LaxIpv4Slice<'a>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Eq for LaxIpv4Slice<'a>

source§

impl<'a> StructuralPartialEq for LaxIpv4Slice<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for LaxIpv4Slice<'a>

§

impl<'a> RefUnwindSafe for LaxIpv4Slice<'a>

§

impl<'a> Send for LaxIpv4Slice<'a>

§

impl<'a> Sync for LaxIpv4Slice<'a>

§

impl<'a> Unpin for LaxIpv4Slice<'a>

§

impl<'a> UnwindSafe for LaxIpv4Slice<'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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.