Enum etherparse::Icmpv4Type

source ·
pub enum Icmpv4Type {
    Unknown {
        type_u8: u8,
        code_u8: u8,
        bytes5to8: [u8; 4],
    },
    EchoReply(IcmpEchoHeader),
    DestinationUnreachable(DestUnreachableHeader),
    Redirect(RedirectHeader),
    EchoRequest(IcmpEchoHeader),
    TimeExceeded(TimeExceededCode),
    ParameterProblem(ParameterProblemHeader),
    TimestampRequest(TimestampMessage),
    TimestampReply(TimestampMessage),
}
Expand description

Starting contents of an ICMPv4 packet without the checksum.

Variants§

§

Unknown

In case of an unknown ICMP type and code combination is received the header elements are stored raw in this enum value. The Unknown value can also be passed to the Icmpv4Header::write function to write arbitrary ICMP packets.

§What is part of the header for Icmpv4Type::Unknown?

For unknown ICMP type & code combination the first 8 bytes are stored in the Icmpv4Header and the rest is stored in the payload (Icmpv4Slice::payload or PacketHeaders::payload).

0               1               2               3               4
+---------------------------------------------------------------+  -
|     type_u8   |    code_u8    |  checksum (in Icmpv4Header)   |  |
+---------------------------------------------------------------+  | part of header & type
|                          bytes5to8                            |  ↓
+---------------------------------------------------------------+  -
|                                                               |  |
...                           ...                             ...  | part of payload
|                                                               |  ↓
+---------------------------------------------------------------+  -

Fields

§type_u8: u8

ICMP type (present in the first byte of the ICMP packet).

§code_u8: u8

ICMP code (present in the 2nd byte of the ICMP packet).

§bytes5to8: [u8; 4]

Bytes located at th 5th, 6th, 7th and 8th position of the ICMP packet.

§

EchoReply(IcmpEchoHeader)

Response to an EchoRequest message (defined in RFC792).

§What is part of the header for Icmpv4Type::EchoReply?

For the Icmpv4Type::EchoReply type the first 8 bytes/octets of the ICMP packet are part of the header. This includes the id and seq fields. The data part of the ICMP Echo Reply packet is part of the payload (Icmpv4Slice::payload or PacketHeaders::payload) and not part of the Icmpv4Header.

0               1               2               3               4
+---------------------------------------------------------------+  -
|       0       |       0       |  checksum (in Icmpv4Header)   |  |
+---------------------------------------------------------------+  | part of header & type
|          [value].id           |         [value].seq           |  ↓
+---------------------------------------------------------------+  -
|                                                               |  |
...                          <data>                           ...  | part of payload
|                                                               |  ↓
+---------------------------------------------------------------+  -
§

DestinationUnreachable(DestUnreachableHeader)

Message sent to inform the client that the destination is unreachable for some reason (defined in RFC792).

§What is part of the header for Icmpv4Type::DestinationUnreachable?

For the Icmpv4Type::DestinationUnreachable type the first 8 bytes/octets of the ICMP packet are part of the header. This includes the next_hop_mtu field. The unused part is not stored and droped. The offending packet is stored in the payload part of the packet (Icmpv4Slice::payload or PacketHeaders::payload) and is not part of the Icmpv4Header.

0               1               2               3               4
+---------------------------------------------------------------+  -
|       3       |       0       |  checksum (in Icmpv4Header)   |  |
+---------------------------------------------------------------+  | part of header & type
|[v].next_hop...|                    <unused>                   |  ↓
+---------------------------------------------------------------+  -
|                                                               |  |
...    Internet Header + 64 bits of Original Data Datagram    ...  | part of payload
|                                                               |  ↓
+---------------------------------------------------------------+  -
§

Redirect(RedirectHeader)

Requests data packets be sent on an alternative route (defined in RFC792).

§What is part of the header for Icmpv4Type::Redirect?

For the Icmpv4Type::Redirect type the first 8 bytes/octets of the ICMP packet are part of the header. This includes the gateway_internet_address field. The offending packet is stored in the payload part of the packet (Icmpv4Slice::payload or PacketHeaders::payload) and is not part of the Icmpv4Header.

