linktype/
lib.rs

1use num_enum::FromPrimitive;
2
3/**
4### This enum is used to represent the type of link layer found in a pcap file.
5Each variant represents a different type of link layer, with a corresponding integer value that is present in the last 4 bytes of a pcap file.
6
7If you find a mistake or want to add a new variant, please open an issue or a pull request.
8
9Reference: https://www.tcpdump.org/linktypes.html
10
11#### Example
12```rust
13use linktype::LinkType;
14
15let link_type = LinkType::Ethernet;
16println!("Link type: {:?}", link_type);
17
18match link_type {
19    LinkType::Ethernet => {
20        // Adjust code execution according to the link type
21    },
22    _ => println!("Unknown link type"),
23}
24
25let some_link_value=1;
26let link_type=LinkType::from_u32(some_link_value);
27println!("Link type: {:?}", link_type);
28
29```
30
31 */
32#[derive(Debug, FromPrimitive)]
33#[repr(u32)]
34pub enum LinkType {
35    Null = 0,
36    Ethernet = 1,
37    ExpEthernet = 2,
38    AX25 = 3,
39    Pronet = 4,
40    Chaos = 5,
41    Ieee8025 = 6,
42    ArcnetBSD = 7,
43    Slip = 8,
44    Ppp = 9,
45    Fddi = 10,
46    PppHdlc = 50,
47    PppEther = 51,
48    SymantecFirewall = 99,
49    AtmRfc1483 = 100,
50    Raw = 101,
51    Chdlc = 104,
52    Ieee80211 = 105,
53    AtmClip = 106,
54    Frelay = 107,
55    Loop = 108,
56    Enc = 109,
57    NetBSDHdlc = 112,
58    LinuxSll = 113,
59    Ltalk = 114,
60    Pflog = 117,
61    Ieee80211Prism = 119,
62    IpOverFc = 122,
63    Sunatm = 123,
64    Ieee80211Radiotap = 127,
65    Tzsp = 128,
66    ArcnetLinux = 129,
67    JuniperMlppp = 130,
68    JuniperMlfr = 131,
69    JuniperEs = 132,
70    JuniperGgsn = 133,
71    JuniperMfr = 134,
72    JuniperAtm2 = 135,
73    JuniperServices = 136,
74    JuniperAtm1 = 137,
75    AppleIpOverIeee1394 = 138,
76    Mtp2WithPhdr = 139,
77    Mtp2 = 140,
78    Mtp3 = 141,
79    Sccp = 142,
80    Docsis = 143,
81    LinuxIrda = 144,
82    IbmSp = 145,
83    IbmSn = 146,
84    Ieee80211Avs = 163,
85    JuniperMonitor = 164,
86    BacnetMsTp = 165,
87    PppPppd = 166,
88    JuniperPpoe = 167,
89    JuniperPpoeAtm = 168,
90    GprsLlc = 169,
91    GpfT = 170,
92    GpfF = 171,
93    GcomT1E1 = 172,
94    GcomSerial = 173,
95    JuniperPicPeer = 174,
96    ErfEth = 175,
97    ErfPos = 176,
98    LinuxLapd = 177,
99    JuniperEther = 178,
100    JuniperPpp = 179,
101    JuniperFrelay = 180,
102    JuniperChdlc = 181,
103    Mfr = 182,
104    JuniperVp = 183,
105    A429 = 184,
106    A653Icm = 185,
107    UsbFreebsd = 186,
108    BluetoothHciH4 = 187,
109    Ieee80216MacCps = 188,
110    UsbLinux = 189,
111    Can20B = 190,
112    Ieee802154Linux = 191,
113    Ppi = 192,
114    Ieee80216MacCpsRadio = 193,
115    JuniperIsm = 194,
116    Ieee802154WithFcs = 195,
117    Sita = 196,
118    Erf = 197,
119    Raif1 = 198,
120    IpmbKontron = 199,
121    JuniperSt = 200,
122    BluetoothHciH4WithPhdr = 201,
123    Ax25Kiss = 202,
124    Lapd = 203,
125    PppWithDir = 204,
126    CHdlcWithDir = 205,
127    FrelayWithDir = 206,
128    LapbWithDir = 207,
129    I2CLinux = 209,
130    Most = 211,
131    Lin = 212,
132    X2eSerial = 213,
133    X2eXoraya = 214,
134    Ieee802154NonaskPhy = 215,
135    LinuxEvdev = 216,
136    GsmtapUm = 217,
137    GsmtapAbis = 218,
138    Mpls = 219,
139    UsbLinuxMmapped = 220,
140    Dect = 221,
141    Aos = 222,
142    Wihart = 223,
143    Fc2 = 224,
144    Fc2WithFrameDelims = 225,
145    Ipnet = 226,
146    CanSocketcan = 227,
147    Ipv4 = 228,
148    Ipv6 = 229,
149    Ieee802154Nofcs = 230,
150    Dbus = 231,
151    JuniperVs = 232,
152    JuniperSrxE2e = 233,
153    JuniperFibreChannel = 234,
154    DvbCi = 235,
155    Mux27010 = 236,
156    Stanag5066DPdu = 237,
157    JuniperAtmCemic = 238,
158    Nflog = 239,
159    Netanalyzer = 240,
160    NetanalyzerTransparent = 241,
161    Ipoib = 242,
162    Mpeg2Ts = 243,
163    Ng40 = 244,
164    NfcLlcp = 245,
165    PfSync = 246,
166    Infiniband = 247,
167    Sctp = 248,
168    Usbpcap = 249,
169    RtacSerial = 250,
170    BluetoothLELL = 251,
171    WiresharkUpperPdu = 252,
172    Netlink = 253,
173    BluetoothLinuxMonitor = 254,
174    BluetoothBredrBb = 255,
175    BluetoothLELLWithPhdr = 256,
176    ProfibusDl = 257,
177    Pktap = 258,
178    Epon = 259,
179    IpmiHpm2 = 260,
180    ZwaveR1R2 = 261,
181    ZwaveR3 = 262,
182    WattstopperDlm = 263,
183    Iso14443 = 264,
184    Rds = 265,
185    UsbDarwin = 266,
186    Openflow = 267,
187    Sdlc = 268,
188    TILlnSniffer = 269,
189    Loratap = 270,
190    Vsock = 271,
191    NordicBLE = 272,
192    Docsis31Xra31 = 273,
193    EthernetMpacket = 274,
194    DisplayportAux = 275,
195    LinuxSll2 = 276,
196    SercosMonitor = 277,
197    OpenVizsla = 278,
198    Ebhscr = 279,
199    VppDispatch = 280,
200    DsaTagBrcm = 281,
201    DsaTagBrcmPrepend = 282,
202    IEEE802154Tap = 283,
203    DsaTagDsa = 284,
204    DsaTagEdsa = 285,
205    Elee = 286,
206    ZWaveSerial = 287,
207    Usb20 = 288,
208    AtscAlp = 289,
209    Etw = 290,
210    NetanalyzerNg = 291,
211    ZbossNcp = 292,
212    Usb20LowSpeed = 293,
213    Usb20FullSpeed = 294,
214    Usb20HighSpeed = 295,
215    AuerswaldLog = 296,
216    ZwaveTap = 297,
217    SiLabsDebugChannel = 298,
218    FiraUCI = 299,
219    Mdbus = 300,
220    DectNR = 301,
221    #[num_enum(default)]
222    Unknown = u32::MAX,
223}
224
225impl LinkType {
226    pub fn from_u32(number: u32) -> LinkType {
227        Self::from_primitive(number)
228    }
229}