net_wire/arp/types.rs
1//! ARP type-field wrappers from RFC 826 and IANA registries.
2
3/// An ARP hardware type from the IANA ARP Parameters registry.
4#[repr(transparent)]
5#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
6pub struct ArpHardwareType(u16);
7
8impl ArpHardwareType {
9 /// Ethernet hardware type (`1`) defined by RFC 826.
10 pub const ETHERNET: Self = Self(1);
11
12 /// Preserves an encoded hardware-type value, including unassigned values.
13 #[inline]
14 pub const fn new(raw: u16) -> Self {
15 Self(raw)
16 }
17
18 /// Returns the host-order value encoded in the hardware-type field.
19 #[inline]
20 pub const fn raw(self) -> u16 {
21 self.0
22 }
23}
24
25/// An ARP protocol type, conventionally an EtherType, from RFC 826.
26#[repr(transparent)]
27#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
28pub struct ArpProtocolType(u16);
29
30impl ArpProtocolType {
31 /// Internet Protocol version 4 protocol type (`0x0800`).
32 pub const IPV4: Self = Self(0x0800);
33
34 /// Preserves an encoded protocol-type value, including unassigned values.
35 #[inline]
36 pub const fn new(raw: u16) -> Self {
37 Self(raw)
38 }
39
40 /// Returns the host-order value encoded in the protocol-type field.
41 #[inline]
42 pub const fn raw(self) -> u16 {
43 self.0
44 }
45}
46
47/// An ARP operation value from RFC 826.
48#[repr(transparent)]
49#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
50pub struct ArpOperation(u16);
51
52impl ArpOperation {
53 /// ARP request operation (`1`).
54 pub const REQUEST: Self = Self(1);
55 /// ARP reply operation (`2`).
56 pub const REPLY: Self = Self(2);
57
58 /// Preserves an encoded operation value, including unassigned values.
59 #[inline]
60 pub const fn new(raw: u16) -> Self {
61 Self(raw)
62 }
63
64 /// Returns the host-order value encoded in the operation field.
65 #[inline]
66 pub const fn raw(self) -> u16 {
67 self.0
68 }
69}