Struct etherparse::Ipv6Slice
source · pub struct Ipv6Slice<'a> { /* private fields */ }
Expand description
Slice containing the IPv6 headers & payload.
Implementations§
source§impl<'a> Ipv6Slice<'a>
impl<'a> Ipv6Slice<'a>
sourcepub fn from_slice(slice: &'a [u8]) -> Result<Ipv6Slice<'a>, SliceError>
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.
sourcepub fn from_slice_lax(slice: &'a [u8]) -> Result<Ipv6Slice<'a>, SliceError>
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
.
sourcepub fn header(&self) -> Ipv6HeaderSlice<'a>
pub fn header(&self) -> Ipv6HeaderSlice<'a>
Returns a slice containing the IPv6 header.
sourcepub fn extensions(&self) -> &Ipv6ExtensionsSlice<'a>
pub fn extensions(&self) -> &Ipv6ExtensionsSlice<'a>
Returns a slice containing the IPv6 extension headers.
sourcepub fn payload(&self) -> &IpPayloadSlice<'a>
pub fn payload(&self) -> &IpPayloadSlice<'a>
Returns a slice containing the data after the IPv6 header and IPv6 extensions headers.
sourcepub fn is_payload_fragmented(&self) -> bool
pub fn is_payload_fragmented(&self) -> bool
Returns true if the payload is flagged as being fragmented.