#[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: IcmpHdrUnImplementations§
Source§impl IcmpHdr
impl IcmpHdr
pub const LEN: usize = 8usize
Sourcepub fn checksum(&self) -> u16
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.
Sourcepub fn set_checksum(&mut self, checksum: u16)
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.
Sourcepub fn echo_id(&self) -> Result<u16, IcmpError>
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.
Sourcepub fn set_echo_id(&mut self, id: u16) -> Result<(), IcmpError>
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.
Sourcepub fn echo_sequence(&self) -> Result<u16, IcmpError>
pub fn echo_sequence(&self) -> Result<u16, IcmpError>
Returns the sequence number from ICMP Echo/Timestamp/Info/Mask messages.
Sourcepub fn set_echo_sequence(&mut self, sequence: u16) -> Result<(), IcmpError>
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.
Sourcepub fn gateway_address(&self) -> Result<Ipv4Addr, IcmpError>
pub fn gateway_address(&self) -> Result<Ipv4Addr, IcmpError>
Returns the gateway internet address from an ICMP Redirect message (Type 5)
Sourcepub fn set_gateway_address(&mut self, addr: Ipv4Addr) -> Result<(), IcmpError>
pub fn set_gateway_address(&mut self, addr: Ipv4Addr) -> Result<(), IcmpError>
Sets the gateway internet address for an ICMP Redirect message (Type 5)
Sourcepub fn next_hop_mtu(&self) -> Result<u16, IcmpError>
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).
Sourcepub fn set_next_hop_mtu(&mut self, mtu: u16) -> Result<(), IcmpError>
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).
Sourcepub fn parameter_pointer(&self) -> Result<u8, IcmpError>
pub fn parameter_pointer(&self) -> Result<u8, IcmpError>
Returns the pointer to the errored byte from a Parameter Problem message (Type 12)
Sourcepub fn set_parameter_pointer(&mut self, pointer: u8) -> Result<(), IcmpError>
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)
Sourcepub fn traceroute_id(&self) -> Result<u16, IcmpError>
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).
Sourcepub fn set_traceroute_id(&mut self, id: u16) -> Result<(), IcmpError>
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.
Sourcepub fn photuris_spi(&self) -> Result<u16, IcmpError>
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.
Sourcepub fn set_photuris_spi(&mut self, spi: u16) -> Result<(), IcmpError>
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.
Sourcepub fn photuris_pointer(&self) -> Result<u16, IcmpError>
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§impl IcmpHdr
These are the unsafe alternatives to the safe functions on IcmpHdr that do prevent undefined behavior.
impl IcmpHdr
These are the unsafe alternatives to the safe functions on IcmpHdr that do prevent undefined behavior.
Sourcepub unsafe fn echo_id_unchecked(&self) -> u16
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.
Sourcepub unsafe fn set_echo_id_unchecked(&mut self, id: u16)
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.
Sourcepub unsafe fn echo_sequence_unchecked(&self) -> u16
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.
Sourcepub unsafe fn set_echo_sequence_unchecked(&mut self, sequence: u16)
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.
Sourcepub unsafe fn gateway_address_unchecked(&self) -> Ipv4Addr
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.
Sourcepub unsafe fn set_gateway_address_unchecked(&mut self, addr: Ipv4Addr)
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.
Sourcepub unsafe fn next_hop_mtu_unchecked(&self) -> u16
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.
Sourcepub unsafe fn set_next_hop_mtu_unchecked(&mut self, mtu: u16)
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.
Sourcepub unsafe fn parameter_pointer_unchecked(&self) -> u8
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.
Sourcepub unsafe fn set_parameter_pointer_unchecked(&mut self, pointer: u8)
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.
Sourcepub unsafe fn traceroute_id_unchecked(&self) -> u16
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.
Sourcepub unsafe fn set_traceroute_id_unchecked(&mut self, id: u16)
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.
Sourcepub unsafe fn photuris_spi_unchecked(&self) -> u16
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.
Sourcepub unsafe fn set_photuris_spi_unchecked(&mut self, spi: u16)
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.
Sourcepub unsafe fn photuris_pointer_unchecked(&self) -> u16
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.
Sourcepub unsafe fn set_photuris_pointer_unchecked(&mut self, pointer: u16)
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.