packet_formats::icmp

Function peek_message_type

Source
pub fn peek_message_type<MessageType: TryFrom<u8>>(
    bytes: &[u8],
) -> ParseResult<MessageType>
Expand description

Peek at an ICMP header to see what message type is present.

Since IcmpPacket is statically typed with the message type expected, this type must be known ahead of time before calling parse. If multiple different types are valid in a given parsing context, and so the caller cannot know ahead of time which type to use, peek_message_type can be used to peek at the header first to figure out which static type should be used in a subsequent call to parse.

Note that peek_message_type only inspects certain fields in the header, and so peek_message_type succeeding does not guarantee that a subsequent call to parse will also succeed.