Struct etherparse::Ipv6Slice

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

Slice containing the IPv6 headers & payload.

Implementations§

source§

impl<'a> Ipv6Slice<'a>

source

pub fn from_slice(slice: &'a [u8]) -> Result<Ipv6Slice<'a>, SliceError>

Separates and validates IPv6 headers (including extension headers) in the given slice and determine the sub-slice containing the payload of the IPv6 packet (based on the payload length value in the header).

Note that his function returns an crate::err::LenError if the given slice contains less data then the payload_len field in the IPv6 header indicates should be present.

If you want to ignore these kind of length errors based on the length fields in the IP headers use Ipv6Slice::from_slice_lax instead.

source

pub fn from_slice_lax(slice: &'a [u8]) -> Result<Ipv6Slice<'a>, SliceError>

Seperate an IPv6 header (+ extensions) & 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 crate::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 payload_length (in the IPv6 header) has 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 from_slice:

The main differences is that the function ignores inconsistent payload_length values (in IPv6 headers). 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 the len_source value in the returned IpPayloadSlice is set to LenSource::Slice. If a substitution was not needed len_source is set to LenSource::Ipv6HeaderPayloadLen.

§When is the slice length used as a fallback?

The slice length is used as a fallback/substitude if the payload_length field in the IPv6 header is

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

pub fn header(&self) -> Ipv6HeaderSlice<'a>

Returns a slice containing the IPv6 header.

source

pub fn extensions(&self) -> &Ipv6ExtensionsSlice<'a>

Returns a slice containing the IPv6 extension headers.

source

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

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

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 Ipv6Slice<'a>

source§

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

source§

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

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

impl<'a> From<Ipv6Slice<'a>> for IpSlice<'a>

source§

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

Converts to this type from the input type.
source§

impl<'a> From<Ipv6Slice<'a>> for NetSlice<'a>

source§

fn from(value: Ipv6Slice<'a>) -> NetSlice<'a>

Converts to this type from the input type.
source§

impl<'a> PartialEq for Ipv6Slice<'a>

source§

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

source§

impl<'a> StructuralPartialEq for Ipv6Slice<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Ipv6Slice<'a>

§

impl<'a> RefUnwindSafe for Ipv6Slice<'a>

§

impl<'a> Send for Ipv6Slice<'a>

§

impl<'a> Sync for Ipv6Slice<'a>

§

impl<'a> Unpin for Ipv6Slice<'a>

§

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