pub struct MacAddress(pub [u8; 6]);Expand description
Represents a Media Access Control (MAC) address.
A MAC address is a unique identifier assigned to a network interface for communications at the data link layer of a network segment.
Tuple Fields§
§0: [u8; 6]Implementations§
Source§impl MacAddress
impl MacAddress
Sourcepub fn display_with_oui(&self) -> String
pub fn display_with_oui(&self) -> String
Returns a formatted string of the MAC address, including its OUI if recognized.
- If the OUI is recognized, the format is:
{Manufacturer}:{Last three bytes} - Otherwise, the MAC address is displayed in standard hexadecimal notation.
§Example
use packet_parser::parse::data_link::mac_addres::MacAddress;
let mac = MacAddress([0x2C, 0xFD, 0xA1, 0x3C, 0x4D, 0x5E]);
assert_eq!(mac.display_with_oui(), "ASUSTek:3c:4d:5e");
let unknown_mac = MacAddress([0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5E]);
assert_eq!(unknown_mac.display_with_oui(), "00:1a:2b:3c:4d:5e");Trait Implementations§
Source§impl Clone for MacAddress
impl Clone for MacAddress
Source§fn clone(&self) -> MacAddress
fn clone(&self) -> MacAddress
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MacAddress
impl Debug for MacAddress
Source§impl<'de> Deserialize<'de> for MacAddress
impl<'de> Deserialize<'de> for MacAddress
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for MacAddress
impl Display for MacAddress
Source§impl Hash for MacAddress
impl Hash for MacAddress
Source§impl PartialEq for MacAddress
impl PartialEq for MacAddress
Source§impl Serialize for MacAddress
impl Serialize for MacAddress
Source§impl TryFrom<&[u8]> for MacAddress
impl TryFrom<&[u8]> for MacAddress
Source§fn try_from(bytes: &[u8]) -> Result<Self, Self::Error>
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error>
Converts a byte slice into a MacAddress, enforcing a length of 6 bytes.
§Errors
Returns MacParseError::InvalidLength if the input slice is not exactly 6 bytes.
§Example
use packet_parser::parse::data_link::mac_addres::MacAddress;
use std::convert::TryFrom;
let bytes = [0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5E];
let mac = MacAddress::try_from(bytes.as_ref()).expect("Valid MAC address");
assert_eq!(mac, MacAddress([0x00, 0x1A, 0x2B, 0x3C, 0x4D, 0x5E]));impl Copy for MacAddress
impl Eq for MacAddress
impl StructuralPartialEq for MacAddress
Auto Trait Implementations§
impl Freeze for MacAddress
impl RefUnwindSafe for MacAddress
impl Send for MacAddress
impl Sync for MacAddress
impl Unpin for MacAddress
impl UnsafeUnpin for MacAddress
impl UnwindSafe for MacAddress
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more