Struct etherparse::Icmpv4Slice
source · pub struct Icmpv4Slice<'a> { /* private fields */ }
Expand description
A slice containing an ICMPv4 network package.
Struct allows the selective read of fields in the ICMPv4 packet.
Implementations§
source§impl<'a> Icmpv4Slice<'a>
impl<'a> Icmpv4Slice<'a>
sourcepub fn from_slice(slice: &'a [u8]) -> Result<Icmpv4Slice<'a>, LenError>
pub fn from_slice(slice: &'a [u8]) -> Result<Icmpv4Slice<'a>, LenError>
Creates a slice containing an ICMPv4 packet.
§Errors
The function will return an Err
err::LenError
if the given slice is too small or does not match the expected
length in case of a timestamp message.
sourcepub fn header(&self) -> Icmpv4Header
pub fn header(&self) -> Icmpv4Header
Decode the header values into an Icmpv4Header
struct.
sourcepub fn header_len(&self) -> usize
pub fn header_len(&self) -> usize
Number of bytes/octets that will be converted into a
Icmpv4Header
when Icmpv4Slice::header
gets called.
sourcepub fn icmp_type(&self) -> Icmpv4Type
pub fn icmp_type(&self) -> Icmpv4Type
Decode the header values (excluding the checksum) into an Icmpv4Type
enum.
sourcepub fn bytes5to8(&self) -> [u8; 4]
pub fn bytes5to8(&self) -> [u8; 4]
Returns the bytes from position 4 till and including the 8th position in the ICMPv4 header.
These bytes located at th 5th, 6th, 7th and 8th position of the ICMP packet can depending on the ICMPv4 type and code contain additional data.
sourcepub fn payload(&self) -> &'a [u8] ⓘ
pub fn payload(&self) -> &'a [u8] ⓘ
Returns a slice to the bytes not covered by .header()
.
The contents of the slice returned by payload()
depends on the type
and code of the ICMP packet:
.header().icmp_type or .icmp_type() | Payload Content |
---|---|
Icmpv4Type::EchoReply Icmpv4Type::EchoRequest | Data part of the echo message |
Icmpv4Type::DestinationUnreachable Icmpv4Type::Redirect Icmpv4Type::TimeExceeded Icmpv4Type::ParameterProblem | Internet Header + 64 bits of Original Data Datagram causing the ICMP message |
Icmpv4Type::TimestampRequest Icmpv4Type::TimestampReply | Nothing |
Icmpv4Type::Unknown | Everything after the 8th byte/octet of the ICMP packet. |
Trait Implementations§
source§impl<'a> Clone for Icmpv4Slice<'a>
impl<'a> Clone for Icmpv4Slice<'a>
source§fn clone(&self) -> Icmpv4Slice<'a>
fn clone(&self) -> Icmpv4Slice<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for Icmpv4Slice<'a>
impl<'a> Debug for Icmpv4Slice<'a>
source§impl<'a> PartialEq for Icmpv4Slice<'a>
impl<'a> PartialEq for Icmpv4Slice<'a>
source§fn eq(&self, other: &Icmpv4Slice<'a>) -> bool
fn eq(&self, other: &Icmpv4Slice<'a>) -> bool
self
and other
values to be equal, and is used
by ==
.