Struct etherparse::Ipv4ExtensionsSlice
source · 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>
impl<'a> Ipv4ExtensionsSlice<'a>
sourcepub fn from_slice(
start_ip_number: IpNumber,
start_slice: &'a [u8]
) -> Result<(Ipv4ExtensionsSlice<'_>, IpNumber, &[u8]), HeaderSliceError>
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.
sourcepub fn from_slice_lax(
start_ip_number: IpNumber,
start_slice: &'a [u8]
) -> (Ipv4ExtensionsSlice<'_>, IpNumber, &[u8], Option<HeaderSliceError>)
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 headersIpNumber
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,
})));
sourcepub fn to_header(&self) -> Ipv4Extensions
pub fn to_header(&self) -> Ipv4Extensions
Convert the slices into actual headers.
Trait Implementations§
source§impl<'a> Clone for Ipv4ExtensionsSlice<'a>
impl<'a> Clone for Ipv4ExtensionsSlice<'a>
source§fn clone(&self) -> Ipv4ExtensionsSlice<'a>
fn clone(&self) -> Ipv4ExtensionsSlice<'a>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<'a> Debug for Ipv4ExtensionsSlice<'a>
impl<'a> Debug for Ipv4ExtensionsSlice<'a>
source§impl<'a> Default for Ipv4ExtensionsSlice<'a>
impl<'a> Default for Ipv4ExtensionsSlice<'a>
source§fn default() -> Ipv4ExtensionsSlice<'a>
fn default() -> Ipv4ExtensionsSlice<'a>
Returns the “default value” for a type. Read more
source§impl<'a> PartialEq for Ipv4ExtensionsSlice<'a>
impl<'a> PartialEq for Ipv4ExtensionsSlice<'a>
source§fn eq(&self, other: &Ipv4ExtensionsSlice<'a>) -> bool
fn eq(&self, other: &Ipv4ExtensionsSlice<'a>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl<'a> Copy for Ipv4ExtensionsSlice<'a>
impl<'a> Eq for Ipv4ExtensionsSlice<'a>
impl<'a> StructuralPartialEq for Ipv4ExtensionsSlice<'a>
Auto Trait Implementations§
impl<'a> Freeze for Ipv4ExtensionsSlice<'a>
impl<'a> RefUnwindSafe for Ipv4ExtensionsSlice<'a>
impl<'a> Send for Ipv4ExtensionsSlice<'a>
impl<'a> Sync for Ipv4ExtensionsSlice<'a>
impl<'a> Unpin for Ipv4ExtensionsSlice<'a>
impl<'a> UnwindSafe for Ipv4ExtensionsSlice<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more