pub struct Icmpv4Header {
    pub icmp_type: Icmpv4Type,
    pub checksum: u16,
}
Expand description

A header of an ICMPv4 packet.

What is part of the header depends on the ICMPv4 type and code. But usually the static sized elements are part of the header.

Fields§

§icmp_type: Icmpv4Type

Type & type specific values & code.

§checksum: u16

Checksum in the ICMP header.

Implementations§

source§

impl Icmpv4Header

source

pub const MIN_LEN: usize = 8usize

Minimum number of bytes/octets an Icmpv4Header takes up in serialized form.

source

pub const MIN_SERIALIZED_SIZE: usize = 8usize

👎Deprecated since 0.14.0: Please use Icmpv4Header::MIN_LEN instead

Deprecated, use Icmpv4Header::MIN_LEN instead.

source

pub const MAX_LEN: usize = 20usize

Maximum number of bytes/octets an Icmpv4Header takes up in serialized form.

Currently this number is determined by the biggest supported ICMPv4 header type, which is currently the “Timestamp” and “Timestamp Reply Message”.

source

pub const MAX_SERIALIZED_SIZE: usize = 20usize

👎Deprecated since 0.14.0: Please use Icmpv4Header::MAX_LEN instead

Deprecated, use Icmpv4Header::MAX_LEN instead.

source

pub fn new(icmp_type: Icmpv4Type) -> Icmpv4Header

Constructs an Icmpv4Header using the given type and the checksum set to 0.

source

pub fn with_checksum(icmp_type: Icmpv4Type, payload: &[u8]) -> Icmpv4Header

Creates a Icmpv4Header with a checksum calculated based on the given payload.

source

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

Reads an icmp4 header from a slice directly and returns a tuple containing the resulting header & unused part of the slice.

source

pub fn read<T: Read + Sized>(reader: &mut T) -> Result<Icmpv4Header, Error>

Available on crate feature std only.

Reads an ICMPv4 header from the given reader.

source

pub fn write<T: Write + Sized>(&self, writer: &mut T) -> Result<(), Error>

Available on crate feature std only.

Write the ICMPv4 header to the given writer.

source

pub fn header_len(&self) -> usize

Length in bytes/octets of this header type.

source

pub fn fixed_payload_size(&self) -> Option<usize>

If the ICMP type has a fixed size returns the number of bytes that should be present after the header of this type.

source

pub fn update_checksum(&mut self, payload: &[u8])

Calculates & updates the checksum in the header.

Note this method assumes that all unused bytes/octets are filled with zeroes.

source

pub fn to_bytes(&self) -> ArrayVec<u8, { Icmpv4Header::MAX_LEN }>

Converts the header to the on the wire bytes.

Trait Implementations§

source§

impl Clone for Icmpv4Header

source§

fn clone(&self) -> Icmpv4Header

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 Debug for Icmpv4Header

source§

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

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

impl PartialEq for Icmpv4Header

source§

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

source§

impl StructuralPartialEq for Icmpv4Header

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