Skip to main content

Packet

Struct Packet 

Source
pub struct Packet { /* private fields */ }
Expand description

Ordered stack of packet layers.

Implementations§

Source§

impl Packet

Source

pub const fn new() -> Self

Create an empty packet.

Source

pub fn from_layer<L>(layer: L) -> Self
where L: Layer,

Create a packet containing one layer.

Source

pub fn push<L>(self, layer: L) -> Self
where L: Layer,

Append a concrete layer and return the packet for builder chaining.

Source

pub fn push_box(self, layer: Box<dyn Layer>) -> Self

Append a boxed layer and return the packet for builder chaining.

Source

pub fn push_mut<L>(&mut self, layer: L) -> &mut Self
where L: Layer,

Mutably append a concrete layer.

Source

pub fn push_box_mut(&mut self, layer: Box<dyn Layer>) -> &mut Self

Mutably append a boxed layer.

Source

pub fn concat(self, other: impl IntoPacket) -> Self

Append all layers from another packet.

Source

pub fn extend(&mut self, other: impl IntoPacket) -> &mut Self

Mutably append all layers from another packet.

Source

pub fn pop(&mut self) -> Option<Box<dyn Layer>>

Remove and return the final layer.

Source

pub fn pop_typed<T>(&mut self) -> Option<T>
where T: Layer,

Remove and return the final layer when it has type T.

Source

pub fn len(&self) -> usize

Number of layers in the packet.

Source

pub fn is_empty(&self) -> bool

Return true when the packet contains no layers.

Source

pub fn encoded_len(&self) -> usize

Return the encoded byte length implied by the current layers.

Source

pub fn get(&self, index: usize) -> Option<&dyn Layer>

Positional layer access.

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut dyn Layer>

Mutable positional layer access.

Source

pub fn layer<T>(&self) -> Option<&T>
where T: Layer,

First layer of type T.

Source

pub fn layer_mut<T>(&mut self) -> Option<&mut T>
where T: Layer,

First mutable layer of type T.

Source

pub fn layers<T>(&self) -> impl Iterator<Item = &T>
where T: Layer,

All layers of type T, preserving packet order.

Source

pub fn layers_mut<T>(&mut self) -> impl Iterator<Item = &mut T>
where T: Layer,

All mutable layers of type T, preserving packet order.

Source

pub fn iter(&self) -> impl Iterator<Item = &dyn Layer>

Ordered layer iteration.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut dyn Layer>

Ordered mutable layer iteration.

Source

pub fn compile(&self) -> Result<CompiledPacket>

Compile the packet into deterministic bytes.

Source

pub fn compile_into(&self, out: &mut Vec<u8>) -> Result<()>

Append compiled bytes into an existing buffer.

Source

pub fn decode_raw(bytes: impl AsRef<[u8]>) -> Result<Self>

Decode bytes as raw payload.

Decode bytes from a link-layer entrypoint.

Decode bytes from a link-layer entrypoint using an explicit registry.

Source

pub fn decode_from_l3( network_layer: NetworkLayer, bytes: impl AsRef<[u8]>, ) -> Result<Self>

Decode bytes from a network-layer entrypoint.

Source

pub fn decode_from_l3_with_registry( registry: &ProtocolRegistry, network_layer: NetworkLayer, bytes: impl AsRef<[u8]>, ) -> Result<Self>

Decode bytes from a network-layer entrypoint using an explicit registry.

Source

pub fn summary(&self) -> String

One-line packet summary.

Source

pub fn show(&self) -> String

Multi-line packet tree intended for display in examples and tools.

Source

pub fn hexdump(&self) -> Result<String>

Compile and return a canonical hex dump.

Source

pub fn raw_string_lossy(&self) -> Result<String>

Compile and return raw bytes as a lossy UTF-8 string.

Trait Implementations§

Source§

impl Clone for Packet

Source§

fn clone(&self) -> Packet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Packet

Source§

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

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

impl Default for Packet

Source§

fn default() -> Packet

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

impl<R> Div<R> for Packet
where R: IntoPacket,

Source§

type Output = Packet

The resulting type after applying the / operator.
Source§

fn div(self, rhs: R) -> Self::Output

Performs the / operation. Read more
Source§

impl IntoPacket for Packet

Source§

fn into_packet(self) -> Packet

Convert this value into a packet.
Source§

impl PacketSendExt for Packet

Source§

fn send_plan(&self, options: impl Into<SendOptions>) -> Result<SendPlan>

Build a compile-only send plan.
Source§

fn send_dry_run(&self, options: impl Into<SendOptions>) -> Result<SendPlan>

Compile and plan a send without transmitting bytes.
Source§

fn send(&self, options: impl Into<SendOptions>) -> Result<SendReport>

Send a packet according to the supplied options.
Source§

impl PacketSendRecvExt for Packet

Source§

fn reply_filter(&self) -> Result<String>

Derive a BPF-style filter for likely replies.
Source§

fn send_recv(&self, options: impl Into<SendRecv>) -> Result<Option<Packet>>

Send a packet and return the first matching reply, if any.
Source§

fn send_recv_report( &self, options: impl Into<SendRecv>, ) -> Result<SendRecvReport>

Send a packet and return a detailed send/receive report.

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> 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> Same for T

Source§

type Output = T

Should always be Self
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, 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.