IcmpHdr

Struct IcmpHdr 

Source
#[repr(C, packed(1))]
pub struct IcmpHdr { pub type_: u8, pub code: u8, pub check: [u8; 2], pub data: IcmpHdrUn, }
Expand description

Represents an ICMP header as defined in RFC 792. The header consists of a type and code field identifying the message type, a checksum for error detection, and a data field whose format depends on the message type.

The type_ field identifies the general category of message, such as:

  • 0: Echo Reply
  • 3: Destination Unreachable
  • 5: Redirect
  • 8: Echo Request
  • 30: Traceroute
  • 40: PHOTURIS

The code field provides additional context for the message type.

The check field contains a checksum calculated over the ICMP header and its payload.

The data field contains type-specific data such as echo identifiers/sequence numbers, redirect gateway addresses, or pointers to errors in received packets.

Fields§

§type_: u8§code: u8§check: [u8; 2]§data: IcmpHdrUn

Implementations§

Source§

impl IcmpHdr

Source

pub const LEN: usize = 8usize

Source

pub fn checksum(&self) -> u16

Returns the ICMP header checksum value in host byte order. This field is used to detect data corruption in the ICMP header and payload.

Source

pub fn set_checksum(&mut self, checksum: u16)

Sets the ICMP header checksum field to the given value. The checksum value should be calculated over the entire ICMP message (header and payload) according to RFC 792. The value will be stored in network byte order.

Source

pub fn echo_id(&self) -> Result<u16, IcmpError>

Returns the identification field from ICMP Echo/Timestamp/Info/Mask messages. Only valid for ICMP Types: 0, 8, 13, 14, 15, 16, 17, 18, 37, 38.

Source

pub fn set_echo_id(&mut self, id: u16) -> Result<(), IcmpError>

Sets the identification field for ICMP Echo/Timestamp/Info/Mask messages. Only valid for ICMP Types: 0, 8, 13, 14, 15, 16, 17, 18, 37, 38.

Source

pub fn echo_sequence(&self) -> Result<u16, IcmpError>

Returns the sequence number from ICMP Echo/Timestamp/Info/Mask messages.

Source

pub fn set_echo_sequence(&mut self, sequence: u16) -> Result<(), IcmpError>

Sets the sequence number for ICMP Echo/Timestamp/Info/Mask messages. Only valid for ICMP Types: 0, 8, 13, 14, 15, 16, 17, 18, 37, 38.

Source

pub fn gateway_address(&self) -> Result<Ipv4Addr, IcmpError>

Returns the gateway internet address from an ICMP Redirect message (Type 5)

Source

pub fn set_gateway_address(&mut self, addr: Ipv4Addr) -> Result<(), IcmpError>

Sets the gateway internet address for an ICMP Redirect message (Type 5)

Source

pub fn next_hop_mtu(&self) -> Result<u16, IcmpError>

Returns the Next-Hop MTU field from a Destination Unreachable message in host byte order. Used for Path MTU Discovery (RFC 1191).

Source

pub fn set_next_hop_mtu(&mut self, mtu: u16) -> Result<(), IcmpError>

Sets the Next-Hop MTU field for a Destination Unreachable message. Used for Path MTU Discovery (RFC 1191).

Source

pub fn parameter_pointer(&self) -> Result<u8, IcmpError>

Returns the pointer to the errored byte from a Parameter Problem message (Type 12)

Source

pub fn set_parameter_pointer(&mut self, pointer: u8) -> Result<(), IcmpError>

Sets the pointer to the errored byte for a Parameter Problem message (Type 12)

Source

pub fn traceroute_id(&self) -> Result<u16, IcmpError>

Returns the ID Number field from a Traceroute message (Type 30). The ID Number is used to match Reply messages (Type 31) to their corresponding Request messages. This is only valid for ICMP Type 30 (Traceroute Request) and Type 31 (Traceroute Reply).

Source

pub fn set_traceroute_id(&mut self, id: u16) -> Result<(), IcmpError>

