Struct etherparse::Icmpv4Slice

source ·
pub struct Icmpv4Slice<'a> { /* private fields */ }
Expand description

A slice containing an ICMPv4 network package.

Struct allows the selective read of fields in the ICMPv4 packet.

Implementations§

source§

impl<'a> Icmpv4Slice<'a>

source

pub fn from_slice(slice: &'a [u8]) -> Result<Icmpv4Slice<'a>, LenError>

Creates a slice containing an ICMPv4 packet.

§Errors

The function will return an Err err::LenError if the given slice is too small or does not match the expected length in case of a timestamp message.

source

pub fn header(&self) -> Icmpv4Header

Decode the header values into an Icmpv4Header struct.

source

pub fn header_len(&self) -> usize

Number of bytes/octets that will be converted into a Icmpv4Header when Icmpv4Slice::header gets called.

source

pub fn icmp_type(&self) -> Icmpv4Type

Decode the header values (excluding the checksum) into an Icmpv4Type enum.

source

pub fn type_u8(&self) -> u8

Returns “type” value in the ICMPv4 header.

source

pub fn code_u8(&self) -> u8

Returns “code” value in the ICMPv4 header.

source

pub fn checksum(&self) -> u16

Returns “checksum” value in the ICMPv4 header.

source

pub fn bytes5to8(&self) -> [u8; 4]

Returns the bytes from position 4 till and including the 8th position in the ICMPv4 header.

These bytes located at th 5th, 6th, 7th and 8th position of the ICMP packet can depending on the ICMPv4 type and code contain additional data.

source

pub fn payload(&self) -> &'a [u8]

Returns a slice to the bytes not covered by .header().

The contents of the slice returned by payload() depends on the type and code of the ICMP packet:

.header().icmp_type or .icmp_type()Payload Content
Icmpv4Type::EchoReply
Icmpv4Type::EchoRequest
Data part of the echo message
Icmpv4Type::DestinationUnreachable
Icmpv4Type::Redirect
Icmpv4Type::TimeExceeded
Icmpv4Type::ParameterProblem
Internet Header + 64 bits of Original Data Datagram causing the ICMP message
Icmpv4Type::TimestampRequest
Icmpv4Type::TimestampReply
Nothing
Icmpv4Type::UnknownEverything after the 8th byte/octet of the ICMP packet.
source

pub fn slice(&self) -> &'a [u8]

Returns the slice containing the ICMPv4 packet.

Trait Implementations§

source§

impl<'a> Clone for Icmpv4Slice<'a>

source§

fn clone(&self) -> Icmpv4Slice<'a>

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<'a> Debug for Icmpv4Slice<'a>

source§

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

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

impl<'a> PartialEq for Icmpv4Slice<'a>

source§

fn eq(&self, other: &Icmpv4Slice<'a>) -> 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<'a> Eq for Icmpv4Slice<'a>

source§

impl<'a> StructuralPartialEq for Icmpv4Slice<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Icmpv4Slice<'a>

§

impl<'a> RefUnwindSafe for Icmpv4Slice<'a>

§

impl<'a> Send for Icmpv4Slice<'a>

§

impl<'a> Sync for Icmpv4Slice<'a>

§

impl<'a> Unpin for Icmpv4Slice<'a>

§

impl<'a> UnwindSafe for Icmpv4Slice<'a>

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.