1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Protocol {
    ARP,
    NDP,
    ICMP,
    TCP,
    UDP,
}

impl Protocol {
    pub fn from_str(s: &str) -> Option<Protocol> {
        match s.to_lowercase().as_str() {
            "arp" => Some(Protocol::ARP),
            "ndp" => Some(Protocol::NDP),
            "icmp" => Some(Protocol::ICMP),
            "tcp" => Some(Protocol::TCP),
            "udp" => Some(Protocol::UDP),
            _ => None,
        }
    }
    pub fn to_str(&self) -> &str {
        match self {
            Protocol::ARP => "ARP",
            Protocol::NDP => "NDP",
            Protocol::ICMP => "ICMP",
            Protocol::TCP => "TCP",
            Protocol::UDP => "UDP",
        }
    }
}