Struct etherparse::Ipv6Header

source ·
pub struct Ipv6Header {
    pub traffic_class: u8,
    pub flow_label: Ipv6FlowLabel,
    pub payload_length: u16,
    pub next_header: IpNumber,
    pub hop_limit: u8,
    pub source: [u8; 16],
    pub destination: [u8; 16],
}
Expand description

IPv6 header according to rfc8200.

Fields§

§traffic_class: u8§flow_label: Ipv6FlowLabel

If non 0 serves as a hint to router and switches with multiple outbound paths that these packets should stay on the same path, so that they will not be reordered.

§payload_length: u16

The length of the payload and extension headers in bytes (0 in case of jumbo payloads).

§next_header: IpNumber

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

See IpNumber or ip_number for a definitions of ids.

§hop_limit: u8

The number of hops the packet can take before it is discarded.

§source: [u8; 16]

IPv6 source address

§destination: [u8; 16]

IPv6 destination address

Implementations§

source§

impl Ipv6Header

source

pub const LEN: usize = 40usize

Serialized size of an IPv6 header in bytes/octets.

source

pub const SERIALIZED_SIZE: usize = 40usize

👎Deprecated since 0.14.0: Use Ipv6Header::LEN instead
source

pub fn read_from_slice( slice: &[u8] ) -> Result<(Ipv6Header, &[u8]), HeaderSliceError>

👎Deprecated since 0.10.1: Renamed to Ipv6Header::from_slice

Renamed to Ipv6Header::from_slice

source

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

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

Note that this function DOES NOT seperate the payload based on the length payload_length present in the IPv6 header. It just returns the left over slice after the header.

If you want to have correctly seperated payload including the IP extension headers use

or

for a laxer version which falls back to slice length when the payload_length contains an inconsistent value.

source

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

Available on crate feature std only.

Reads an IPv6 header from the current position.

source

pub fn read_without_version<T: Read + Seek + Sized>( reader: &mut T, version_rest: u8 ) -> Result<Ipv6Header, Error>

Available on crate feature std only.

Reads an IPv6 header assuming the version & flow_label field have already been read.

source

pub fn skip_header_extension_in_slice( slice: &[u8], next_header: IpNumber ) -> Result<(IpNumber, &[u8]), LenError>

Takes a slice and skips an ipv6 header extensions and returns the next_header ip number & the slice past the header.

source

pub fn is_skippable_header_extension(ip_protocol_number: IpNumber) -> bool

Returns true if the given ip protocol number is a skippable header extension.

A skippable header extension is an extension header for which it is known how to determine the protocol number of the following header as well as how many octets have to be skipped to reach the start of the following header.

source

pub fn skip_all_header_extensions_in_slice( slice: &[u8], next_header: IpNumber ) -> Result<(IpNumber, &[u8]), LenError>

Takes a slice & ip protocol number (identifying the first header type) and returns next_header id & the slice past after all ipv6 header extensions.

source

pub fn skip_header_extension<T: Read + Seek + Sized>( reader: &mut T, next_header: IpNumber ) -> Result<IpNumber, Error>

Available on crate feature std only.

Skips the ipv6 header extension and returns the next ip protocol number

source

pub fn skip_all_header_extensions<T: Read + Seek + Sized>( reader: &mut T, next_header: IpNumber ) -> Result<IpNumber, Error>

Available on crate feature std only.

Skips all ipv6 header extensions and returns the next ip protocol number

source

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

Available on crate feature std only.

Writes a given IPv6 header to the current position.

source

pub fn source_addr(&self) -> Ipv6Addr

Available on crate feature std only.

Return the ipv6 source address as an std::net::Ipv6Addr

source

pub fn destination_addr(&self) -> Ipv6Addr

Available on crate feature std only.

Return the ipv6 destination address as an std::net::Ipv6Addr

source

pub fn header_len(&self) -> usize

Length of the serialized header in bytes.

The function always returns the constant Ipv6Header::LEN and exists to keep the methods consistent with other headers.

source

pub fn set_payload_length( &mut self, size: usize ) -> Result<(), ValueTooBigError<usize>>

Sets the field total_length based on the size of the payload and the options. Returns an error if the payload is too big to fit.

source

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

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

Trait Implementations§

source§

impl Clone for Ipv6Header

source§

fn clone(&self) -> Ipv6Header

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 Ipv6Header

source§

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

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

impl Default for Ipv6Header

source§

fn default() -> Ipv6Header

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

impl PartialEq for Ipv6Header

source§

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

source§

impl StructuralPartialEq for Ipv6Header

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.