pub struct Ipv6FragmentHeader {
    pub next_header: IpNumber,
    pub fragment_offset: IpFragOffset,
    pub more_fragments: bool,
    pub identification: u32,
}
Expand description

IPv6 fragment header.

Fields§

§next_header: IpNumber

IP protocol number specifying the next header or transport layer protocol.

See IpNumber or ip_number for a definition of the known values.

§fragment_offset: IpFragOffset

Offset of the current IP payload relative to the start of the fragmented packet payload.

§more_fragments: bool

True if more fragment packets will follow. False if this is the last packet.

§identification: u32

Identifcation value generated by the source.

Implementations§

source§

impl Ipv6FragmentHeader

source

pub const LEN: usize = 8usize

Length of the serialized header.

source

pub const fn new( next_header: IpNumber, fragment_offset: IpFragOffset, more_fragments: bool, identification: u32 ) -> Ipv6FragmentHeader

Create a new fragmentation header with the given parameters.

Note that the fragment_offset can only support values between 0 and 0x1fff (inclusive).

source

pub fn from_slice(slice: &[u8]) -> Result<(Ipv6FragmentHeader, &[u8]), LenError>

Read an Ipv6FragmentHeader from a slice and return the header & unused parts of the slice.

source

pub fn read<T: Read + Seek + Sized>( reader: &mut T ) -> Result<Ipv6FragmentHeader, Error>

Available on crate feature std only.

Read an fragment header from the current reader position.

source

pub fn read_limited<T: Read + Seek + Sized>( reader: &mut LimitedReader<T> ) -> Result<Ipv6FragmentHeader, LimitedReadError>

Available on crate feature std only.

Read an fragment header from the current reader position.

source

pub fn write<T: Write + Sized>(&self, writer: &mut T) -> Result<(), Error>

Available on crate feature std only.

Writes a given IPv6 fragment header to the current position.

source

pub fn header_len(&self) -> usize

Length of the header in bytes.

source

pub fn is_fragmenting_payload(&self) -> bool

Checks if the fragment header actually fragments the packet.

Returns false if the fragment offset is 0 and the more flag is not set. Otherwise returns true.

RFC8200 explicitly states that fragment headers that don’t fragment the packet payload are allowed. See the following quote from RFC8200 page 32:

Revised the text to handle the case of fragments that are whole datagrams (i.e., both the Fragment Offset field and the M flag are zero). If received, they should be processed as a reassembled packet. Any other fragments that match should be processed independently. The Fragment creation process was modified to not create whole datagram fragments (Fragment Offset field and the M flag are zero). See RFC6946 and RFC8021 for more information.“

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

// offset 0 & no more fragments result in an unfragmented payload
{
    let header = Ipv6FragmentHeader::new(UDP, 0.try_into().unwrap(), false, 123);
    assert!(false == header.is_fragmenting_payload());
}

// offset 0 & but more fragments will come -> fragmented
{
    let header = Ipv6FragmentHeader::new(UDP, 0.try_into().unwrap(), true, 123);
    assert!(header.is_fragmenting_payload());
}

// offset non zero & no more fragments will come -> fragmented
{
    let header = Ipv6FragmentHeader::new(UDP, 1.try_into().unwrap(), false, 123);
    assert!(header.is_fragmenting_payload());
}
source

pub fn to_bytes(&self) -> [u8; 8]

Returns the serialized form of the header as a statically sized byte array.

Trait Implementations§

source§

impl Clone for Ipv6FragmentHeader

source§

fn clone(&self) -> Ipv6FragmentHeader

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 Debug for Ipv6FragmentHeader

source§

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

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

impl PartialEq for Ipv6FragmentHeader

source§

fn eq(&self, other: &Ipv6FragmentHeader) -> 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 Eq for Ipv6FragmentHeader

source§

impl StructuralPartialEq for Ipv6FragmentHeader

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.