pub struct Ipv4ExtensionsSlice<'a> {
    pub auth: Option<IpAuthHeaderSlice<'a>>,
}
Expand description

Slices of the IPv4 extension headers present after the ip header.

Currently supported:

  • Authentication Header

Currently not supported:

  • Encapsulating Security Payload Header (ESP)

Fields§

§auth: Option<IpAuthHeaderSlice<'a>>

Implementations§

source§

impl<'a> Ipv4ExtensionsSlice<'a>

source

pub fn from_slice( start_ip_number: IpNumber, start_slice: &'a [u8] ) -> Result<(Ipv4ExtensionsSlice<'_>, IpNumber, &[u8]), HeaderSliceError>

Read all known ipv4 extensions and return an Ipv4ExtensionSlices with the identified slices, the final ip number and a slice pointing to the non parsed data.

source

pub fn from_slice_lax( start_ip_number: IpNumber, start_slice: &'a [u8] ) -> (Ipv4ExtensionsSlice<'_>, IpNumber, &[u8], Option<HeaderSliceError>)

Collects all ipv4 extension headers in a slice until an error is encountered or a “non IP extension header” is found and returns the successfully parsed parts (+ the unparsed slice it’s IpNumber and the error if one occurred).

The returned values are

  • Ipv4ExtensionsSlice containing the successfully parsed IPv6 extension headers
  • IpNumber of unparsed data
  • Slice with unparsed data
  • Optional with error if there was an error wich stoped the parsing.
§Examples
use etherparse::{Ipv4ExtensionsSlice, IpAuthHeader, ip_number::{UDP, AUTHENTICATION_HEADER}};

let auth_header = IpAuthHeader::new(UDP, 0, 0, &[]).unwrap();
let data = auth_header.to_bytes();

let (ipv4_exts, next_ip_num, next_data, err) =
    Ipv4ExtensionsSlice::from_slice_lax(AUTHENTICATION_HEADER, &data);

// authentication header is separated and no error occurred
assert!(ipv4_exts.auth.is_some());
assert_eq!(next_ip_num, UDP);
assert_eq!(next_data, &[]);
assert!(err.is_none());

It is also ok to pass in a “non ip extension”:

use etherparse::{Ipv4ExtensionsSlice, ip_number::UDP};

let data = [0,1,2,3];
// passing a non "ip extension header" ip number
let (ipv4_exts, next_ip_num, next_data, err) =
    Ipv4ExtensionsSlice::from_slice_lax(UDP, &data);

// the original data gets returned as UDP is not a
// an IP extension header
assert!(ipv4_exts.is_empty());
assert_eq!(next_ip_num, UDP);
assert_eq!(next_data, &data);
// no errors gets triggered as the data is valid
assert!(err.is_none());

In case an error occurred the original data gets returned together with the error:

use etherparse::{
    Ipv4ExtensionsSlice,
    IpAuthHeader,
    ip_number::AUTHENTICATION_HEADER,
    LenSource,
    err::{ip_auth::HeaderSliceError::Len, LenError, Layer}
};

// providing not enough data
let (ipv4_exts, next_ip_num, next_data, err) =
    Ipv4ExtensionsSlice::from_slice_lax(AUTHENTICATION_HEADER, &[]);

// original data will be returned with no data parsed
assert!(ipv4_exts.is_empty());
assert_eq!(next_ip_num, AUTHENTICATION_HEADER);
assert_eq!(next_data, &[]);
// the error that stopped the parsing will also be returned
assert_eq!(err, Some(Len(LenError{
    required_len: IpAuthHeader::MIN_LEN,
    len: 0,
    len_source: LenSource::Slice,
    layer: Layer::IpAuthHeader,
    layer_start_offset: 0,
})));
source

pub fn to_header(&self) -> Ipv4Extensions

Convert the slices into actual headers.

source

pub fn is_empty(&self) -> bool

Returns true if no IPv4 extension header is present (all fields None).

Trait Implementations§

source§

impl<'a> Clone for Ipv4ExtensionsSlice<'a>

source§

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

source§

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

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

impl<'a> Default for Ipv4ExtensionsSlice<'a>

source§

fn default() -> Ipv4ExtensionsSlice<'a>

Returns the “default value” for a type. Read more
source§

impl<'a> PartialEq for Ipv4ExtensionsSlice<'a>

source§

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

source§

impl<'a> Eq for Ipv4ExtensionsSlice<'a>

source§

impl<'a> StructuralPartialEq for Ipv4ExtensionsSlice<'a>

Auto Trait Implementations§

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.