1 /// Represents an ARP protocol hardware identifier. 2 /// 3 /// You can access the underlying `u16` value by using `.0` and any `u16` 4 /// can be converted to an `ArpHardwareId`: 5 /// 6 /// ``` 7 /// use etherparse::ArpHardwareId; 8 /// 9 /// assert_eq!(ArpHardwareId::ETHERNET.0, 0x0001); 10 /// assert_eq!(ArpHardwareId::ETHERNET, ArpHardwareId(0x0001)); 11 /// 12 /// // convert to ArpHardwareId using the from & into trait 13 /// let arp_hrd_id: ArpHardwareId = 0x0001.into(); 14 /// assert_eq!(ArpHardwareId::ETHERNET, arp_hrd_id); 15 /// 16 /// // convert to u16 using the from & into trait 17 /// let num: u16 = ArpHardwareId::ETHERNET.into(); 18 /// assert_eq!(0x0001, num); 19 /// ``` 20 /// 21 #[derive(Clone, Copy, Eq, PartialEq, Default, Ord, PartialOrd, Hash)] 22 pub struct ArpHardwareId(pub u16); 23 24 impl ArpHardwareId { 25 // Numbers sourced from 26 // * https://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml 27 // * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/include/uapi/linux/if_arp.h?id=e33c4963bf536900f917fb65a687724d5539bc21 28 29 /// Reserved 30 pub const NETROM: ArpHardwareId = Self(0); 31 32 /// Ethernet (10Mb) 33 pub const ETHERNET: ArpHardwareId = Self(1); 34 35 /// Deprecated use [`ArpHardwareId::ETHERNET`] instead 36 #[deprecated(since = "0.17.0", note = "Use `ArpHardwareId::ETHERNET` instead")] 37 pub const ETHER: ArpHardwareId = Self(1); 38 39 /// Experimental Ethernet (3Mb) 40 pub const EETHER: ArpHardwareId = Self(2); 41 42 /// Amateur Radio AX.25 43 pub const AX25: ArpHardwareId = Self(3); 44 45 /// Proteon ProNET Token Ring 46 pub const PRONET: ArpHardwareId = Self(4); 47 48 /// Chaos 49 pub const CHAOS: ArpHardwareId = Self(5); 50 51 /// IEEE 802 Networks 52 pub const IEEE802: ArpHardwareId = Self(6); 53 54 /// ARCNET 55 pub const ARCNET: ArpHardwareId = Self(7); 56 57 /// Hyperchannel 58 pub const HYPERCHANNEL: ArpHardwareId = Self(8); 59 60 /// APPLEtalk 61 pub const APPLETLK: ArpHardwareId = Self(8); 62 63 /// Lanstar 64 pub const LANSTAR: ArpHardwareId = Self(9); 65 66 /// Autonet Short Address 67 pub const AUTONET_SHORT_ADDRESS: ArpHardwareId = Self(10); 68 69 /// LocalTalk 70 pub const LOCAL_TALK: ArpHardwareId = Self(11); 71 72 /// LocalNet (IBM PCNet or SYTEK LocalNET) 73 pub const LOCAL_NET: ArpHardwareId = Self(12); 74 75 /// Ultra link 76 pub const ULTRA_LINK: ArpHardwareId = Self(13); 77 78 /// SMDS 79 pub const SMDS: ArpHardwareId = Self(14); 80 81 /// DLCI (alias for [`ArpHardwareId::FRAME_RELAY`]) 82 pub const DLCI: ArpHardwareId = Self(15); 83 84 /// Frame Relay (alias for [`ArpHardwareId::DLCI`]) 85 pub const FRAME_RELAY: ArpHardwareId = Self(15); 86 87 /// Asynchronous Transmission Mode (ATM) \[JXB2\] 88 pub const ATM_JXB2: ArpHardwareId = Self(16); 89 90 /// HDLC 91 pub const HDLC: ArpHardwareId = Self(17); 92 93 /// Fibre Channel 94 pub const FIBRE_CHANNEL: ArpHardwareId = Self(18); 95 96 /// Asynchronous Transmission Mode (ATM) \[RFC2225\] 97 pub const ATM: ArpHardwareId = Self(19); 98 99 /// Serial Line 100 pub const SERIAL_LINE: ArpHardwareId = Self(20); 101 102 /// Asynchronous Transmission Mode (ATM) \[Mike_Burrows\] 103 pub const ATM_21: ArpHardwareId = Self(21); 104 105 /// MIL-STD-188-220 106 pub const MIL_STD_188_220: ArpHardwareId = Self(22); 107 108 /// Metricom 109 pub const METRICOM: ArpHardwareId = Self(23); 110 111 /// IEEE 1394.1995 112 pub const IEEE1394: ArpHardwareId = Self(24); 113 114 /// MAPOS 115 pub const MAPOS: ArpHardwareId = Self(25); 116 117 /// Twinaxial 118 pub const TWINAXIAL: ArpHardwareId = Self(26); 119 120 /// EUI-64 121 pub const EUI64: ArpHardwareId = Self(27); 122 123 /// HIPARP 124 pub const HIPARP: ArpHardwareId = Self(28); 125 126 /// IP and ARP over ISO 7816-3 127 pub const IP_AND_ARP_OVER_ISO_7816_3: ArpHardwareId = Self(29); 128 129 /// ARPSec 130 pub const ARPSEC: ArpHardwareId = Self(30); 131 132 /// IPsec tunnel 133 pub const IPSEC_TUNNEL: ArpHardwareId = Self(31); 134 135 /// InfiniBand 136 pub const INFINIBAND: ArpHardwareId = Self(32); 137 138 /// TIA-102 Project 25 Common Air Interface (CAI) 139 pub const CAI: ArpHardwareId = Self(33); 140 141 /// Wiegand Interface 142 pub const WIEGAND_INTERFACE: ArpHardwareId = Self(34); 143 144 /// Pure IP 145 pub const PURE_IP: ArpHardwareId = Self(35); 146 147 /// HW_EXP1 148 pub const HW_EXP1: ArpHardwareId = Self(36); 149 150 /// HFI 151 pub const HFI: ArpHardwareId = Self(37); 152 153 /// Unified Bus (UB) 154 pub const UNIFIED_BUS: ArpHardwareId = Self(38); 155 156 pub const SLIP: ArpHardwareId = Self(256); 157 pub const CSLIP: ArpHardwareId = Self(257); 158 pub const SLIP6: ArpHardwareId = Self(258); 159 pub const CSLIP6: ArpHardwareId = Self(259); 160 pub const RSRVD: ArpHardwareId = Self(260); 161 pub const ADAPT: ArpHardwareId = Self(264); 162 pub const ROSE: ArpHardwareId = Self(270); 163 pub const X25: ArpHardwareId = Self(271); 164 pub const HWX25: ArpHardwareId = Self(272); 165 pub const CAN: ArpHardwareId = Self(280); 166 pub const PPP: ArpHardwareId = Self(512); 167 pub const CISCO_HDLC: ArpHardwareId = Self(513); 168 pub const LAPB: ArpHardwareId = Self(516); 169 pub const DDCMP: ArpHardwareId = Self(517); 170 pub const RAWHDLC: ArpHardwareId = Self(518); 171 pub const RAWIP: ArpHardwareId = Self(519); 172 pub const TUNNEL: ArpHardwareId = Self(768); 173 pub const TUNNEL6: ArpHardwareId = Self(769); 174 pub const FRAD: ArpHardwareId = Self(770); 175 pub const SKIP: ArpHardwareId = Self(771); 176 pub const LOOPBACK: ArpHardwareId = Self(772); 177 pub const LOCALTLK: ArpHardwareId = Self(773); 178 pub const FDDI: ArpHardwareId = Self(774); 179 pub const BIF: ArpHardwareId = Self(775); 180 pub const SIT: ArpHardwareId = Self(776); 181 pub const IPDDP: ArpHardwareId = Self(777); 182 pub const IPGRE: ArpHardwareId = Self(778); 183 pub const PIMREG: ArpHardwareId = Self(779); 184 pub const HIPPI: ArpHardwareId = Self(780); 185 pub const ASH: ArpHardwareId = Self(781); 186 pub const ECONET: ArpHardwareId = Self(782); 187 pub const IRDA: ArpHardwareId = Self(783); 188 pub const FCPP: ArpHardwareId = Self(784); 189 pub const FCAL: ArpHardwareId = Self(785); 190 pub const FCPL: ArpHardwareId = Self(786); 191 pub const FCFABRIC: ArpHardwareId = Self(787); 192 pub const IEEE802_TR: ArpHardwareId = Self(800); 193 pub const IEEE80211: ArpHardwareId = Self(801); 194 pub const IEEE80211_PRISM: ArpHardwareId = Self(802); 195 pub const IEEE80211_RADIOTAP: ArpHardwareId = Self(803); 196 pub const IEEE802154: ArpHardwareId = Self(804); 197 pub const IEEE802154_MONITOR: ArpHardwareId = Self(805); 198 pub const PHONET: ArpHardwareId = Self(820); 199 pub const PHONET_PIPE: ArpHardwareId = Self(821); 200 pub const CAIF: ArpHardwareId = Self(822); 201 pub const IP6GRE: ArpHardwareId = Self(823); 202 pub const NETLINK: ArpHardwareId = Self(824); 203 pub const IPV6LOWPAN: ArpHardwareId = Self(825); 204 pub const VSOCKMON: ArpHardwareId = Self(826); 205 pub const VOID: ArpHardwareId = Self(0xFFFF); 206 pub const NONE: ArpHardwareId = Self(0xFFFE); 207 } 208 209 impl From<u16> for ArpHardwareId { 210 #[inline] from(val: u16) -> Self211 fn from(val: u16) -> Self { 212 ArpHardwareId(val) 213 } 214 } 215 216 impl From<ArpHardwareId> for u16 { 217 #[inline] from(val: ArpHardwareId) -> Self218 fn from(val: ArpHardwareId) -> Self { 219 val.0 220 } 221 } 222 223 impl core::fmt::Debug for ArpHardwareId { fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result224 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 225 match *self { 226 Self::NETROM => write!(f, "{} (from KA9Q: NET/ROM pseudo)", self.0), 227 Self::ETHERNET => write!(f, "{} (Ethernet)", self.0), 228 Self::EETHER => write!(f, "{} (Experimental Ethernet)", self.0), 229 Self::AX25 => write!(f, "{} (AX.25 Level 2)", self.0), 230 Self::PRONET => write!(f, "{} (PROnet token ring)", self.0), 231 Self::CHAOS => write!(f, "{} (Chaosnet)", self.0), 232 Self::IEEE802 => write!(f, "{} (IEEE 802.2 Ethernet/TR/TB)", self.0), 233 Self::ARCNET => write!(f, "{} (ARCnet)", self.0), 234 Self::APPLETLK => write!(f, "{} (APPLEtalk or Hyperchannel)", self.0), 235 Self::LANSTAR => write!(f, "{} (Lanstar)", self.0), 236 Self::AUTONET_SHORT_ADDRESS => write!(f, "{} (Autonet Short Address)", self.0), 237 Self::LOCAL_TALK => write!(f, "{} (LocalTalk)", self.0), 238 Self::LOCAL_NET => write!(f, "{} (LocalNet)", self.0), 239 Self::ULTRA_LINK => write!(f, "{} (Ultra link)", self.0), 240 Self::SMDS => write!(f, "{} (SMDS)", self.0), 241 Self::DLCI => write!(f, "{} (Frame Relay DLCI)", self.0), 242 Self::ATM_JXB2 => write!(f, "{} (Asynchronous Transmission Mode (ATM) JXB2)", self.0), 243 Self::HDLC => write!(f, "{} (HDLC)", self.0), 244 Self::FIBRE_CHANNEL => write!(f, "{} (Fibre Channel)", self.0), 245 Self::ATM => write!(f, "{} (ATM)", self.0), 246 Self::SERIAL_LINE => write!(f, "{} (Serial Line)", self.0), 247 Self::ATM_21 => write!(f, "{} (Asynchronous Transmission Mode (ATM))", self.0), 248 Self::MIL_STD_188_220 => write!(f, "{} (MIL-STD-188-220)", self.0), 249 Self::METRICOM => write!(f, "{} (Metricom STRIP (new IANA id))", self.0), 250 Self::IEEE1394 => write!(f, "{} (IEEE 1394 IPv4 - RFC 2734)", self.0), 251 Self::MAPOS => write!(f, "{} (MAPOS)", self.0), 252 Self::TWINAXIAL => write!(f, "{} (Twinaxial)", self.0), 253 Self::EUI64 => write!(f, "{} (EUI-64)", self.0), 254 Self::HIPARP => write!(f, "{} (HIPARP)", self.0), 255 Self::IP_AND_ARP_OVER_ISO_7816_3 => { 256 write!(f, "{} (IP and ARP over ISO 7816-3)", self.0) 257 } 258 Self::ARPSEC => write!(f, "{} (ARPSec)", self.0), 259 Self::IPSEC_TUNNEL => write!(f, "{} (IPsec tunnel)", self.0), 260 Self::INFINIBAND => write!(f, "{} (InfiniBand)", self.0), 261 Self::CAI => write!( 262 f, 263 "{} (TIA-102 Project 25 Common Air Interface (CAI))", 264 self.0 265 ), 266 Self::WIEGAND_INTERFACE => write!(f, "{} (Wiegand Interface)", self.0), 267 Self::PURE_IP => write!(f, "{} (Pure IP)", self.0), 268 Self::HW_EXP1 => write!(f, "{} (HW_EXP1)", self.0), 269 Self::HFI => write!(f, "{} (HFI)", self.0), 270 Self::UNIFIED_BUS => write!(f, "{} (Unified Bus (UB))", self.0), 271 Self::SLIP => write!(f, "{} (SLIP)", self.0), 272 Self::CSLIP => write!(f, "{} (CSLIP)", self.0), 273 Self::SLIP6 => write!(f, "{} (SLIP6)", self.0), 274 Self::CSLIP6 => write!(f, "{} (CSLIP6)", self.0), 275 Self::RSRVD => write!(f, "{} (Notional KISS type)", self.0), 276 Self::ADAPT => write!(f, "{} (ADAPT)", self.0), 277 Self::ROSE => write!(f, "{} (ROSE)", self.0), 278 Self::X25 => write!(f, "{} (CCITT X.25)", self.0), 279 Self::HWX25 => write!(f, "{} (Boards with X.25 in firmware)", self.0), 280 Self::CAN => write!(f, "{} (Controller Area Network)", self.0), 281 Self::PPP => write!(f, "{} (PPP)", self.0), 282 Self::CISCO_HDLC => write!(f, "{} (Cisco HDLC)", self.0), 283 Self::LAPB => write!(f, "{} (LAPB)", self.0), 284 Self::DDCMP => write!(f, "{} (Digital's DDCMP protocol)", self.0), 285 Self::RAWHDLC => write!(f, "{} (Raw HDLC)", self.0), 286 Self::RAWIP => write!(f, "{} (Raw IP)", self.0), 287 Self::TUNNEL => write!(f, "{} (IPIP tunnel)", self.0), 288 Self::TUNNEL6 => write!(f, "{} (IP6IP6 tunnel)", self.0), 289 Self::FRAD => write!(f, "{} (Frame Relay Access Device)", self.0), 290 Self::SKIP => write!(f, "{} (SKIP vif)", self.0), 291 Self::LOOPBACK => write!(f, "{} (Loopback device)", self.0), 292 Self::LOCALTLK => write!(f, "{} (Localtalk device)", self.0), 293 Self::FDDI => write!(f, "{} (Fiber Distributed Data Interface)", self.0), 294 Self::BIF => write!(f, "{} (AP1000 BIF)", self.0), 295 Self::SIT => write!(f, "{} (sit0 device - IPv6-in-IPv4)", self.0), 296 Self::IPDDP => write!(f, "{} (IP over DDP tunneller)", self.0), 297 Self::IPGRE => write!(f, "{} (GRE over IP)", self.0), 298 Self::PIMREG => write!(f, "{} (PIMSM register interface)", self.0), 299 Self::HIPPI => write!(f, "{} (High Performance Parallel Interface)", self.0), 300 Self::ASH => write!(f, "{} (Nexus 64Mbps Ash)", self.0), 301 Self::ECONET => write!(f, "{} (Acorn Econet)", self.0), 302 Self::IRDA => write!(f, "{} (Linux-IrDA)", self.0), 303 Self::FCPP => write!(f, "{} (Point to point fibrechannel)", self.0), 304 Self::FCAL => write!(f, "{} (Fibrechannel arbitrated loop)", self.0), 305 Self::FCPL => write!(f, "{} (Fibrechannel public loop)", self.0), 306 Self::FCFABRIC => write!(f, "{} (Fibrechannel fabric)", self.0), 307 Self::IEEE802_TR => write!(f, "{} (Magic type ident for TR)", self.0), 308 Self::IEEE80211 => write!(f, "{} (IEEE 802.11)", self.0), 309 Self::IEEE80211_PRISM => write!(f, "{} (IEEE 802.11 + Prism2 header)", self.0), 310 Self::IEEE80211_RADIOTAP => write!(f, "{} (IEEE 802.11 + radiotap header)", self.0), 311 Self::IEEE802154 => write!(f, "{} (IEEE 802.15.4)", self.0), 312 Self::IEEE802154_MONITOR => write!(f, "{} (IEEE 802.15.4 network monitor)", self.0), 313 Self::PHONET => write!(f, "{} (PhoNet media type)", self.0), 314 Self::PHONET_PIPE => write!(f, "{} (PhoNet pipe header)", self.0), 315 Self::CAIF => write!(f, "{} (CAIF media type)", self.0), 316 Self::IP6GRE => write!(f, "{} (GRE over IPv6)", self.0), 317 Self::NETLINK => write!(f, "{} (Netlink header)", self.0), 318 Self::IPV6LOWPAN => write!(f, "{} (IPv6 over LoWPAN)", self.0), 319 Self::VSOCKMON => write!(f, "{} (Vsock monitor header)", self.0), 320 Self::VOID => write!(f, "{:#06X} (Void type, nothing is known)", self.0), 321 Self::NONE => write!(f, "{:#06X} (zero header length)", self.0), 322 _ => write!(f, "{:#06X}", self.0), 323 } 324 } 325 } 326 327 #[cfg(test)] 328 mod test { 329 use super::*; 330 use alloc::format; 331 332 #[test] to_u16()333 fn to_u16() { 334 assert_eq!(0, u16::from(ArpHardwareId::NETROM)); 335 assert_eq!(1, u16::from(ArpHardwareId::ETHERNET)); 336 assert_eq!(2, u16::from(ArpHardwareId::EETHER)); 337 assert_eq!(3, u16::from(ArpHardwareId::AX25)); 338 assert_eq!(4, u16::from(ArpHardwareId::PRONET)); 339 assert_eq!(5, u16::from(ArpHardwareId::CHAOS)); 340 assert_eq!(6, u16::from(ArpHardwareId::IEEE802)); 341 assert_eq!(7, u16::from(ArpHardwareId::ARCNET)); 342 assert_eq!(8, u16::from(ArpHardwareId::APPLETLK)); 343 assert_eq!(15, u16::from(ArpHardwareId::DLCI)); 344 assert_eq!(19, u16::from(ArpHardwareId::ATM)); 345 assert_eq!(23, u16::from(ArpHardwareId::METRICOM)); 346 assert_eq!(24, u16::from(ArpHardwareId::IEEE1394)); 347 assert_eq!(27, u16::from(ArpHardwareId::EUI64)); 348 assert_eq!(32, u16::from(ArpHardwareId::INFINIBAND)); 349 350 assert_eq!(256, u16::from(ArpHardwareId::SLIP)); 351 assert_eq!(257, u16::from(ArpHardwareId::CSLIP)); 352 assert_eq!(258, u16::from(ArpHardwareId::SLIP6)); 353 assert_eq!(259, u16::from(ArpHardwareId::CSLIP6)); 354 assert_eq!(260, u16::from(ArpHardwareId::RSRVD)); 355 assert_eq!(264, u16::from(ArpHardwareId::ADAPT)); 356 assert_eq!(270, u16::from(ArpHardwareId::ROSE)); 357 assert_eq!(271, u16::from(ArpHardwareId::X25)); 358 assert_eq!(272, u16::from(ArpHardwareId::HWX25)); 359 assert_eq!(280, u16::from(ArpHardwareId::CAN)); 360 assert_eq!(512, u16::from(ArpHardwareId::PPP)); 361 assert_eq!(513, u16::from(ArpHardwareId::CISCO_HDLC)); 362 assert_eq!(516, u16::from(ArpHardwareId::LAPB)); 363 assert_eq!(517, u16::from(ArpHardwareId::DDCMP)); 364 assert_eq!(518, u16::from(ArpHardwareId::RAWHDLC)); 365 assert_eq!(519, u16::from(ArpHardwareId::RAWIP)); 366 367 assert_eq!(768, u16::from(ArpHardwareId::TUNNEL)); 368 assert_eq!(769, u16::from(ArpHardwareId::TUNNEL6)); 369 assert_eq!(770, u16::from(ArpHardwareId::FRAD)); 370 assert_eq!(771, u16::from(ArpHardwareId::SKIP)); 371 assert_eq!(772, u16::from(ArpHardwareId::LOOPBACK)); 372 assert_eq!(773, u16::from(ArpHardwareId::LOCALTLK)); 373 assert_eq!(774, u16::from(ArpHardwareId::FDDI)); 374 assert_eq!(775, u16::from(ArpHardwareId::BIF)); 375 assert_eq!(776, u16::from(ArpHardwareId::SIT)); 376 assert_eq!(777, u16::from(ArpHardwareId::IPDDP)); 377 assert_eq!(778, u16::from(ArpHardwareId::IPGRE)); 378 assert_eq!(779, u16::from(ArpHardwareId::PIMREG)); 379 assert_eq!(780, u16::from(ArpHardwareId::HIPPI)); 380 assert_eq!(781, u16::from(ArpHardwareId::ASH)); 381 assert_eq!(782, u16::from(ArpHardwareId::ECONET)); 382 assert_eq!(783, u16::from(ArpHardwareId::IRDA)); 383 384 assert_eq!(784, u16::from(ArpHardwareId::FCPP)); 385 assert_eq!(785, u16::from(ArpHardwareId::FCAL)); 386 assert_eq!(786, u16::from(ArpHardwareId::FCPL)); 387 assert_eq!(787, u16::from(ArpHardwareId::FCFABRIC)); 388 389 assert_eq!(800, u16::from(ArpHardwareId::IEEE802_TR)); 390 assert_eq!(801, u16::from(ArpHardwareId::IEEE80211)); 391 assert_eq!(802, u16::from(ArpHardwareId::IEEE80211_PRISM)); 392 assert_eq!(803, u16::from(ArpHardwareId::IEEE80211_RADIOTAP)); 393 assert_eq!(804, u16::from(ArpHardwareId::IEEE802154)); 394 assert_eq!(805, u16::from(ArpHardwareId::IEEE802154_MONITOR)); 395 396 assert_eq!(820, u16::from(ArpHardwareId::PHONET)); 397 assert_eq!(821, u16::from(ArpHardwareId::PHONET_PIPE)); 398 assert_eq!(822, u16::from(ArpHardwareId::CAIF)); 399 assert_eq!(823, u16::from(ArpHardwareId::IP6GRE)); 400 assert_eq!(824, u16::from(ArpHardwareId::NETLINK)); 401 assert_eq!(825, u16::from(ArpHardwareId::IPV6LOWPAN)); 402 assert_eq!(826, u16::from(ArpHardwareId::VSOCKMON)); 403 404 assert_eq!(0xFFFF, u16::from(ArpHardwareId::VOID)); 405 assert_eq!(0xFFFE, u16::from(ArpHardwareId::NONE)); 406 } 407 408 #[test] from_u16()409 fn from_u16() { 410 assert_eq!(ArpHardwareId::from(0), ArpHardwareId::NETROM); 411 assert_eq!(ArpHardwareId::from(1), ArpHardwareId::ETHERNET); 412 assert_eq!(ArpHardwareId::from(2), ArpHardwareId::EETHER); 413 assert_eq!(ArpHardwareId::from(3), ArpHardwareId::AX25); 414 assert_eq!(ArpHardwareId::from(4), ArpHardwareId::PRONET); 415 assert_eq!(ArpHardwareId::from(5), ArpHardwareId::CHAOS); 416 assert_eq!(ArpHardwareId::from(6), ArpHardwareId::IEEE802); 417 assert_eq!(ArpHardwareId::from(7), ArpHardwareId::ARCNET); 418 assert_eq!(ArpHardwareId::from(8), ArpHardwareId::APPLETLK); 419 assert_eq!(ArpHardwareId::from(15), ArpHardwareId::DLCI); 420 assert_eq!(ArpHardwareId::from(19), ArpHardwareId::ATM); 421 assert_eq!(ArpHardwareId::from(23), ArpHardwareId::METRICOM); 422 assert_eq!(ArpHardwareId::from(24), ArpHardwareId::IEEE1394); 423 assert_eq!(ArpHardwareId::from(27), ArpHardwareId::EUI64); 424 assert_eq!(ArpHardwareId::from(32), ArpHardwareId::INFINIBAND); 425 426 assert_eq!(ArpHardwareId::from(256), ArpHardwareId::SLIP); 427 assert_eq!(ArpHardwareId::from(257), ArpHardwareId::CSLIP); 428 assert_eq!(ArpHardwareId::from(258), ArpHardwareId::SLIP6); 429 assert_eq!(ArpHardwareId::from(259), ArpHardwareId::CSLIP6); 430 assert_eq!(ArpHardwareId::from(260), ArpHardwareId::RSRVD); 431 assert_eq!(ArpHardwareId::from(264), ArpHardwareId::ADAPT); 432 assert_eq!(ArpHardwareId::from(270), ArpHardwareId::ROSE); 433 assert_eq!(ArpHardwareId::from(271), ArpHardwareId::X25); 434 assert_eq!(ArpHardwareId::from(272), ArpHardwareId::HWX25); 435 assert_eq!(ArpHardwareId::from(280), ArpHardwareId::CAN); 436 assert_eq!(ArpHardwareId::from(512), ArpHardwareId::PPP); 437 assert_eq!(ArpHardwareId::from(513), ArpHardwareId::CISCO_HDLC); 438 assert_eq!(ArpHardwareId::from(516), ArpHardwareId::LAPB); 439 assert_eq!(ArpHardwareId::from(517), ArpHardwareId::DDCMP); 440 assert_eq!(ArpHardwareId::from(518), ArpHardwareId::RAWHDLC); 441 assert_eq!(ArpHardwareId::from(519), ArpHardwareId::RAWIP); 442 443 assert_eq!(ArpHardwareId::from(768), ArpHardwareId::TUNNEL); 444 assert_eq!(ArpHardwareId::from(769), ArpHardwareId::TUNNEL6); 445 assert_eq!(ArpHardwareId::from(770), ArpHardwareId::FRAD); 446 assert_eq!(ArpHardwareId::from(771), ArpHardwareId::SKIP); 447 assert_eq!(ArpHardwareId::from(772), ArpHardwareId::LOOPBACK); 448 assert_eq!(ArpHardwareId::from(773), ArpHardwareId::LOCALTLK); 449 assert_eq!(ArpHardwareId::from(774), ArpHardwareId::FDDI); 450 assert_eq!(ArpHardwareId::from(775), ArpHardwareId::BIF); 451 assert_eq!(ArpHardwareId::from(776), ArpHardwareId::SIT); 452 assert_eq!(ArpHardwareId::from(777), ArpHardwareId::IPDDP); 453 assert_eq!(ArpHardwareId::from(778), ArpHardwareId::IPGRE); 454 assert_eq!(ArpHardwareId::from(779), ArpHardwareId::PIMREG); 455 assert_eq!(ArpHardwareId::from(780), ArpHardwareId::HIPPI); 456 assert_eq!(ArpHardwareId::from(781), ArpHardwareId::ASH); 457 assert_eq!(ArpHardwareId::from(782), ArpHardwareId::ECONET); 458 assert_eq!(ArpHardwareId::from(783), ArpHardwareId::IRDA); 459 460 assert_eq!(ArpHardwareId::from(784), ArpHardwareId::FCPP); 461 assert_eq!(ArpHardwareId::from(785), ArpHardwareId::FCAL); 462 assert_eq!(ArpHardwareId::from(786), ArpHardwareId::FCPL); 463 assert_eq!(ArpHardwareId::from(787), ArpHardwareId::FCFABRIC); 464 465 assert_eq!(ArpHardwareId::from(800), ArpHardwareId::IEEE802_TR); 466 assert_eq!(ArpHardwareId::from(801), ArpHardwareId::IEEE80211); 467 assert_eq!(ArpHardwareId::from(802), ArpHardwareId::IEEE80211_PRISM); 468 assert_eq!(ArpHardwareId::from(803), ArpHardwareId::IEEE80211_RADIOTAP); 469 assert_eq!(ArpHardwareId::from(804), ArpHardwareId::IEEE802154); 470 assert_eq!(ArpHardwareId::from(805), ArpHardwareId::IEEE802154_MONITOR); 471 472 assert_eq!(ArpHardwareId::from(820), ArpHardwareId::PHONET); 473 assert_eq!(ArpHardwareId::from(821), ArpHardwareId::PHONET_PIPE); 474 assert_eq!(ArpHardwareId::from(822), ArpHardwareId::CAIF); 475 assert_eq!(ArpHardwareId::from(823), ArpHardwareId::IP6GRE); 476 assert_eq!(ArpHardwareId::from(824), ArpHardwareId::NETLINK); 477 assert_eq!(ArpHardwareId::from(825), ArpHardwareId::IPV6LOWPAN); 478 assert_eq!(ArpHardwareId::from(826), ArpHardwareId::VSOCKMON); 479 480 assert_eq!(ArpHardwareId::from(0xFFFF), ArpHardwareId::VOID); 481 assert_eq!(ArpHardwareId::from(0xFFFE), ArpHardwareId::NONE); 482 } 483 484 #[test] display_dbg()485 fn display_dbg() { 486 let pairs = &[ 487 (ArpHardwareId::NETROM, "0 (from KA9Q: NET/ROM pseudo)"), 488 (ArpHardwareId::ETHERNET, "1 (Ethernet)"), 489 (ArpHardwareId::EETHER, "2 (Experimental Ethernet)"), 490 (ArpHardwareId::AX25, "3 (AX.25 Level 2)"), 491 (ArpHardwareId::PRONET, "4 (PROnet token ring)"), 492 (ArpHardwareId::CHAOS, "5 (Chaosnet)"), 493 (ArpHardwareId::IEEE802, "6 (IEEE 802.2 Ethernet/TR/TB)"), 494 (ArpHardwareId::ARCNET, "7 (ARCnet)"), 495 (ArpHardwareId::APPLETLK, "8 (APPLEtalk or Hyperchannel)"), 496 (ArpHardwareId::LANSTAR, "9 (Lanstar)"), 497 ( 498 ArpHardwareId::AUTONET_SHORT_ADDRESS, 499 "10 (Autonet Short Address)", 500 ), 501 (ArpHardwareId::LOCAL_TALK, "11 (LocalTalk)"), 502 (ArpHardwareId::LOCAL_NET, "12 (LocalNet)"), 503 (ArpHardwareId::ULTRA_LINK, "13 (Ultra link)"), 504 (ArpHardwareId::SMDS, "14 (SMDS)"), 505 (ArpHardwareId::DLCI, "15 (Frame Relay DLCI)"), 506 ( 507 ArpHardwareId::ATM_JXB2, 508 "16 (Asynchronous Transmission Mode (ATM) JXB2)", 509 ), 510 (ArpHardwareId::HDLC, "17 (HDLC)"), 511 (ArpHardwareId::FIBRE_CHANNEL, "18 (Fibre Channel)"), 512 (ArpHardwareId::ATM, "19 (ATM)"), 513 (ArpHardwareId::SERIAL_LINE, "20 (Serial Line)"), 514 ( 515 ArpHardwareId::ATM_21, 516 "21 (Asynchronous Transmission Mode (ATM))", 517 ), 518 (ArpHardwareId::MIL_STD_188_220, "22 (MIL-STD-188-220)"), 519 (ArpHardwareId::METRICOM, "23 (Metricom STRIP (new IANA id))"), 520 (ArpHardwareId::IEEE1394, "24 (IEEE 1394 IPv4 - RFC 2734)"), 521 (ArpHardwareId::MAPOS, "25 (MAPOS)"), 522 (ArpHardwareId::TWINAXIAL, "26 (Twinaxial)"), 523 (ArpHardwareId::EUI64, "27 (EUI-64)"), 524 (ArpHardwareId::HIPARP, "28 (HIPARP)"), 525 ( 526 ArpHardwareId::IP_AND_ARP_OVER_ISO_7816_3, 527 "29 (IP and ARP over ISO 7816-3)", 528 ), 529 (ArpHardwareId::ARPSEC, "30 (ARPSec)"), 530 (ArpHardwareId::IPSEC_TUNNEL, "31 (IPsec tunnel)"), 531 (ArpHardwareId::INFINIBAND, "32 (InfiniBand)"), 532 ( 533 ArpHardwareId::CAI, 534 "33 (TIA-102 Project 25 Common Air Interface (CAI))", 535 ), 536 (ArpHardwareId::WIEGAND_INTERFACE, "34 (Wiegand Interface)"), 537 (ArpHardwareId::PURE_IP, "35 (Pure IP)"), 538 (ArpHardwareId::HW_EXP1, "36 (HW_EXP1)"), 539 (ArpHardwareId::HFI, "37 (HFI)"), 540 (ArpHardwareId::UNIFIED_BUS, "38 (Unified Bus (UB))"), 541 (ArpHardwareId::SLIP, "256 (SLIP)"), 542 (ArpHardwareId::CSLIP, "257 (CSLIP)"), 543 (ArpHardwareId::SLIP6, "258 (SLIP6)"), 544 (ArpHardwareId::CSLIP6, "259 (CSLIP6)"), 545 (ArpHardwareId::RSRVD, "260 (Notional KISS type)"), 546 (ArpHardwareId::ADAPT, "264 (ADAPT)"), 547 (ArpHardwareId::ROSE, "270 (ROSE)"), 548 (ArpHardwareId::X25, "271 (CCITT X.25)"), 549 (ArpHardwareId::HWX25, "272 (Boards with X.25 in firmware)"), 550 (ArpHardwareId::CAN, "280 (Controller Area Network)"), 551 (ArpHardwareId::PPP, "512 (PPP)"), 552 (ArpHardwareId::CISCO_HDLC, "513 (Cisco HDLC)"), 553 (ArpHardwareId::LAPB, "516 (LAPB)"), 554 (ArpHardwareId::DDCMP, "517 (Digital's DDCMP protocol)"), 555 (ArpHardwareId::RAWHDLC, "518 (Raw HDLC)"), 556 (ArpHardwareId::RAWIP, "519 (Raw IP)"), 557 (ArpHardwareId::TUNNEL, "768 (IPIP tunnel)"), 558 (ArpHardwareId::TUNNEL6, "769 (IP6IP6 tunnel)"), 559 (ArpHardwareId::FRAD, "770 (Frame Relay Access Device)"), 560 (ArpHardwareId::SKIP, "771 (SKIP vif)"), 561 (ArpHardwareId::LOOPBACK, "772 (Loopback device)"), 562 (ArpHardwareId::LOCALTLK, "773 (Localtalk device)"), 563 ( 564 ArpHardwareId::FDDI, 565 "774 (Fiber Distributed Data Interface)", 566 ), 567 (ArpHardwareId::BIF, "775 (AP1000 BIF)"), 568 (ArpHardwareId::SIT, "776 (sit0 device - IPv6-in-IPv4)"), 569 (ArpHardwareId::IPDDP, "777 (IP over DDP tunneller)"), 570 (ArpHardwareId::IPGRE, "778 (GRE over IP)"), 571 (ArpHardwareId::PIMREG, "779 (PIMSM register interface)"), 572 ( 573 ArpHardwareId::HIPPI, 574 "780 (High Performance Parallel Interface)", 575 ), 576 (ArpHardwareId::ASH, "781 (Nexus 64Mbps Ash)"), 577 (ArpHardwareId::ECONET, "782 (Acorn Econet)"), 578 (ArpHardwareId::IRDA, "783 (Linux-IrDA)"), 579 (ArpHardwareId::FCPP, "784 (Point to point fibrechannel)"), 580 (ArpHardwareId::FCAL, "785 (Fibrechannel arbitrated loop)"), 581 (ArpHardwareId::FCPL, "786 (Fibrechannel public loop)"), 582 (ArpHardwareId::FCFABRIC, "787 (Fibrechannel fabric)"), 583 (ArpHardwareId::IEEE802_TR, "800 (Magic type ident for TR)"), 584 (ArpHardwareId::IEEE80211, "801 (IEEE 802.11)"), 585 ( 586 ArpHardwareId::IEEE80211_PRISM, 587 "802 (IEEE 802.11 + Prism2 header)", 588 ), 589 ( 590 ArpHardwareId::IEEE80211_RADIOTAP, 591 "803 (IEEE 802.11 + radiotap header)", 592 ), 593 (ArpHardwareId::IEEE802154, "804 (IEEE 802.15.4)"), 594 ( 595 ArpHardwareId::IEEE802154_MONITOR, 596 "805 (IEEE 802.15.4 network monitor)", 597 ), 598 (ArpHardwareId::PHONET, "820 (PhoNet media type)"), 599 (ArpHardwareId::PHONET_PIPE, "821 (PhoNet pipe header)"), 600 (ArpHardwareId::CAIF, "822 (CAIF media type)"), 601 (ArpHardwareId::IP6GRE, "823 (GRE over IPv6)"), 602 (ArpHardwareId::NETLINK, "824 (Netlink header)"), 603 (ArpHardwareId::IPV6LOWPAN, "825 (IPv6 over LoWPAN)"), 604 (ArpHardwareId::VSOCKMON, "826 (Vsock monitor header)"), 605 (ArpHardwareId::VOID, "0xFFFF (Void type, nothing is known)"), 606 (ArpHardwareId::NONE, "0xFFFE (zero header length)"), 607 (ArpHardwareId::from(0x1234), "0x1234"), 608 ]; 609 610 for (arp_hw_id, str_value) in pairs { 611 assert_eq!(str_value, &format!("{:?}", arp_hw_id)); 612 } 613 } 614 615 #[test] default()616 fn default() { 617 let value: ArpHardwareId = Default::default(); 618 assert_eq!(ArpHardwareId(0), value); 619 } 620 621 #[test] clone_eq()622 fn clone_eq() { 623 let values = &[ 624 ArpHardwareId::NETROM, 625 ArpHardwareId::ETHERNET, 626 ArpHardwareId::EETHER, 627 ArpHardwareId::AX25, 628 ArpHardwareId::PRONET, 629 ArpHardwareId::CHAOS, 630 ArpHardwareId::IEEE802, 631 ArpHardwareId::ARCNET, 632 ArpHardwareId::APPLETLK, 633 ArpHardwareId::DLCI, 634 ArpHardwareId::ATM, 635 ArpHardwareId::METRICOM, 636 ArpHardwareId::IEEE1394, 637 ArpHardwareId::EUI64, 638 ArpHardwareId::INFINIBAND, 639 ArpHardwareId::SLIP, 640 ArpHardwareId::CSLIP, 641 ArpHardwareId::SLIP6, 642 ArpHardwareId::CSLIP6, 643 ArpHardwareId::RSRVD, 644 ArpHardwareId::ADAPT, 645 ArpHardwareId::ROSE, 646 ArpHardwareId::X25, 647 ArpHardwareId::HWX25, 648 ArpHardwareId::CAN, 649 ArpHardwareId::PPP, 650 ArpHardwareId::CISCO_HDLC, 651 ArpHardwareId::LAPB, 652 ArpHardwareId::DDCMP, 653 ArpHardwareId::RAWHDLC, 654 ArpHardwareId::RAWIP, 655 ArpHardwareId::TUNNEL, 656 ArpHardwareId::TUNNEL6, 657 ArpHardwareId::FRAD, 658 ArpHardwareId::SKIP, 659 ArpHardwareId::LOOPBACK, 660 ArpHardwareId::LOCALTLK, 661 ArpHardwareId::FDDI, 662 ArpHardwareId::BIF, 663 ArpHardwareId::SIT, 664 ArpHardwareId::IPDDP, 665 ArpHardwareId::IPGRE, 666 ArpHardwareId::PIMREG, 667 ArpHardwareId::HIPPI, 668 ArpHardwareId::ASH, 669 ArpHardwareId::ECONET, 670 ArpHardwareId::IRDA, 671 ArpHardwareId::FCPP, 672 ArpHardwareId::FCAL, 673 ArpHardwareId::FCPL, 674 ArpHardwareId::FCFABRIC, 675 ArpHardwareId::IEEE802_TR, 676 ArpHardwareId::IEEE80211, 677 ArpHardwareId::IEEE80211_PRISM, 678 ArpHardwareId::IEEE80211_RADIOTAP, 679 ArpHardwareId::IEEE802154, 680 ArpHardwareId::IEEE802154_MONITOR, 681 ArpHardwareId::PHONET, 682 ArpHardwareId::PHONET_PIPE, 683 ArpHardwareId::CAIF, 684 ArpHardwareId::IP6GRE, 685 ArpHardwareId::NETLINK, 686 ArpHardwareId::IPV6LOWPAN, 687 ArpHardwareId::VSOCKMON, 688 ArpHardwareId::VOID, 689 ArpHardwareId::NONE, 690 ]; 691 692 // clone 693 for v in values { 694 assert_eq!(v, &v.clone()); 695 } 696 697 // eq 698 for (a_pos, a) in values.iter().enumerate() { 699 for (b_pos, b) in values.iter().enumerate() { 700 assert_eq!(a_pos == b_pos, a == b); 701 assert_eq!(a_pos != b_pos, a != b); 702 } 703 } 704 } 705 } 706