Struct etherparse::Icmpv4Header
source · pub struct Icmpv4Header {
pub icmp_type: Icmpv4Type,
pub checksum: u16,
}
Expand description
A header of an ICMPv4 packet.
What is part of the header depends on the ICMPv4 type and code. But usually the static sized elements are part of the header.
Fields§
§icmp_type: Icmpv4Type
Type & type specific values & code.
checksum: u16
Checksum in the ICMP header.
Implementations§
source§impl Icmpv4Header
impl Icmpv4Header
sourcepub const MIN_LEN: usize = 8usize
pub const MIN_LEN: usize = 8usize
Minimum number of bytes/octets an Icmpv4Header takes up in serialized form.
sourcepub const MIN_SERIALIZED_SIZE: usize = 8usize
👎Deprecated since 0.14.0: Please use Icmpv4Header::MIN_LEN instead
pub const MIN_SERIALIZED_SIZE: usize = 8usize
Deprecated, use Icmpv4Header::MIN_LEN
instead.
sourcepub const MAX_LEN: usize = 20usize
pub const MAX_LEN: usize = 20usize
Maximum number of bytes/octets an Icmpv4Header takes up in serialized form.
Currently this number is determined by the biggest supported ICMPv4 header type, which is currently the “Timestamp” and “Timestamp Reply Message”.
sourcepub const MAX_SERIALIZED_SIZE: usize = 20usize
👎Deprecated since 0.14.0: Please use Icmpv4Header::MAX_LEN instead
pub const MAX_SERIALIZED_SIZE: usize = 20usize
Deprecated, use Icmpv4Header::MAX_LEN
instead.
sourcepub fn new(icmp_type: Icmpv4Type) -> Icmpv4Header
pub fn new(icmp_type: Icmpv4Type) -> Icmpv4Header
Constructs an Icmpv4Header
using the given type
and the checksum set to 0.
sourcepub fn with_checksum(icmp_type: Icmpv4Type, payload: &[u8]) -> Icmpv4Header
pub fn with_checksum(icmp_type: Icmpv4Type, payload: &[u8]) -> Icmpv4Header
Creates a Icmpv4Header
with a checksum calculated based on the given payload.
sourcepub fn from_slice(slice: &[u8]) -> Result<(Icmpv4Header, &[u8]), LenError>
pub fn from_slice(slice: &[u8]) -> Result<(Icmpv4Header, &[u8]), LenError>
Reads an icmp4 header from a slice directly and returns a tuple containing the resulting header & unused part of the slice.
sourcepub fn read<T: Read + Sized>(reader: &mut T) -> Result<Icmpv4Header, Error>
Available on crate feature std
only.
pub fn read<T: Read + Sized>(reader: &mut T) -> Result<Icmpv4Header, Error>
std
only.Reads an ICMPv4 header from the given reader.
sourcepub fn write<T: Write + Sized>(&self, writer: &mut T) -> Result<(), Error>
Available on crate feature std
only.
pub fn write<T: Write + Sized>(&self, writer: &mut T) -> Result<(), Error>
std
only.Write the ICMPv4 header to the given writer.
sourcepub fn header_len(&self) -> usize
pub fn header_len(&self) -> usize
Length in bytes/octets of this header type.
sourcepub fn fixed_payload_size(&self) -> Option<usize>
pub fn fixed_payload_size(&self) -> Option<usize>
If the ICMP type has a fixed size returns the number of bytes that should be present after the header of this type.
sourcepub fn update_checksum(&mut self, payload: &[u8])
pub fn update_checksum(&mut self, payload: &[u8])
Calculates & updates the checksum in the header.
Note this method assumes that all unused bytes/octets are filled with zeroes.
Trait Implementations§
source§impl Clone for Icmpv4Header
impl Clone for Icmpv4Header
source§fn clone(&self) -> Icmpv4Header
fn clone(&self) -> Icmpv4Header
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Icmpv4Header
impl Debug for Icmpv4Header
source§impl PartialEq for Icmpv4Header
impl PartialEq for Icmpv4Header
source§fn eq(&self, other: &Icmpv4Header) -> bool
fn eq(&self, other: &Icmpv4Header) -> bool
self
and other
values to be equal, and is used
by ==
.