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.
Trait Implementations§
Source§impl Layer for IcmpLayer
impl Layer for IcmpLayer
Source§fn header_len(&self, data: &[u8]) -> usize
fn header_len(&self, data: &[u8]) -> usize
Source§fn answers(&self, data: &[u8], other: &Self, other_data: &[u8]) -> bool
fn answers(&self, data: &[u8], other: &Self, other_data: &[u8]) -> bool
Source§fn extract_padding<'a>(&self, data: &'a [u8]) -> (&'a [u8], &'a [u8])
fn extract_padding<'a>(&self, data: &'a [u8]) -> (&'a [u8], &'a [u8])
Source§fn field_names(&self) -> &'static [&'static str]
fn field_names(&self) -> &'static [&'static str]
Source§impl LayerDispatch for IcmpLayer
impl LayerDispatch for IcmpLayer
Source§fn dispatch_kind(&self) -> LayerKind
fn dispatch_kind(&self) -> LayerKind
Source§fn dispatch_index(&self) -> &LayerIndex
fn dispatch_index(&self) -> &LayerIndex
Source§fn dispatch_summary(&self, buf: &[u8]) -> String
fn dispatch_summary(&self, buf: &[u8]) -> String
Source§fn dispatch_header_len(&self, buf: &[u8]) -> usize
fn dispatch_header_len(&self, buf: &[u8]) -> usize
Source§fn dispatch_field_names(&self) -> &'static [&'static str]
fn dispatch_field_names(&self) -> &'static [&'static str]
Source§fn dispatch_get_field(
&self,
buf: &[u8],
name: &str,
) -> Option<Result<FieldValue, FieldError>>
fn dispatch_get_field( &self, buf: &[u8], name: &str, ) -> Option<Result<FieldValue, FieldError>>
Source§fn dispatch_set_field(
&self,
buf: &mut [u8],
name: &str,
value: FieldValue,
) -> Option<Result<(), FieldError>>
fn dispatch_set_field( &self, buf: &mut [u8], name: &str, value: FieldValue, ) -> Option<Result<(), FieldError>>
Auto Trait Implementations§
impl Freeze for IcmpLayer
impl RefUnwindSafe for IcmpLayer
impl Send for IcmpLayer
impl Sync for IcmpLayer
impl Unpin for IcmpLayer
impl UnsafeUnpin for IcmpLayer
impl UnwindSafe for IcmpLayer
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more