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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use crate::PrimitiveValues;

use alloc::vec::Vec;

use pnet_base::core_net::Ipv4Addr;
use pnet_base::MacAddr;
use pnet_macros::packet;
use pnet_macros_support::types::*;

/// Represents an Dhcp operation.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DhcpOperation(pub u8);

impl DhcpOperation {
    /// Create a new `ArpOperation`.
    pub fn new(value: u8) -> Self {
        DhcpOperation(value)
    }
}

impl PrimitiveValues for DhcpOperation {
    type T = (u8,);
    fn to_primitive_values(&self) -> (u8,) {
        (self.0,)
    }
}

/// The Dhcp protocol operations.
#[allow(non_snake_case)]
#[allow(non_upper_case_globals)]
pub mod DhcpOperations {
    use super::DhcpOperation;

    /// DHCP request
    pub const Request: DhcpOperation = DhcpOperation(1);

    /// Dhcp reply
    pub const Reply: DhcpOperation = DhcpOperation(2);
}

/// Represents the Dhcp hardware types.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DhcpHardwareType(pub u8);

impl DhcpHardwareType {
    /// Create a new `DhcpHardwareType`.
    pub fn new(value: u8) -> Self {
        DhcpHardwareType(value)
    }
}

impl PrimitiveValues for DhcpHardwareType {
    type T = (u8,);
    fn to_primitive_values(&self) -> (u8,) {
        (self.0,)
    }
}

/// The Dhcp protocol hardware types.
#[allow(non_snake_case)]
#[allow(non_upper_case_globals)]
pub mod DhcpHardwareTypes {
    use super::DhcpHardwareType;

    /// Ethernet
    pub const Ethernet: DhcpHardwareType = DhcpHardwareType(1);
}

/// Represents an DHCP Packet.
#[packet]
#[allow(non_snake_case)]
pub struct Dhcp {
    #[construct_with(u8)]
    pub op: DhcpOperation,
    #[construct_with(u8)]
    pub htype: DhcpHardwareType,
    pub hlen: u8,
    pub hops: u8,
    pub xid: u32be,
    pub secs: u16be,
    pub flags: u16be,
    #[construct_with(u8, u8, u8, u8)]
    pub ciaddr: Ipv4Addr,
    #[construct_with(u8, u8, u8, u8)]
    pub yiaddr: Ipv4Addr,
    #[construct_with(u8, u8, u8, u8)]
    pub siaddr: Ipv4Addr,
    #[construct_with(u8, u8, u8, u8)]
    pub giaddr: Ipv4Addr,
    #[construct_with(u8, u8, u8, u8, u8, u8)]
    pub chaddr: MacAddr,
    #[length = "10"]
    pub chaddr_pad: Vec<u8>,
    #[length = "64"]
    pub sname: Vec<u8>,
    #[length = "128"]
    pub file: Vec<u8>,
    #[payload]
    pub options: Vec<u8>,
}