Struct Packet

Source
pub struct Packet<T: Payload> { /* private fields */ }
Expand description

A read/write wrapper around an Internet Protocol version 6 packet buffer.

Implementations§

Source§

impl<T: Payload> Packet<T>

Source

pub fn new_checked(buffer: T) -> Result<Packet<T>>

Shorthand for a combination of new_unchecked and check_len.

Source

pub fn get_ref(&self) -> &T

Get an immutable reference to the whole buffer.

Useful if the buffer is some other packet encapsulation.

Source

pub fn repr(&self) -> Repr

Get the repr of the packet header.

Source

pub fn new_unchecked(buffer: T, repr: Repr) -> Self

Create a new packet without checking the representation.

Misuse may lead to panics from out-of-bounds access or other subtle inconsistencies. Since the representation might not represent the actual content in the payload, this also might mean that seemingly inconsistent values are returned. The usage is still memory safe though.

Source

pub fn into_inner(self) -> T

Consume the packet, returning the underlying buffer.

Methods from Deref<Target = ipv6>§

Source

pub fn as_bytes(&self) -> &[u8]

View the packet as a raw byte slice.

Source

pub fn check_len(&self) -> Result<()>

Ensure that no accessor method will panic if called. Returns Err(Error::Truncated) if the buffer is too short.

The result of this check is invalidated by calling set_payload_len.

Source

pub fn header_len(&self) -> usize

Return the header length.

Source

pub fn version(&self) -> u8

Return the version field.

Source

pub fn traffic_class(&self) -> u8

Return the traffic class.

Source

pub fn flow_label(&self) -> u32

Return the flow label field.

Source

pub fn payload_len(&self) -> u16

Return the payload length field.

Source

pub fn total_len(&self) -> usize

Return the payload length added to the known header length.

Source

pub fn next_header(&self) -> Protocol

Return the next header field.

Source

pub fn hop_limit(&self) -> u8

Return the hop limit field.

Source

pub fn src_addr(&self) -> Address

Return the source address field.

Source

pub fn dst_addr(&self) -> Address

Return the destination address field.

Source

pub fn payload_slice(&self) -> &[u8]

Return a pointer to the payload.

Trait Implementations§

Source§

impl<T: Payload> AsRef<[u8]> for Packet<T>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Clone + Payload> Clone for Packet<T>

Source§

fn clone(&self) -> Packet<T>

Returns a duplicate 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<T: Debug + Payload> Debug for Packet<T>

Source§

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

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

impl<T: Payload> Deref for Packet<T>

Source§

type Target = ipv6

The resulting type after dereferencing.
Source§

fn deref(&self) -> &ipv6

Dereferences the value.
Source§

impl<T: Payload> Display for Packet<T>

Source§

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

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

impl<T: PartialEq + Payload> PartialEq for Packet<T>

Source§

fn eq(&self, other: &Packet<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Payload> Payload for Packet<T>

Source§

fn payload(&self) -> &payload

Get the bytes wrapped in the payload newtype.
Source§

impl<T: PayloadMut> PayloadMut for Packet<T>

Source§

fn payload_mut(&mut self) -> &mut payload

Retrieve the mutable, inner payload.
Source§

fn resize(&mut self, length: usize) -> Result<(), PayloadError>

Resize the payload. Read more
Source§

fn reframe(&mut self, reframe: Reframe) -> Result<(), PayloadError>

Resize the payload while keeping some data. Read more
Source§

impl<T: Payload> StructuralPartialEq for Packet<T>

Auto Trait Implementations§

§

impl<T> Freeze for Packet<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Packet<T>
where T: RefUnwindSafe,

§

impl<T> Send for Packet<T>
where T: Send,

§

impl<T> Sync for Packet<T>
where T: Sync,

§

impl<T> Unpin for Packet<T>
where T: Unpin,

§

impl<T> UnwindSafe for Packet<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> PayloadMutExt for T
where T: PayloadMut,

Source§

fn reframe_payload(&mut self, frame: ReframePayload) -> PayloadResult<()>

Reframe but keep the payload. Read more
Source§

fn memset(&mut self, offset: usize, length: usize, value: u8)

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.