pub struct IcmpLayer {
pub index: LayerIndex,
}Expand description
ICMP layer representation.
ICMP is the control protocol for IP, defined in RFC 792. The header format varies based on message type:
Base header (all types):
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Code | Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| (Type-specific data) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Echo/Echo Reply (type 0, 8):
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identifier | Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Redirect (type 5):
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Gateway IP Address |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+Fields§
§index: LayerIndexImplementations§
Source§impl IcmpLayer
impl IcmpLayer
Sourcepub fn new(index: LayerIndex) -> Self
pub fn new(index: LayerIndex) -> Self
Create a new ICMP layer from a layer index.
Sourcepub fn id(&self, buf: &[u8]) -> Result<Option<u16>, FieldError>
pub fn id(&self, buf: &[u8]) -> Result<Option<u16>, FieldError>
Get the identifier (for echo, timestamp).
Returns None if this ICMP type doesn’t have an ID field.
Sourcepub fn seq(&self, buf: &[u8]) -> Result<Option<u16>, FieldError>
pub fn seq(&self, buf: &[u8]) -> Result<Option<u16>, FieldError>
Get the sequence number (for echo, timestamp).
Returns None if this ICMP type doesn’t have a sequence field.
Sourcepub fn gateway(&self, buf: &[u8]) -> Result<Option<Ipv4Addr>, FieldError>
pub fn gateway(&self, buf: &[u8]) -> Result<Option<Ipv4Addr>, FieldError>
Get the gateway address (for redirect messages).
Returns None if this is not a redirect message.
Sourcepub fn next_hop_mtu(&self, buf: &[u8]) -> Result<Option<u16>, FieldError>
pub fn next_hop_mtu(&self, buf: &[u8]) -> Result<Option<u16>, FieldError>
Get the next-hop MTU (for destination unreachable, fragmentation needed).
Returns None if this is not a dest unreachable with code 4 (fragmentation needed).
Sourcepub fn ptr(&self, buf: &[u8]) -> Result<Option<u8>, FieldError>
pub fn ptr(&self, buf: &[u8]) -> Result<Option<u8>, FieldError>
Get the pointer field (for parameter problem).
Returns None if this is not a parameter problem message.
Sourcepub fn ts_ori(&self, buf: &[u8]) -> Result<Option<u32>, FieldError>
pub fn ts_ori(&self, buf: &[u8]) -> Result<Option<u32>, FieldError>
Get the originate timestamp (for timestamp request/reply).
Returns None if this is not a timestamp message. Timestamp is in milliseconds since midnight UT.
Sourcepub fn ts_rx(&self, buf: &[u8]) -> Result<Option<u32>, FieldError>
pub fn ts_rx(&self, buf: &[u8]) -> Result<Option<u32>, FieldError>
Get the receive timestamp (for timestamp request/reply).
Returns None if this is not a timestamp message. Timestamp is in milliseconds since midnight UT.
Sourcepub fn ts_tx(&self, buf: &[u8]) -> Result<Option<u32>, FieldError>
pub fn ts_tx(&self, buf: &[u8]) -> Result<Option<u32>, FieldError>
Get the transmit timestamp (for timestamp request/reply).
Returns None if this is not a timestamp message. Timestamp is in milliseconds since midnight UT.
Sourcepub fn addr_mask(&self, buf: &[u8]) -> Result<Option<Ipv4Addr>, FieldError>
pub fn addr_mask(&self, buf: &[u8]) -> Result<Option<Ipv4Addr>, FieldError>
Get the address mask (for address mask request/reply).
Returns None if this is not an address mask message.
Sourcepub fn set_checksum(&self, buf: &mut [u8], value: u16) -> Result<(), FieldError>
pub fn set_checksum(&self, buf: &mut [u8], value: u16) -> Result<(), FieldError>
Set the checksum.
Sourcepub fn set_id(&self, buf: &mut [u8], value: u16) -> Result<(), FieldError>
pub fn set_id(&self, buf: &mut [u8], value: u16) -> Result<(), FieldError>
Set the identifier (for echo, timestamp).
Sourcepub fn set_seq(&self, buf: &mut [u8], value: u16) -> Result<(), FieldError>
pub fn set_seq(&self, buf: &mut [u8], value: u16) -> Result<(), FieldError>
Set the sequence number (for echo, timestamp).
Sourcepub fn set_gateway(
&self,
buf: &mut [u8],
value: Ipv4Addr,
) -> Result<(), FieldError>
pub fn set_gateway( &self, buf: &mut [u8], value: Ipv4Addr, ) -> Result<(), FieldError>
Set the gateway address (for redirect).
Sourcepub fn set_next_hop_mtu(
&self,
buf: &mut [u8],
value: u16,
) -> Result<(), FieldError>
pub fn set_next_hop_mtu( &self, buf: &mut [u8], value: u16, ) -> Result<(), FieldError>
Set the next-hop MTU (for destination unreachable, fragmentation needed).
Sourcepub fn set_ptr(&self, buf: &mut [u8], value: u8) -> Result<(), FieldError>
pub fn set_ptr(&self, buf: &mut [u8], value: u8) -> Result<(), FieldError>
Set the pointer field (for parameter problem).
Sourcepub fn set_ts_ori(&self, buf: &mut [u8], value: u32) -> Result<(), FieldError>
pub fn set_ts_ori(&self, buf: &mut [u8], value: u32) -> Result<(), FieldError>
Set the originate timestamp (for timestamp request/reply).
Sourcepub fn set_ts_rx(&self, buf: &mut [u8], value: u32) -> Result<(), FieldError>
pub fn set_ts_rx(&self, buf: &mut [u8], value: u32) -> Result<(), FieldError>
Set the receive timestamp (for timestamp request/reply).
Sourcepub fn set_ts_tx(&self, buf: &mut [u8], value: u32) -> Result<(), FieldError>
pub fn set_ts_tx(&self, buf: &mut [u8], value: u32) -> Result<(), FieldError>
Set the transmit timestamp (for timestamp request/reply).
Sourcepub fn set_addr_mask(
&self,
buf: &mut [u8],
value: Ipv4Addr,
) -> Result<(), FieldError>
pub fn set_addr_mask( &self, buf: &mut [u8], value: Ipv4Addr, ) -> Result<(), FieldError>
Set the address mask (for address mask request/reply).
Sourcepub fn header_len(&self, buf: &[u8]) -> usize
pub fn header_len(&self, buf: &[u8]) -> usize
Get the ICMP header length (variable based on type).
Sourcepub fn field_names(&self) -> &'static [&'static str]
pub fn field_names(&self) -> &'static [&'static str]
Get field names for this layer.
Sourcepub fn get_field(
&self,
buf: &[u8],
name: &str,
) -> Option<Result<FieldValue, FieldError>>
pub fn get_field( &self, buf: &[u8], name: &str, ) -> Option<Result<FieldValue, FieldError>>
Get a field value by name.
Sourcepub fn set_field(
&self,
buf: &mut [u8],
name: &str,
value: FieldValue,
) -> Option<Result<(), FieldError>>
pub fn set_field( &self, buf: &mut [u8], name: &str, value: FieldValue, ) -> Option<Result<(), FieldError>>
Set a field value by name.