packet_formats::icmp

Struct IcmpPacket

Source
pub struct IcmpPacket<I: IcmpIpExt, B: SplitByteSlice, M: IcmpMessage<I>> { /* private fields */ }
Expand description

An ICMP packet.

An IcmpPacket shares its underlying memory with the byte slice it was parsed from, meaning that no copying or extra allocation is necessary.

Implementations§

Source§

impl<I: IcmpIpExt, B: SplitByteSlice, M: IcmpMessage<I>> IcmpPacket<I, B, M>

Source

pub fn message(&self) -> &M

Get the ICMP message.

Source

pub fn body(&self) -> &M::Body<B>

Get the ICMP body.

Source

pub fn code(&self) -> M::Code

Get the ICMP message code.

The code provides extra details about the message. Each message type has its own set of codes that are allowed.

Source

pub fn builder( &self, src_ip: I::Addr, dst_ip: I::Addr, ) -> IcmpPacketBuilder<I, M>

Construct a builder with the same contents as this packet.

Source§

impl<I: IcmpIpExt, B: SplitByteSlice, M: IcmpMessage<I, Body<B> = OriginalPacket<B>>> IcmpPacket<I, B, M>

Source

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

Get the body of the packet that caused this ICMP message.

This ICMP message contains some of the bytes of the packet that caused this message to be emitted. original_packet_body returns as much of the body of that packet as is contained in this message. For IPv4, this is guaranteed to be 8 bytes. For IPv6, there are no guarantees about the length.

Source

pub fn original_packet(&self) -> &OriginalPacket<B>

Returns the original packt that caused this ICMP message.

This ICMP message contains some of the bytes of the packet that caused this message to be emitted. original_packet returns as much of the body of that packet as is contained in this message. For IPv4, this is guaranteed to be 8 bytes. For IPv6, there are no guarantees about the length.

Source§

impl<B: SplitByteSlice, M: IcmpMessage<Ipv4, Body<B> = OriginalPacket<B>>> IcmpPacket<Ipv4, B, M>

Source

pub fn with_original_packet<O, F: FnOnce(Result<Ipv4PacketRaw<&[u8]>, &[u8]>) -> O>( &self, f: F, ) -> O

Attempt to partially parse the original packet as an IPv4 packet.

f will be invoked on the result of calling Ipv4PacketRaw::parse on the original packet.

Source§

impl<B: SplitByteSlice, M: IcmpMessage<Ipv6, Body<B> = OriginalPacket<B>>> IcmpPacket<Ipv6, B, M>

Source

pub fn with_original_packet<O, F: FnOnce(Result<Ipv6PacketRaw<&[u8]>, &[u8]>) -> O>( &self, f: F, ) -> O

Attempt to partially parse the original packet as an IPv6 packet.

f will be invoked on the result of calling Ipv6PacketRaw::parse on the original packet.

Source§

impl<I: IcmpIpExt, B: SplitByteSlice, M: IcmpMessage<I, Body<B> = Options<B>>> IcmpPacket<I, B, M>

Source

pub fn ndp_options(&self) -> &Options<B>

Get the pared list of NDP options from the ICMP message.

Trait Implementations§

Source§

impl<I: Debug + IcmpIpExt, B: Debug + SplitByteSlice, M: Debug + IcmpMessage<I>> Debug for IcmpPacket<I, B, M>
where M::Body<B>: Debug,

Source§

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

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

impl<B: SplitByteSlice, I: IcmpIpExt, M: IcmpMessage<I>> FromRaw<IcmpPacketRaw<I, B, M>, IcmpParseArgs<<I as Ip>::Addr>> for IcmpPacket<I, B, M>

Source§

type Error = ParseError

The type of error that may happen during validation.
Source§

fn try_from_raw_with( raw: IcmpPacketRaw<I, B, M>, args: IcmpParseArgs<I::Addr>, ) -> ParseResult<Self>

Attempts to create Self from the raw form in raw with args.
Source§

impl<B: SplitByteSlice, I: IcmpIpExt, M: IcmpMessage<I>> ParsablePacket<B, IcmpParseArgs<<I as Ip>::Addr>> for IcmpPacket<I, B, M>

Source§

type Error = ParseError

The type of errors returned from parse and parse_mut.
Source§

fn parse_metadata(&self) -> ParseMetadata

Gets metadata about this packet required by [GrowBuffer::undo_parse]. Read more
Source§

fn parse<BV: BufferView<B>>( buffer: BV, args: IcmpParseArgs<I::Addr>, ) -> ParseResult<Self>

Parses a packet from a buffer. Read more
§

fn parse_mut<BV>(buffer: BV, args: ParseArgs) -> Result<Self, Self::Error>
where BV: BufferViewMut<B>, B: SplitByteSliceMut,

Parses a packet from a mutable buffer. Read more

Auto Trait Implementations§

§

impl<I, B, M> Freeze for IcmpPacket<I, B, M>
where <M as IcmpMessage<I>>::Body<B>: Freeze, B: Freeze,

§

impl<I, B, M> RefUnwindSafe for IcmpPacket<I, B, M>

§

impl<I, B, M> Send for IcmpPacket<I, B, M>
where <M as IcmpMessage<I>>::Body<B>: Send, B: Send, M: Send,

§

impl<I, B, M> Sync for IcmpPacket<I, B, M>
where <M as IcmpMessage<I>>::Body<B>: Sync, B: Sync, M: Sync,

§

impl<I, B, M> Unpin for IcmpPacket<I, B, M>
where <M as IcmpMessage<I>>::Body<B>: Unpin, B: Unpin, I: Unpin, M: Unpin,

§

impl<I, B, M> UnwindSafe for IcmpPacket<I, B, M>
where <M as IcmpMessage<I>>::Body<B>: UnwindSafe, B: UnwindSafe, I: UnwindSafe, M: 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> 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, 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.