pub enum LaxIpSlice<'a> {
    Ipv4(LaxIpv4Slice<'a>),
    Ipv6(LaxIpv6Slice<'a>),
}
Expand description

Slice containing laxly separated IPv4 or IPv6 headers & payload.

Compared to the normal IpSlice 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) or payload_len (for IPv6) 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).

Variants§

§

Ipv4(LaxIpv4Slice<'a>)

The ipv4 header & the decoded extension headers.

§

Ipv6(LaxIpv6Slice<'a>)

The ipv6 header & the decoded extension headers.

Implementations§

source§

impl<'a> LaxIpSlice<'a>

source

pub fn ipv4(&self) -> Option<&LaxIpv4Slice<'_>>

Returns a reference to the Ipv4Slice if self is a IpSlice::Ipv4.

source

pub fn ipv6(&self) -> Option<&LaxIpv6Slice<'_>>

Returns a reference to the Ipv6Slice if self is a IpSlice::Ipv6.

source

pub fn is_fragmenting_payload(&self) -> bool

Returns true if the payload is fragmented.

source

pub fn source_addr(&self) -> IpAddr

Available on crate feature std only.

Return the source address as an std::net::Ipvddr (requires crate feature std).

source

pub fn destination_addr(&self) -> IpAddr

Available on crate feature std only.

Return the destination address as an std::net::IpAddr (requires crate feature std).

source

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

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

source

pub fn payload_ip_number(&self) -> IpNumber

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

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

source

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

Separates IP headers (include extension headers) & the IP payload from the given slice as far as possible without encountering an error and with less strict length checks. This function is usefull for cut off packet or for packets with unset length fields.

If you want to only receive correct IpPayloads use [IpSlice::from_ip_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) or payload_length (for IPv6) 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 IpSlice::from_slice:
  • 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 from_slice function an Err is returned if an error is encountered in an exteions header.
  • from_slice_lax ignores inconsistent total_len (in IPv4 headers) and inconsistent payload_length (in IPv6 headers) values. When these length values in the IP header are inconsistant the length of the given slice is used as a substitute.

You can check if the slice length was used as a substitude by checking if result.payload().len_source is set to LenSource::Slice. If a substitution was not needed len_source is set to LenSource::Ipv4HeaderTotalLen or LenSource::Ipv6HeaderPayloadLen.

§When is the slice length used as a fallback?

For IPv4 packets the slice length is used as a fallback/substitude 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.

For IPv6 packet the slice length is used as a fallback/substitude if the payload_length is

  • Bigger then the given slice (payload cannot fully be seperated).
  • The value 0.

Trait Implementations§

source§

impl<'a> Clone for LaxIpSlice<'a>

source§

fn clone(&self) -> LaxIpSlice<'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 LaxIpSlice<'a>

source§

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

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

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

source§

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

Converts to this type from the input type.
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<LaxIpv6Slice<'a>> for LaxIpSlice<'a>

source§

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

Converts to this type from the input type.
source§

impl<'a> PartialEq for LaxIpSlice<'a>

source§

fn eq(&self, other: &LaxIpSlice<'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 LaxIpSlice<'a>

source§

impl<'a> StructuralPartialEq for LaxIpSlice<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for LaxIpSlice<'a>

§

impl<'a> RefUnwindSafe for LaxIpSlice<'a>

§

impl<'a> Send for LaxIpSlice<'a>

§

impl<'a> Sync for LaxIpSlice<'a>

§

impl<'a> Unpin for LaxIpSlice<'a>

§

impl<'a> UnwindSafe for LaxIpSlice<'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.