#[repr(C)]pub struct Icmpv4Hdr {
pub type_: u8,
pub code: u8,
pub check: [u8; 2],
pub data: [u8; 4],
}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: [u8; 4]Implementations§
Source§impl Icmpv4Hdr
impl Icmpv4Hdr
pub const LEN: usize
pub fn icmp_type(&self) -> Result<Icmpv4Type, IcmpError>
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 data(&self) -> Result<Icmpv4HdrData<'_>, IcmpError>
pub fn data(&self) -> Result<Icmpv4HdrData<'_>, IcmpError>
Returns a type-safe view over the data bytes based on the ICMPv4 type.
Sourcepub fn data_mut(&mut self) -> Result<Icmpv4HdrDataMut<'_>, IcmpError>
pub fn data_mut(&mut self) -> Result<Icmpv4HdrDataMut<'_>, IcmpError>
Returns a mutable type-safe view over the data bytes based on the ICMPv4 type.
Source§impl Icmpv4Hdr
These are the unsafe alternatives to the safe functions on IcmpHdr that do prevent undefined behavior.
impl Icmpv4Hdr
These are the unsafe alternatives to the safe functions on IcmpHdr that do prevent undefined behavior.
Sourcepub unsafe fn id_sequence_unchecked(&self) -> &IcmpIdSequence
pub unsafe fn id_sequence_unchecked(&self) -> &IcmpIdSequence
Returns a reference to the ID and sequence fields. 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. Calling this method with other ICMP types may result in undefined behavior.
Sourcepub unsafe fn id_sequence_mut_unchecked(&mut self) -> &mut IcmpIdSequence
pub unsafe fn id_sequence_mut_unchecked(&mut self) -> &mut IcmpIdSequence
Returns a mutable reference to the ID and sequence fields. 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. Calling this method with other ICMP types may result in undefined behavior.
Sourcepub unsafe fn redirect_unchecked(&self) -> &Icmpv4Redirect
pub unsafe fn redirect_unchecked(&self) -> &Icmpv4Redirect
Returns a reference to the Redirect message payload (Type 5).
§Safety
Caller must ensure ICMP type is 5 (Redirect) before calling this function.
Sourcepub unsafe fn redirect_mut_unchecked(&mut self) -> &mut Icmpv4Redirect
pub unsafe fn redirect_mut_unchecked(&mut self) -> &mut Icmpv4Redirect
Returns a mutable reference to the Redirect message payload (Type 5).
§Safety
Caller must ensure ICMP type is 5 (Redirect) before calling this function.
Sourcepub unsafe fn destination_unreachable_unchecked(&self) -> &IcmpDstUnreachable
pub unsafe fn destination_unreachable_unchecked(&self) -> &IcmpDstUnreachable
Returns a reference to the 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 destination_unreachable_mut_unchecked(
&mut self,
) -> &mut IcmpDstUnreachable
pub unsafe fn destination_unreachable_mut_unchecked( &mut self, ) -> &mut IcmpDstUnreachable
Returns a mutable reference to the 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_problem_unchecked(&self) -> &Icmpv4ParamProblem
pub unsafe fn parameter_problem_unchecked(&self) -> &Icmpv4ParamProblem
Returns a reference to the 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 parameter_problem_mut_unchecked(
&mut self,
) -> &mut Icmpv4ParamProblem
pub unsafe fn parameter_problem_mut_unchecked( &mut self, ) -> &mut Icmpv4ParamProblem
Returns a reference to the 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_unchecked(&self) -> &IcmpTraceroute
pub unsafe fn traceroute_unchecked(&self) -> &IcmpTraceroute
Returns a reference the Traceroute message (Type 30). This is only valid for ICMP Type 30 (Traceroute Request).
§Safety
Caller must ensure ICMP type is 30 (Traceroute Request) before calling this function. Accessing the traceroute field with other ICMP types may result in undefined behavior.
Sourcepub unsafe fn traceroute_mut_unchecked(&mut self) -> &mut IcmpTraceroute
pub unsafe fn traceroute_mut_unchecked(&mut self) -> &mut IcmpTraceroute
Returns a mutable reference the Traceroute message (Type 30). This is only valid for ICMP Type 30 (Traceroute Request).
§Safety
Caller must ensure ICMP type is 30 (Traceroute Request) before calling this function. Accessing the traceroute field with other ICMP types may result in undefined behavior.
Sourcepub unsafe fn photuris_unchecked(&self) -> &IcmpHdrPhoturis
pub unsafe fn photuris_unchecked(&self) -> &IcmpHdrPhoturis
Returns a reference to the PHOTURIS message (Type 40).
§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_mut_unchecked(&mut self) -> &mut IcmpHdrPhoturis
pub unsafe fn photuris_mut_unchecked(&mut self) -> &mut IcmpHdrPhoturis
Returns a mutable reference to the PHOTURIS message (Type 40).
§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<'de, WincodeConfig: Config> SchemaRead<'de, WincodeConfig> for Icmpv4Hdr
impl<'de, WincodeConfig: Config> SchemaRead<'de, WincodeConfig> for Icmpv4Hdr
Source§impl<WincodeConfig: Config> SchemaWrite<WincodeConfig> for Icmpv4Hdr
impl<WincodeConfig: Config> SchemaWrite<WincodeConfig> for Icmpv4Hdr
Source§impl<WincodeConfig: Config> ZeroCopy<WincodeConfig> for Icmpv4Hdr
impl<WincodeConfig: Config> ZeroCopy<WincodeConfig> for Icmpv4Hdr
Source§fn from_bytes<'de>(bytes: &'de [u8], config: C) -> Result<&'de Self, ReadError>where
Self: Sized + SchemaRead<'de, C, Dst = Self>,
fn from_bytes<'de>(bytes: &'de [u8], config: C) -> Result<&'de Self, ReadError>where
Self: Sized + SchemaRead<'de, C, Dst = Self>,
crate::ZeroCopy::from_bytes, but allows the caller to provide a custom configuration.Source§fn from_bytes_mut<'de>(
bytes: &'de mut [u8],
config: C,
) -> Result<&'de mut Self, ReadError>where
Self: Sized + SchemaRead<'de, C, Dst = Self>,
fn from_bytes_mut<'de>(
bytes: &'de mut [u8],
config: C,
) -> Result<&'de mut Self, ReadError>where
Self: Sized + SchemaRead<'de, C, Dst = Self>,
crate::ZeroCopy::from_bytes_mut, but allows the caller to provide a custom configuration.impl Copy for Icmpv4Hdr
Auto Trait Implementations§
impl Freeze for Icmpv4Hdr
impl RefUnwindSafe for Icmpv4Hdr
impl Send for Icmpv4Hdr
impl Sync for Icmpv4Hdr
impl Unpin for Icmpv4Hdr
impl UnsafeUnpin for Icmpv4Hdr
impl UnwindSafe for Icmpv4Hdr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'de, T> Deserialize<'de> for Twhere
T: SchemaRead<'de, Configuration>,
impl<'de, T> Deserialize<'de> for Twhere
T: SchemaRead<'de, Configuration>,
Source§impl<'de, T, C> Deserialize<'de, C> for Twhere
C: Config,
T: SchemaRead<'de, C>,
impl<'de, T, C> Deserialize<'de, C> for Twhere
C: Config,
T: SchemaRead<'de, C>,
Source§impl<T, C> DeserializeOwned<C> for Twhere
C: Config,
T: SchemaReadOwned<C>,
impl<T, C> DeserializeOwned<C> for Twhere
C: Config,
T: SchemaReadOwned<C>,
Source§fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>
fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>
Reader into a new Self::Dst.Source§fn deserialize_from_into<'de>(
src: impl Reader<'de>,
dst: &mut MaybeUninit<Self::Dst>,
) -> Result<(), ReadError>
fn deserialize_from_into<'de>( src: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> Result<(), ReadError>
Reader into dst.Source§impl<T> DeserializeOwned for Twhere
T: SchemaReadOwned<Configuration>,
impl<T> DeserializeOwned for Twhere
T: SchemaReadOwned<Configuration>,
Source§fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>
fn deserialize_from<'de>(src: impl Reader<'de>) -> Result<Self::Dst, ReadError>
Reader into a new Self::Dst.Source§fn deserialize_from_into<'de>(
src: impl Reader<'de>,
dst: &mut MaybeUninit<Self::Dst>,
) -> Result<(), ReadError>
fn deserialize_from_into<'de>( src: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>, ) -> Result<(), ReadError>
Reader into dst.Source§impl<T, C> Serialize<C> for T
impl<T, C> Serialize<C> for T
Source§fn serialize_into(
dst: impl Writer,
src: &Self::Src,
config: C,
) -> Result<(), WriteError>
fn serialize_into( dst: impl Writer, src: &Self::Src, config: C, ) -> Result<(), WriteError>
Writer.