packet_formats::igmp

Function peek_message_type

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

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

Since IgmpPacket 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.

Because IGMP reuses the message type field for different semantic meanings between IGMP v2 and v3, peek_message_type also returns a boolean indicating if it’s a “long message”, which should direct parsers into parsing an IGMP v3 message.

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.