summaryrefslogtreecommitdiff
path: root/tests/expectations/tests/layout_arp.rs
blob: 390c87aa81e17614450a8dacf5c0011cc3167365 (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#![allow(
    dead_code,
    non_snake_case,
    non_camel_case_types,
    non_upper_case_globals
)]

pub const ETHER_ADDR_LEN: u32 = 6;
pub const ARP_HRD_ETHER: u32 = 1;
pub const ARP_OP_REQUEST: u32 = 1;
pub const ARP_OP_REPLY: u32 = 2;
pub const ARP_OP_REVREQUEST: u32 = 3;
pub const ARP_OP_REVREPLY: u32 = 4;
pub const ARP_OP_INVREQUEST: u32 = 8;
pub const ARP_OP_INVREPLY: u32 = 9;
/// Ethernet address:
/// A universally administered address is uniquely assigned to a device by its
/// manufacturer. The first three octets (in transmission order) contain the
/// Organizationally Unique Identifier (OUI). The following three (MAC-48 and
/// EUI-48) octets are assigned by that organization with the only constraint
/// of uniqueness.
/// A locally administered address is assigned to a device by a network
/// administrator and does not contain OUIs.
/// See http://standards.ieee.org/regauth/groupmac/tutorial.html
#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone)]
pub struct ether_addr {
    ///< Addr bytes in tx order
    pub addr_bytes: [u8; 6usize],
}
#[test]
fn bindgen_test_layout_ether_addr() {
    assert_eq!(
        ::std::mem::size_of::<ether_addr>(),
        6usize,
        concat!("Size of: ", stringify!(ether_addr))
    );
    assert_eq!(
        ::std::mem::align_of::<ether_addr>(),
        1usize,
        concat!("Alignment of ", stringify!(ether_addr))
    );
    assert_eq!(
        unsafe {
            let uninit = ::std::mem::MaybeUninit::<ether_addr>::uninit();
            let ptr = uninit.as_ptr();
            ::std::ptr::addr_of!((*ptr).addr_bytes) as usize - ptr as usize
        },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(ether_addr),
            "::",
            stringify!(addr_bytes)
        )
    );
}
/// ARP header IPv4 payload.
#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone)]
pub struct arp_ipv4 {
    ///< sender hardware address
    pub arp_sha: ether_addr,
    ///< sender IP address
    pub arp_sip: u32,
    ///< target hardware address
    pub arp_tha: ether_addr,
    ///< target IP address
    pub arp_tip: u32,
}
#[test]
fn bindgen_test_layout_arp_ipv4() {
    assert_eq!(
        ::std::mem::size_of::<arp_ipv4>(),
        20usize,
        concat!("Size of: ", stringify!(arp_ipv4))
    );
    assert_eq!(
        ::std::mem::align_of::<arp_ipv4>(),
        1usize,
        concat!("Alignment of ", stringify!(arp_ipv4))
    );
    assert_eq!(
        unsafe {
            let uninit = ::std::mem::MaybeUninit::<arp_ipv4>::uninit();
            let ptr = uninit.as_ptr();
            ::std::ptr::addr_of!((*ptr).arp_sha) as usize - ptr as usize
        },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(arp_ipv4),
            "::",
            stringify!(arp_sha)
        )
    );
    assert_eq!(
        unsafe {
            let uninit = ::std::mem::MaybeUninit::<arp_ipv4>::uninit();
            let ptr = uninit.as_ptr();
            ::std::ptr::addr_of!((*ptr).arp_sip) as usize - ptr as usize
        },
        6usize,
        concat!(
            "Offset of field: ",
            stringify!(arp_ipv4),
            "::",
            stringify!(arp_sip)
        )
    );
    assert_eq!(
        unsafe {
            let uninit = ::std::mem::MaybeUninit::<arp_ipv4>::uninit();
            let ptr = uninit.as_ptr();
            ::std::ptr::addr_of!((*ptr).arp_tha) as usize - ptr as usize
        },
        10usize,
        concat!(
            "Offset of field: ",
            stringify!(arp_ipv4),
            "::",
            stringify!(arp_tha)
        )
    );
    assert_eq!(
        unsafe {
            let uninit = ::std::mem::MaybeUninit::<arp_ipv4>::uninit();
            let ptr = uninit.as_ptr();
            ::std::ptr::addr_of!((*ptr).arp_tip) as usize - ptr as usize
        },
        16usize,
        concat!(
            "Offset of field: ",
            stringify!(arp_ipv4),
            "::",
            stringify!(arp_tip)
        )
    );
}
/// ARP header.
#[repr(C, packed)]
#[derive(Debug, Default, Copy, Clone)]
pub struct arp_hdr {
    pub arp_hrd: u16,
    pub arp_pro: u16,
    pub arp_hln: u8,
    pub arp_pln: u8,
    pub arp_op: u16,
    pub arp_data: arp_ipv4,
}
#[test]
fn bindgen_test_layout_arp_hdr() {
    assert_eq!(
        ::std::mem::size_of::<arp_hdr>(),
        28usize,
        concat!("Size of: ", stringify!(arp_hdr))
    );
    assert_eq!(
        ::std::mem::align_of::<arp_hdr>(),
        1usize,
        concat!("Alignment of ", stringify!(arp_hdr))
    );
    assert_eq!(
        unsafe {
            let uninit = ::std::mem::MaybeUninit::<arp_hdr>::uninit();
            let ptr = uninit.as_ptr();
            ::std::ptr::addr_of!((*ptr).arp_hrd) as usize - ptr as usize
        },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(arp_hdr),
            "::",
            stringify!(arp_hrd)
        )
    );
    assert_eq!(
        unsafe {
            let uninit = ::std::mem::MaybeUninit::<arp_hdr>::uninit();
            let ptr = uninit.as_ptr();
            ::std::ptr::addr_of!((*ptr).arp_pro) as usize - ptr as usize
        },
        2usize,
        concat!(
            "Offset of field: ",
            stringify!(arp_hdr),
            "::",
            stringify!(arp_pro)
        )
    );
    assert_eq!(
        unsafe {
            let uninit = ::std::mem::MaybeUninit::<arp_hdr>::uninit();
            let ptr = uninit.as_ptr();
            ::std::ptr::addr_of!((*ptr).arp_hln) as usize - ptr as usize
        },
        4usize,
        concat!(
            "Offset of field: ",
            stringify!(arp_hdr),
            "::",
            stringify!(arp_hln)
        )
    );
    assert_eq!(
        unsafe {
            let uninit = ::std::mem::MaybeUninit::<arp_hdr>::uninit();
            let ptr = uninit.as_ptr();
            ::std::ptr::addr_of!((*ptr).arp_pln) as usize - ptr as usize
        },
        5usize,
        concat!(
            "Offset of field: ",
            stringify!(arp_hdr),
            "::",
            stringify!(arp_pln)
        )
    );
    assert_eq!(
        unsafe {
            let uninit = ::std::mem::MaybeUninit::<arp_hdr>::uninit();
            let ptr = uninit.as_ptr();
            ::std::ptr::addr_of!((*ptr).arp_op) as usize - ptr as usize
        },
        6usize,
        concat!(
            "Offset of field: ",
            stringify!(arp_hdr),
            "::",
            stringify!(arp_op)
        )
    );
    assert_eq!(
        unsafe {
            let uninit = ::std::mem::MaybeUninit::<arp_hdr>::uninit();
            let ptr = uninit.as_ptr();
            ::std::ptr::addr_of!((*ptr).arp_data) as usize - ptr as usize
        },
        8usize,
        concat!(
            "Offset of field: ",
            stringify!(arp_hdr),
            "::",
            stringify!(arp_data)
        )
    );
}