rips_packets/
ip.rs

1/// Represents the eight bit header field in IPv4/IPv6 that defines what protocol the payload has.
2/// See [this list] for the full definition.
3///
4/// [this list]: https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers
5#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
6pub struct Protocol(pub u8);
7
8impl Protocol {
9    pub const ICMP: Protocol = Protocol(1);
10    pub const TCP: Protocol = Protocol(6);
11    pub const UDP: Protocol = Protocol(17);
12    pub const RESERVED: Protocol = Protocol(255);
13
14    /// Returns the numeric representation of this protocol.
15    #[inline]
16    pub fn value(&self) -> u8 {
17        self.0
18    }
19
20    pub fn is_unassigned(&self) -> bool {
21        self.0 >= 143 && self.0 <= 252
22    }
23
24    pub fn is_experimental(&self) -> bool {
25        self.0 >= 253 && self.0 <= 254
26    }
27}