| // Copyright 2018 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| //! The Address Resolution Protocol (ARP). |
| |
| /// The type of an ARP operation. |
| #[derive(Debug, PartialEq)] |
| #[allow(missing_docs)] |
| #[repr(u16)] |
| pub enum ArpOp { |
| Request = ArpOp::REQUEST, |
| Response = ArpOp::RESPONSE, |
| } |
| |
| impl ArpOp { |
| const REQUEST: u16 = 0x0001; |
| const RESPONSE: u16 = 0x0002; |
| |
| /// Construct an `ArpOp` from a `u16`. |
| /// |
| /// `from_u16` returns the `ArpOp` with the numerical value `u`, or `None` |
| /// if the value is unrecognized. |
| pub fn from_u16(u: u16) -> Option<ArpOp> { |
| match u { |
| Self::REQUEST => Some(ArpOp::Request), |
| Self::RESPONSE => Some(ArpOp::Response), |
| _ => None, |
| } |
| } |
| } |
| |
| /// An ARP hardware protocol. |
| #[derive(Debug, PartialEq)] |
| #[allow(missing_docs)] |
| #[repr(u16)] |
| pub enum ArpHardwareType { |
| Ethernet = ArpHardwareType::ETHERNET, |
| } |
| |
| impl ArpHardwareType { |
| const ETHERNET: u16 = 0x0001; |
| |
| /// Construct an `ArpHardwareType` from a `u16`. |
| /// |
| /// `from_u16` returns the `ArpHardwareType` with the numerical value `u`, |
| /// or `None` if the value is unrecognized. |
| pub fn from_u16(u: u16) -> Option<ArpHardwareType> { |
| match u { |
| Self::ETHERNET => Some(ArpHardwareType::Ethernet), |
| _ => None, |
| } |
| } |
| } |