Sets the ID Number field for a Traceroute message (Type 30). The ID Number is used to match Reply messages (Type 31) to their corresponding Request messages.

Source

pub fn photuris_spi(&self) -> Result<u16, IcmpError>

Returns the Security Parameters Index (SPI) from a PHOTURIS message (Type 40). The SPI identifies a security association between two peers.

Source

pub fn set_photuris_spi(&mut self, spi: u16) -> Result<(), IcmpError>

Sets the Security Parameters Index (SPI) for a PHOTURIS message (Type 40). The SPI identifies a security association between two peers.

Source

pub fn photuris_pointer(&self) -> Result<u16, IcmpError>

Returns the pointer to the byte where an error was detected in a PHOTURIS message (Type 40). Used to identify the location of errors during PHOTURIS protocol processing.

Source

pub fn set_photuris_pointer(&mut self, pointer: u16) -> Result<(), IcmpError>

Sets the pointer to the byte where an error was detected in a PHOTURIS message (Type 40). Used to identify the location of errors during PHOTURIS protocol processing.

Source§

impl IcmpHdr

These are the unsafe alternatives to the safe functions on IcmpHdr that do prevent undefined behavior.

Source

pub unsafe fn echo_id_unchecked(&self) -> u16

Returns the identification field from ICMP Echo/Timestamp/Info/Mask messages. Only valid for ICMP Types: 0, 8, 13, 14, 15, 16, 17, 18, 37, 38.

§Safety

Caller must ensure that the ICMP type is one of: 0, 8, 13, 14, 15, 16, 17, 18, 37, 38 before calling this function. Accessing the echo fields with other ICMP types may result in undefined behavior.

Source

pub unsafe fn set_echo_id_unchecked(&mut self, id: u16)

Sets the identification field for ICMP Echo/Timestamp/Info/Mask messages. Only valid for ICMP Types: 0, 8, 13, 14, 15, 16, 17, 18, 37, 38.

§Safety

Caller must ensure that the ICMP type is one of: 0, 8, 13, 14, 15, 16, 17, 18, 37, 38 before calling this function. Accessing the echo fields with other ICMP types may result in undefined behavior.

Source

pub unsafe fn echo_sequence_unchecked(&self) -> u16

Returns the sequence number from ICMP Echo/Timestamp/Info/Mask messages. Only valid for ICMP Types: 0, 8, 13, 14, 15, 16, 17, 18, 37, 38.

§Safety

Caller must ensure that the ICMP type is one of: 0, 8, 13, 14, 15, 16, 17, 18, 37, 38 before calling this function. Accessing the echo fields with other ICMP types may result in undefined behavior.

Source

pub unsafe fn set_echo_sequence_unchecked(&mut self, sequence: u16)

Sets the sequence number for ICMP Echo/Timestamp/Info/Mask messages. Only valid for ICMP Types: 0, 8, 13, 14, 15, 16, 17, 18, 37, 38.

§Safety

Caller must ensure that the ICMP type is one of: 0, 8, 13, 14, 15, 16, 17, 18, 37, 38 before calling this function. Accessing the echo fields with other ICMP types may result in undefined behavior.

Source

pub unsafe fn gateway_address_unchecked(&self) -> Ipv4Addr

Returns the gateway internet address from an ICMP Redirect message (Type 5)

§Safety

Caller must ensure ICMP type is 5 (Redirect) before calling this function. Accessing the redirect field with other ICMP types may result in undefined behavior.

Source

pub unsafe fn set_gateway_address_unchecked(&mut self, addr: Ipv4Addr)

Sets the gateway internet address for an ICMP Redirect message (Type 5)

§Safety

Caller must ensure ICMP type is 5 (Redirect) before calling this function. Accessing the redirect field with other ICMP types may result in undefined behavior.

Source

pub unsafe fn next_hop_mtu_unchecked(&self) -> u16

Returns the Next-Hop MTU field from a Destination Unreachable message in host byte order. Used for Path MTU Discovery (RFC 1191).

