rusty_pcap/
link_type.rs

1//! Link types for pcap and pcap-ng files
2//!
3//! Source: <https://www.tcpdump.org/linktypes.html>
4use thiserror::Error;
5#[derive(Debug, Error)]
6#[error("Invalid link type: {0}")]
7pub struct InvalidLinkType(pub u16);
8macro_rules! link_type {
9    (
10        $(
11            $name:ident = $value:literal
12        ),*
13    ) => {
14        /// Represents the link type for pcap and pcap-ng files
15        #[derive(Debug, Clone, Copy, PartialEq, Eq)]
16        #[repr(u16)]
17        pub enum LinkType {
18            $(
19                $name = $value,
20            )*
21        }
22
23        impl TryFrom<u16> for LinkType {
24            type Error = InvalidLinkType;
25
26            fn try_from(value: u16) -> Result<Self, Self::Error> {
27                match value {
28                    $(
29                        $value => Ok(LinkType::$name),
30                    )*
31                    _ => Err(InvalidLinkType(value)),
32                }
33            }
34        }
35        impl TryFrom<u32> for LinkType {
36            type Error = InvalidLinkType;
37
38            fn try_from(value: u32) -> Result<Self, Self::Error> {
39                match value {
40                    $(
41                        $value => Ok(LinkType::$name),
42                    )*
43                    _ => Err(InvalidLinkType(value as u16)),
44                }
45            }
46        }
47    };
48}
49link_type! {
50    // Standard Link Types
51    Null = 0,
52    Ethernet = 1,
53    Ax25 = 3,
54    Ieee802_5 = 6,
55    ArcnetBsd = 7,
56    Slip = 8,
57    Ppp = 9,
58    Fddi = 10,
59
60    // HDLC and PPP Variants
61    PppHdlc = 50,
62    PppEther = 51,
63    CHdlc = 104,
64    PppPppd = 166,
65    PppWithDir = 204,
66    CHdlcWithDir = 205,
67    FrelayWithDir = 206,
68
69    // ATM, FR, and Raw IP
70    AtmRfc1483 = 100,
71    Raw = 101,
72    Frelay = 107,
73    Mfr = 182,
74
75    // Wireless and Bluetooth
76    Ieee802_11 = 105,
77    Ieee802_11Prism = 119,
78    Ieee802_11Radiotap = 127,
79    Ieee802_11Avs = 163,
80    BluetoothHciH4 = 187,
81    Ieee802_15_4Withfcs = 195,
82    BluetoothHciH4WithPhdr = 201,
83    Ieee802_15_4NonaskPhy = 215,
84    Ieee802_15_4Nofcs = 230,
85    BluetoothLeLl = 251,
86    BluetoothLinuxMonitor = 254,
87    BluetoothBredrBb = 255,
88    BluetoothLeLlWithPhdr = 256,
89    Ieee802_15_4Tap = 283,
90
91    // Operating System Specific
92    Loop = 108,
93    LinuxSll = 113,
94    Pflog = 117,
95    ArcnetLinux = 129,
96    LinuxIrda = 144,
97    LinuxLapd = 177,
98    UsbLinux = 189,
99    UsbLinuxMmapped = 220,
100    Ipnet = 226,
101    CanSocketcan = 227,
102    Nflog = 239,
103    Netlink = 253,
104    Pktap = 258,
105    UsbDarwin = 266,
106    Vsock = 271,
107    LinuxSll2 = 276,
108
109    // SS7 and Telecommunication
110    Mtp2WithPhdr = 139,
111    Mtp2 = 140,
112    Mtp3 = 141,
113    Sccp = 142,
114    GprsLlc = 169,
115    GpfT = 170,
116    GpfF = 171,
117
118    // Industrial & Embedded
119    IpmbLinux = 209,
120    RtacSerial = 250,
121    ProfibusDl = 257,
122    ZwaveR1R2 = 261,
123    ZwaveR3 = 262,
124    WattstopperDlm = 263,
125    ZWaveSerial = 287,
126
127    // Networking/Other
128    Ltalk = 114,
129    IpOverFc = 122,
130    Sunatm = 123,
131    AppleIpOverIeee1394 = 138,
132    Docsis = 143,
133    BacnetMsTp = 165,
134    Sita = 196,
135    Erf = 197,
136    Ax25Kiss = 202,
137    Lapd = 203,
138    LapbWithDir = 207,
139    Fc2 = 224,
140    Fc2WithFrameDelims = 225,
141    Ipv4 = 228,
142    Ipv6 = 229,
143    Dbus = 231,
144    DvbCi = 235,
145    Mux27010 = 236,
146    Stanag5066DPdu = 237,
147    Netanalyzer = 240,
148    NetanalyzerTransparent = 241,
149    Ipoib = 242,
150    Mpeg2Ts = 243,
151    Ng40 = 244,
152    NfcLlcp = 245,
153    Infiniband = 247,
154    Sctp = 248,
155    UsbPcap = 249,
156    Ppi = 192,
157    Epon = 259,
158    IpmiHpm2 = 260,
159    Iso14443 = 264,
160    Rds = 265,
161    Sdlc = 268,
162    Loratap = 270,
163    NordicBle = 272,
164    Docsis31Xra31 = 273,
165    EthernetMpacket = 274,
166    DisplayportAux = 275,
167    Openvizsla = 278,
168    Ebhscr = 279,
169    VppDispatch = 280,
170    DsaTagBrcm = 281,
171    DsaTagBrcmPrepend = 282,
172    DsaTagDsa = 284,
173    DsaTagEdsa = 285,
174    Elee = 286,
175    Usb2_0 = 288,
176    AtscAlp = 289
177}
178#[allow(clippy::derivable_impls)]
179impl Default for LinkType {
180    fn default() -> Self {
181        LinkType::Null
182    }
183}