1use std::convert::TryFrom;
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)]
8#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9pub enum InterfaceType {
10 Unknown,
12 Ethernet,
14 TokenRing,
16 Fddi,
18 BasicIsdn,
20 PrimaryIsdn,
22 Ppp,
24 Loopback,
26 Ethernet3Megabit,
28 Slip,
30 Atm,
32 GenericModem,
34 FastEthernetT,
36 Isdn,
38 FastEthernetFx,
40 Wireless80211,
42 AsymmetricDsl,
44 RateAdaptDsl,
46 SymmetricDsl,
48 VeryHighSpeedDsl,
50 IPOverAtm,
52 GigabitEthernet,
54 Tunnel,
56 MultiRateSymmetricDsl,
58 HighPerformanceSerialBus,
60 Wman,
62 Wwanpp,
64 Wwanpp2,
66}
67
68impl InterfaceType {
69 #[cfg(target_os = "windows")]
71 pub fn value(&self) -> u32 {
72 match *self {
73 InterfaceType::Unknown => 1,
74 InterfaceType::Ethernet => 6,
75 InterfaceType::TokenRing => 9,
76 InterfaceType::Fddi => 15,
77 InterfaceType::BasicIsdn => 20,
78 InterfaceType::PrimaryIsdn => 21,
79 InterfaceType::Ppp => 23,
80 InterfaceType::Loopback => 24,
81 InterfaceType::Ethernet3Megabit => 26,
82 InterfaceType::Slip => 28,
83 InterfaceType::Atm => 37,
84 InterfaceType::GenericModem => 48,
85 InterfaceType::FastEthernetT => 62,
86 InterfaceType::Isdn => 63,
87 InterfaceType::FastEthernetFx => 69,
88 InterfaceType::Wireless80211 => 71,
89 InterfaceType::AsymmetricDsl => 94,
90 InterfaceType::RateAdaptDsl => 95,
91 InterfaceType::SymmetricDsl => 96,
92 InterfaceType::VeryHighSpeedDsl => 97,
93 InterfaceType::IPOverAtm => 114,
94 InterfaceType::GigabitEthernet => 117,
95 InterfaceType::Tunnel => 131,
96 InterfaceType::MultiRateSymmetricDsl => 143,
97 InterfaceType::HighPerformanceSerialBus => 144,
98 InterfaceType::Wman => 237,
99 InterfaceType::Wwanpp => 243,
100 InterfaceType::Wwanpp2 => 244,
101 }
102 }
103 #[cfg(any(target_os = "linux", target_os = "android"))]
105 pub fn value(&self) -> u32 {
106 match *self {
107 InterfaceType::Ethernet => 1,
108 InterfaceType::TokenRing => 4,
109 InterfaceType::Fddi => 774,
110 InterfaceType::Ppp => 512,
111 InterfaceType::Loopback => 772,
112 InterfaceType::Ethernet3Megabit => 2,
113 InterfaceType::Slip => 256,
114 InterfaceType::Atm => 19,
115 InterfaceType::Wireless80211 => 801,
116 InterfaceType::Tunnel => 768,
117 _ => u32::MAX,
118 }
119 }
120 #[cfg(any(
122 target_os = "macos",
123 target_os = "openbsd",
124 target_os = "freebsd",
125 target_os = "netbsd",
126 target_os = "ios"
127 ))]
128 pub fn value(&self) -> u32 {
129 match *self {
131 _ => 0,
132 }
133 }
134 pub fn name(&self) -> String {
136 match *self {
137 InterfaceType::Unknown => String::from("Unknown"),
138 InterfaceType::Ethernet => String::from("Ethernet"),
139 InterfaceType::TokenRing => String::from("Token Ring"),
140 InterfaceType::Fddi => String::from("FDDI"),
141 InterfaceType::BasicIsdn => String::from("Basic ISDN"),
142 InterfaceType::PrimaryIsdn => String::from("Primary ISDN"),
143 InterfaceType::Ppp => String::from("PPP"),
144 InterfaceType::Loopback => String::from("Loopback"),
145 InterfaceType::Ethernet3Megabit => String::from("Ethernet 3 megabit"),
146 InterfaceType::Slip => String::from("SLIP"),
147 InterfaceType::Atm => String::from("ATM"),
148 InterfaceType::GenericModem => String::from("Generic Modem"),
149 InterfaceType::FastEthernetT => String::from("Fast Ethernet T"),
150 InterfaceType::Isdn => String::from("ISDN"),
151 InterfaceType::FastEthernetFx => String::from("Fast Ethernet FX"),
152 InterfaceType::Wireless80211 => String::from("Wireless IEEE 802.11"),
153 InterfaceType::AsymmetricDsl => String::from("Asymmetric DSL"),
154 InterfaceType::RateAdaptDsl => String::from("Rate Adaptive DSL"),
155 InterfaceType::SymmetricDsl => String::from("Symmetric DSL"),
156 InterfaceType::VeryHighSpeedDsl => String::from("Very High Data Rate DSL"),
157 InterfaceType::IPOverAtm => String::from("IP over ATM"),
158 InterfaceType::GigabitEthernet => String::from("Gigabit Ethernet"),
159 InterfaceType::Tunnel => String::from("Tunnel"),
160 InterfaceType::MultiRateSymmetricDsl => String::from("Multi-Rate Symmetric DSL"),
161 InterfaceType::HighPerformanceSerialBus => String::from("High Performance Serial Bus"),
162 InterfaceType::Wman => String::from("WMAN"),
163 InterfaceType::Wwanpp => String::from("WWANPP"),
164 InterfaceType::Wwanpp2 => String::from("WWANPP2"),
165 }
166 }
167}
168
169impl TryFrom<u32> for InterfaceType {
170 type Error = ();
171 fn try_from(v: u32) -> Result<Self, Self::Error> {
172 match v {
173 x if x == InterfaceType::Unknown.value() => Ok(InterfaceType::Unknown),
174 x if x == InterfaceType::Ethernet.value() => Ok(InterfaceType::Ethernet),
175 x if x == InterfaceType::TokenRing.value() => Ok(InterfaceType::TokenRing),
176 x if x == InterfaceType::Fddi.value() => Ok(InterfaceType::Fddi),
177 x if x == InterfaceType::BasicIsdn.value() => Ok(InterfaceType::BasicIsdn),
178 x if x == InterfaceType::PrimaryIsdn.value() => Ok(InterfaceType::PrimaryIsdn),
179 x if x == InterfaceType::Ppp.value() => Ok(InterfaceType::Ppp),
180 x if x == InterfaceType::Loopback.value() => Ok(InterfaceType::Loopback),
181 x if x == InterfaceType::Ethernet3Megabit.value() => {
182 Ok(InterfaceType::Ethernet3Megabit)
183 }
184 x if x == InterfaceType::Slip.value() => Ok(InterfaceType::Slip),
185 x if x == InterfaceType::Atm.value() => Ok(InterfaceType::Atm),
186 x if x == InterfaceType::GenericModem.value() => Ok(InterfaceType::GenericModem),
187 x if x == InterfaceType::FastEthernetT.value() => Ok(InterfaceType::FastEthernetT),
188 x if x == InterfaceType::Isdn.value() => Ok(InterfaceType::Isdn),
189 x if x == InterfaceType::FastEthernetFx.value() => Ok(InterfaceType::FastEthernetFx),
190 x if x == InterfaceType::Wireless80211.value() => Ok(InterfaceType::Wireless80211),
191 x if x == InterfaceType::AsymmetricDsl.value() => Ok(InterfaceType::AsymmetricDsl),
192 x if x == InterfaceType::RateAdaptDsl.value() => Ok(InterfaceType::RateAdaptDsl),
193 x if x == InterfaceType::SymmetricDsl.value() => Ok(InterfaceType::SymmetricDsl),
194 x if x == InterfaceType::VeryHighSpeedDsl.value() => {
195 Ok(InterfaceType::VeryHighSpeedDsl)
196 }
197 x if x == InterfaceType::IPOverAtm.value() => Ok(InterfaceType::IPOverAtm),
198 x if x == InterfaceType::GigabitEthernet.value() => Ok(InterfaceType::GigabitEthernet),
199 x if x == InterfaceType::Tunnel.value() => Ok(InterfaceType::Tunnel),
200 x if x == InterfaceType::MultiRateSymmetricDsl.value() => {
201 Ok(InterfaceType::MultiRateSymmetricDsl)
202 }
203 x if x == InterfaceType::HighPerformanceSerialBus.value() => {
204 Ok(InterfaceType::HighPerformanceSerialBus)
205 }
206 x if x == InterfaceType::Wman.value() => Ok(InterfaceType::Wman),
207 x if x == InterfaceType::Wwanpp.value() => Ok(InterfaceType::Wwanpp),
208 x if x == InterfaceType::Wwanpp2.value() => Ok(InterfaceType::Wwanpp2),
209 _ => Err(()),
210 }
211 }
212}