0               1               2               3               4
+---------------------------------------------------------------+  -
|       5       | [value].code  |  checksum (in Icmpv4Header)   |  |
+---------------------------------------------------------------+  | part of header & type
|                [value].gateway_internet_address               |  ↓
+---------------------------------------------------------------+  -
|                                                               |  |
..     Internet Header + 64 bits of Original Data Datagram    ...  | part of payload
|                                                               |  ↓
+---------------------------------------------------------------+  -
§

EchoRequest(IcmpEchoHeader)

Requesting an EchoReply from the receiver (defined in RFC792)

§What is part of the header for Icmpv4Type::EchoRequest?

For the Icmpv4Type::EchoRequest type the first 8 bytes/octets of the ICMP packet are part of the header. This includes the id and seq fields. The data part of the ICMP echo request packet is part of the payload (Icmpv4Slice::payload & PacketHeaders::payload) and not part of the Icmpv4Header.

0               1               2               3               4
+---------------------------------------------------------------+  -
|       8       |       0       |  checksum (in Icmpv4Header)   |  |
+---------------------------------------------------------------+  | part of header & type
|          [value].id           |         [value].seq           |  ↓
+---------------------------------------------------------------+  -
|                                                               |  |
...                          <data>                           ...  | part of payload
|                                                               |  ↓
+---------------------------------------------------------------+  -
§

TimeExceeded(TimeExceededCode)

Generated when a datagram had to be discarded due to the time to live field reaching zero (defined in RFC792).

§What is part of the header for Icmpv4Type::TimeExceeded?

For the Icmpv4Type::TimeExceeded type the first 8 bytes/octets of the ICMP packet are part of the header. The unused part is not stored and droped. The offending packet is stored in the payload part of the packet (Icmpv4Slice::payload & PacketHeaders::payload) and is not part of the Icmpv4Header.

0               1               2               3               4
+---------------------------------------------------------------+  -
|       11      | [value as u8] |  checksum (in Icmpv4Header)   |  |
+---------------------------------------------------------------+  | part of header & type
|                           <unused>                            |  ↓
+---------------------------------------------------------------+  -
|                                                               |  |
...    Internet Header + 64 bits of Original Data Datagram    ...  | part of payload
|                                                               |  ↓
+---------------------------------------------------------------+  -
§

ParameterProblem(ParameterProblemHeader)

Sent if there is a problem with a parameter in a received packet.

§What is part of the header for Icmpv4Type::ParameterProblem?

For the Icmpv4Type::ParameterProblem type the first 8 bytes/octets of the ICMP packet are part of the header. The unused part is not stored and droped. The offending packet is stored in the payload part of the packet (Icmpv4Slice::payload & PacketHeaders::payload) and is not part of the Icmpv4Header.

0               1               2               3               4
+---------------------------------------------------------------+  -
|       12      | [v].code_u8() |  checksum (in Icmpv4Header)   |  |
+---------------------------------------------------------------+  | part of header & type
|[value].pointer|                   <unused>                    |  ↓
+---------------------------------------------------------------+  -
|                                                               |  |
...    Internet Header + 64 bits of Original Data Datagram    ...  | part of payload
|                                                               |  ↓
+---------------------------------------------------------------+  -
§

TimestampRequest(TimestampMessage)

Timestamp is used for time synchronization.

§What is part of the header for Icmpv4Type::TimestampRequest?

For the Icmpv4Type::TimestampRequest type the entire ICMP packet is contained within the header. The payload data is empty.

§

TimestampReply(TimestampMessage)

Anwser to a TimestampRequest message.

§What is part of the header for Icmpv4Type::TimestampReply?

For the Icmpv4Type::TimestampReply type the entire ICMP packet is contained within the header. The payload data is empty.

Implementations§

source§

impl Icmpv4Type

source

pub fn header_len(&self) -> usize

Returns the length in bytes/octets of the header of this ICMPv4 message type.

source

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.

source

pub fn calc_checksum(&self, payload: &[u8]) -> u16

Calculate the ICMP checksum value.

Trait Implementations§

source§

impl Clone for Icmpv4Type

source§

fn clone(&self) -> Icmpv4Type

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Icmpv4Type

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for Icmpv4Type

source§

fn eq(&self, other: &Icmpv4Type) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Icmpv4Type

source§

impl StructuralPartialEq for Icmpv4Type

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.