§Safety

Caller must ensure ICMP type is 3 (Destination Unreachable) before calling this function. Accessing the dst_unreachable field with other ICMP types may result in undefined behavior.

Source

pub unsafe fn set_next_hop_mtu_unchecked(&mut self, mtu: u16)

Sets the Next-Hop MTU field for a Destination Unreachable message. Used for Path MTU Discovery (RFC 1191).

§Safety

Caller must ensure ICMP type is 3 (Destination Unreachable) before calling this function. Accessing the dst_unreachable field with other ICMP types may result in undefined behavior.

Source

pub unsafe fn parameter_pointer_unchecked(&self) -> u8

Returns the pointer to the errored byte from a Parameter Problem message (Type 12)

§Safety

Caller must ensure ICMP type is 12 (Parameter Problem) before calling this function. Accessing the param_problem field with other ICMP types may result in undefined behavior.

Source

pub unsafe fn set_parameter_pointer_unchecked(&mut self, pointer: u8)

Sets the pointer to the errored byte for a Parameter Problem message (Type 12)

§Safety

Caller must ensure ICMP type is 12 (Parameter Problem) before calling this function. Accessing the param_problem field with other ICMP types may result in undefined behavior.

Source

pub unsafe fn traceroute_id_unchecked(&self) -> u16

Returns the ID Number field from a Traceroute message (Type 30). The ID Number is used to match Reply messages (Type 31) to their corresponding Request messages. This is only valid for ICMP Type 30 (Traceroute Request) and Type 31 (Traceroute Reply).

§Safety

Caller must ensure ICMP type is 30 (Traceroute Request) or 31 (Traceroute Reply) before calling this function. Accessing the traceroute field with other ICMP types may result in undefined behavior.

Source

pub unsafe fn set_traceroute_id_unchecked(&mut self, id: u16)

Sets the ID Number field for a Traceroute message (Type 30). The ID Number is used to match Reply messages (Type 31) to their corresponding Request messages.

§Safety

Caller must ensure ICMP type is 30 (Traceroute Request) or 31 (Traceroute Reply) before calling this function. Accessing the traceroute field with other ICMP types may result in undefined behavior.

Source

pub unsafe fn photuris_spi_unchecked(&self) -> u16

Returns the Security Parameters Index (SPI) from a PHOTURIS message (Type 40). The SPI identifies a security association between two peers.

§Safety

Caller must ensure ICMP type is 40 (PHOTURIS) before calling this function. Accessing the photuris field with other ICMP types may result in undefined behavior.

Source

pub unsafe fn set_photuris_spi_unchecked(&mut self, spi: u16)

Sets the Security Parameters Index (SPI) for a PHOTURIS message (Type 40). The SPI identifies a security association between two peers.

§Safety

Caller must ensure ICMP type is 40 (PHOTURIS) before calling this function. Accessing the photuris field with other ICMP types may result in undefined behavior.

Source

pub unsafe fn photuris_pointer_unchecked(&self) -> u16

Returns the pointer to the byte where an error was detected in a PHOTURIS message (Type 40). Used to identify the location of errors during PHOTURIS protocol processing.

§Safety

Caller must ensure ICMP type is 40 (PHOTURIS) before calling this function. Accessing the photuris field with other ICMP types may result in undefined behavior.

Source

pub unsafe fn set_photuris_pointer_unchecked(&mut self, pointer: u16)

Sets the pointer to the byte where an error was detected in a PHOTURIS message (Type 40). Used to identify the location of errors during PHOTURIS protocol processing.

§Safety

Caller must ensure ICMP type is 40 (PHOTURIS) before calling this function. Accessing the photuris field with other ICMP types may result in undefined behavior.

Trait Implementations§

Source§

impl Clone for IcmpHdr

Source§

fn clone(&self) -> IcmpHdr

Returns a duplicate 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 IcmpHdr

Source§

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

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

impl Copy for IcmpHdr

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