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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::net::IpAddr;

#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
pub enum IpNextLevelProtocol {
    Icmp,
    Icmpv6,
    Tcp,
    Udp,
    Unknown(u8),
}

impl IpNextLevelProtocol {
    pub fn number(&self) -> u8 {
        match *self {
            IpNextLevelProtocol::Icmp => 1,
            IpNextLevelProtocol::Icmpv6 => 58,
            IpNextLevelProtocol::Tcp => 6,
            IpNextLevelProtocol::Udp => 17,
            IpNextLevelProtocol::Unknown(n) => n,
        }
    }
    pub fn name(&self) -> String {
        match *self {
            IpNextLevelProtocol::Icmp => String::from("ICMP"),
            IpNextLevelProtocol::Icmpv6 => String::from("ICMPv6"),
            IpNextLevelProtocol::Tcp => String::from("TCP"),
            IpNextLevelProtocol::Udp => String::from("UDP"),
            IpNextLevelProtocol::Unknown(n) => format!("Unknown({})", n),
        }
    }
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct IpFingerprint {
    pub source_ip: IpAddr,
    pub destination_ip: IpAddr,
    pub version: u8,
    pub ttl: u8,
    pub tos: u8,
    pub id: u16,
    pub df: bool,
    pub flags: u8,
    pub fragment_offset: u16,
    pub header_length: u8,
    pub total_length: u16,
    pub next_level_protocol: IpNextLevelProtocol,
}