packet_formats::icmp

Trait MessageBody

Source
pub trait MessageBody: Sized {
    type B: SplitByteSlice;

    // Required methods
    fn parse(bytes: Self::B) -> ParseResult<Self>;
    fn len(&self) -> usize;
    fn bytes(&self) -> (&[u8], Option<&[u8]>);

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

MessageBody represents the parsed body of the ICMP packet.

  • For messages that expect no body, the MessageBody is of type EmptyMessage.
  • For NDP messages, the MessageBody is of the type ndp::Options.
  • For all other messages, the MessageBody will be of the type OriginalPacket, which is a thin wrapper around B.

Required Associated Types§

Source

type B: SplitByteSlice

The underlying byteslice.

Required Methods§

Source

fn parse(bytes: Self::B) -> ParseResult<Self>

Parse the MessageBody from the provided bytes.

Source

fn len(&self) -> usize

The length of the underlying buffer.

Source

fn bytes(&self) -> (&[u8], Option<&[u8]>)

Return the underlying bytes.

Not all ICMP messages have a fixed size, some messages like MLDv2 Query or MLDv2 Report (RFC 3810 section 5.1 and RFC 3810 section 5.2) contain a fixed amount of information followed by a variable amount of records. The first value returned contains the fixed size part, while the second value contains the records for the messages that support them, more precisely, the second value is None if the message does not have a variable part, otherwise it will contain the serialized list of records.

Provided Methods§

Source

fn is_empty(&self) -> bool

Is the body empty?

b.is_empty() is equivalent to b.len() == 0.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<B: SplitByteSlice, O: OptionsImpl> MessageBody for Options<B, O>

Source§

type B = B

Source§

fn parse(bytes: B) -> ParseResult<Options<B, O>>

Source§

fn len(&self) -> usize

Source§

fn bytes(&self) -> (&[u8], Option<&[u8]>)

Implementors§

Source§

impl<B: SplitByteSlice> MessageBody for Mldv1Body<B>

Source§

type B = B

Source§

impl<B: SplitByteSlice> MessageBody for Mldv2QueryBody<B>

Source§

type B = B

Source§

impl<B: SplitByteSlice> MessageBody for Mldv2ReportBody<B>

Source§

type B = B

Source§

impl<B: SplitByteSlice> MessageBody for EmptyMessage<B>

Source§

type B = B

Source§

impl<B: SplitByteSlice> MessageBody for OriginalPacket<B>

Source§

type B = B