#[repr(C, packed(1))]pub struct IcmpV6Hdr {
pub type_: u8,
pub code: u8,
pub check: [u8; 2],
pub data: IcmpV6HdrUn,
}Expand description
Represents an ICMPv6 header as defined in RFC 4443. 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:
- 1: Destination Unreachable
- 2: Packet Too Big
- 3: Time Exceeded
- 4: Parameter Problem
- 128: Echo Request
- 129: Echo Reply
The code field provides additional context for the message type.
The check field contains a checksum calculated over an IPv6 pseudo-header,
the ICMPv6 header, and its payload.
The data field contains type-specific data such as echo identifiers/sequence numbers,
MTU values, or pointers to errors in received packets.
Fields§
§type_: u8§code: u8§check: [u8; 2]§data: IcmpV6HdrUnImplementations§
Source§impl IcmpV6Hdr
impl IcmpV6Hdr
pub const LEN: usize = 40usize
Sourcepub fn checksum(&self) -> u16
pub fn checksum(&self) -> u16
Returns the ICMPv6 header checksum value in host byte order. This field is used to detect corruption in the ICMPv6 header and payload.
Sourcepub fn set_checksum(&mut self, checksum: u16)
pub fn set_checksum(&mut self, checksum: u16)
Sets the ICMPv6 header checksum field to the given value. The checksum value should be calculated over the pseudo-header, ICMPv6 header, and payload according to RFC 4443. 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 ICMPv6 Echo Request/Reply messages. Only valid for ICMPv6 Types: 128 (Echo Request), 129 (Echo Reply).
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 ICMPv6 Echo Request/Reply messages. Only valid for ICMPv6 Types: 128 (Echo Request), 129 (Echo Reply).
Sourcepub fn echo_sequence(&self) -> Result<u16, IcmpError>
pub fn echo_sequence(&self) -> Result<u16, IcmpError>
Returns the sequence number from ICMPv6 Echo Request/Reply messages. Only valid for ICMPv6 Types: 128 (Echo Request), 129 (Echo Reply).
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 ICMPv6 Echo Request/Reply messages. Only valid for ICMPv6 Types: 128 (Echo Request), 129 (Echo Reply).
Sourcepub fn mtu(&self) -> Result<u32, IcmpError>
pub fn mtu(&self) -> Result<u32, IcmpError>
Returns the MTU field from an ICMPv6 Packet Too Big message (Type 2). This value indicates the maximum packet size that can be handled by the next hop.
Sourcepub fn set_mtu(&mut self, mtu: u32) -> Result<(), IcmpError>
pub fn set_mtu(&mut self, mtu: u32) -> Result<(), IcmpError>
Sets the MTU field for an ICMPv6 Packet Too Big message (Type 2). This should be set to the maximum packet size that can be handled by the next hop.
Sourcepub fn pointer(&self) -> Result<u32, IcmpError>
pub fn pointer(&self) -> Result<u32, IcmpError>
Returns the pointer field from an ICMPv6 Parameter Problem message (Type 4). The pointer indicates the offset within the invoking packet where the error was detected.
Sourcepub fn set_pointer(&mut self, pointer: u32) -> Result<(), IcmpError>
pub fn set_pointer(&mut self, pointer: u32) -> Result<(), IcmpError>
Sets the pointer field for an ICMPv6 Parameter Problem message (Type 4). The pointer should indicate the offset within the invoking packet where the error was detected.
Sourcepub fn redirect_reserved(&self) -> Result<[u8; 4], IcmpError>
pub fn redirect_reserved(&self) -> Result<[u8; 4], IcmpError>
Returns the 4-byte reserved field from an ICMPv6 Redirect message (Type 137). This field is currently unused and MUST be initialized to zeros by the sender.
Sourcepub fn set_redirect_reserved(
&mut self,
reserved: [u8; 4],
) -> Result<(), IcmpError>
pub fn set_redirect_reserved( &mut self, reserved: [u8; 4], ) -> Result<(), IcmpError>
Sets the 4-byte reserved field for an ICMPv6 Redirect message (Type 137). This field is currently unused and MUST be set to zeros.
Sourcepub fn redirect_target_address(&self) -> Result<Ipv6Addr, IcmpError>
pub fn redirect_target_address(&self) -> Result<Ipv6Addr, IcmpError>
Returns the Target Address from an ICMPv6 Redirect message (Type 137). This field contains the address that is a better first hop to use for the destination.
Sourcepub fn set_redirect_target_address(
&mut self,
addr: Ipv6Addr,
) -> Result<(), IcmpError>
pub fn set_redirect_target_address( &mut self, addr: Ipv6Addr, ) -> Result<(), IcmpError>
Sets the Target Address for an ICMPv6 Redirect message (Type 137). This should be set to the address that is a better first hop to use for the destination.
Sourcepub fn redirect_destination_address(&self) -> Result<Ipv6Addr, IcmpError>
pub fn redirect_destination_address(&self) -> Result<Ipv6Addr, IcmpError>
Returns the Destination Address from an ICMPv6 Redirect message (Type 137). This field contains the IP address of the destination that is redirected to the target.
Source§impl IcmpV6Hdr
impl IcmpV6Hdr
Sourcepub unsafe fn echo_id_unchecked(&self) -> u16
pub unsafe fn echo_id_unchecked(&self) -> u16
Returns the identification field from ICMPv6 Echo Request/Reply messages. Only valid for ICMPv6 Types: 128 (Echo Request), 129 (Echo Reply).
§Safety
Caller must ensure ICMPv6 type is 128 (Echo Request) or 129 (Echo Reply) before calling. Accessing echo fields with other 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 ICMPv6 Echo Request/Reply messages. Only valid for ICMPv6 Types: 128 (Echo Request), 129 (Echo Reply).
§Safety
Caller must ensure ICMPv6 type is 128 (Echo Request) or 129 (Echo Reply) before calling. Accessing echo fields with other 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 ICMPv6 Echo Request/Reply messages. Only valid for ICMPv6 Types: 128 (Echo Request), 129 (Echo Reply).
§Safety
Caller must ensure ICMPv6 type is 128 (Echo Request) or 129 (Echo Reply) before calling. Accessing echo fields with other 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 ICMPv6 Echo Request/Reply messages. Only valid for ICMPv6 Types: 128 (Echo Request), 129 (Echo Reply).
§Safety
Caller must ensure ICMPv6 type is 128 (Echo Request) or 129 (Echo Reply) before calling. Accessing echo fields with other types may result in undefined behavior.
Sourcepub unsafe fn mtu_unchecked(&self) -> u32
pub unsafe fn mtu_unchecked(&self) -> u32
Returns the MTU field from an ICMPv6 Packet Too Big message (Type 2). This value indicates the maximum packet size that can be handled by the next hop.
§Safety
Caller must ensure ICMPv6 type is 2 (Packet Too Big) before calling. Accessing MTU field with other types may result in undefined behavior.
Sourcepub unsafe fn set_mtu_unchecked(&mut self, mtu: u32)
pub unsafe fn set_mtu_unchecked(&mut self, mtu: u32)
Sets the MTU field for an ICMPv6 Packet Too Big message (Type 2). This should be set to the maximum packet size that can be handled by the next hop.
§Safety
Caller must ensure ICMPv6 type is 2 (Packet Too Big) before calling. Accessing MTU field with other types may result in undefined behavior.
Sourcepub unsafe fn pointer_unchecked(&self) -> u32
pub unsafe fn pointer_unchecked(&self) -> u32
Returns the pointer field from an ICMPv6 Parameter Problem message (Type 4). The pointer indicates the offset within the invoking packet where the error was detected.
§Safety
Caller must ensure ICMPv6 type is 4 (Parameter Problem) before calling. Accessing pointer field with other types may result in undefined behavior.
Sourcepub unsafe fn set_pointer_unchecked(&mut self, pointer: u32)
pub unsafe fn set_pointer_unchecked(&mut self, pointer: u32)
Sets the pointer field for an ICMPv6 Parameter Problem message (Type 4). The pointer should indicate the offset within the invoking packet where the error was detected.
§Safety
Caller must ensure ICMPv6 type is 4 (Parameter Problem) before calling. Accessing pointer field with other types may result in undefined behavior.
Sourcepub unsafe fn redirect_reserved_unchecked(&self) -> [u8; 4]
pub unsafe fn redirect_reserved_unchecked(&self) -> [u8; 4]
Returns the 4-byte reserved field from an ICMPv6 Redirect message (Type 137). This field is currently unused and MUST be initialized to zeros by the sender.
§Safety
Caller must ensure ICMPv6 type is 137 (Redirect) before calling. Accessing redirect fields with other types may result in undefined behavior.
Sourcepub unsafe fn set_redirect_reserved_unchecked(&mut self, reserved: [u8; 4])
pub unsafe fn set_redirect_reserved_unchecked(&mut self, reserved: [u8; 4])
Sets the 4-byte reserved field for an ICMPv6 Redirect message (Type 137). This field is currently unused and MUST be set to zeros.
§Safety
Caller must ensure ICMPv6 type is 137 (Redirect) before calling. Accessing redirect fields with other types may result in undefined behavior.
Sourcepub unsafe fn redirect_target_address_unchecked(&self) -> Ipv6Addr
pub unsafe fn redirect_target_address_unchecked(&self) -> Ipv6Addr
Returns the Target Address from an ICMPv6 Redirect message (Type 137). This field contains the address that is a better first hop to use for the destination.
§Safety
Caller must ensure ICMPv6 type is 137 (Redirect) before calling. Accessing redirect fields with other types may result in undefined behavior.
Sourcepub unsafe fn set_redirect_target_address_unchecked(&mut self, addr: Ipv6Addr)
pub unsafe fn set_redirect_target_address_unchecked(&mut self, addr: Ipv6Addr)
Sets the Target Address for an ICMPv6 Redirect message (Type 137). This should be set to the address that is a better first hop to use for the destination.
§Safety
Caller must ensure ICMPv6 type is 137 (Redirect) before calling. Accessing redirect fields with other types may result in undefined behavior.
Sourcepub unsafe fn redirect_destination_address_unchecked(&self) -> Ipv6Addr
pub unsafe fn redirect_destination_address_unchecked(&self) -> Ipv6Addr
Returns the Destination Address from an ICMPv6 Redirect message (Type 137). This field contains the IP address of the destination that is redirected to the target.
§Safety
Caller must ensure ICMPv6 type is 137 (Redirect) before calling. Accessing redirect fields with other types may result in undefined behavior.
Sourcepub unsafe fn set_redirect_destination_address_unchecked(
&mut self,
addr: Ipv6Addr,
)
pub unsafe fn set_redirect_destination_address_unchecked( &mut self, addr: Ipv6Addr, )
Sets the Destination Address for an ICMPv6 Redirect message (Type 137). This should be set to the IP address of the destination that is redirected to the target.
§Safety
Caller must ensure ICMPv6 type is 137 (Redirect) before calling. Accessing redirect fields with other types may result in undefined behavior.