pub struct Mac(/* private fields */);
Expand description
A media access control (MAC) address.
MAC addresses are used to identify devices in the Ethernet protocol.
MAC addresses can be derived from multicast IP addresses; see the From
implementation for more details.
§Layout
Mac
has the same layout as [u8; 6]
, which is the layout that most
protocols use to represent a MAC address in their packet formats. This can
be useful when parsing a MAC address from a packet. For example:
/// The header of an Ethernet frame.
///
/// `EthernetHeader` has the same layout as the header of an Ethernet frame.
#[repr(C)]
struct EthernetHeader {
dst: Mac,
src: Mac,
ethertype: [u8; 2],
}
Implementations§
Source§impl Mac
impl Mac
Sourcepub const BROADCAST: Mac
pub const BROADCAST: Mac
The broadcast MAC address.
The broadcast MAC address, FF:FF:FF:FF:FF:FF, indicates that a frame should be received by all receivers regardless of their local MAC address.
Sourcepub const DEFAULT_EUI_MAGIC: [u8; 2]
pub const DEFAULT_EUI_MAGIC: [u8; 2]
Sourcepub const UNSPECIFIED: Mac
pub const UNSPECIFIED: Mac
The all-zeroes MAC address.
Sourcepub fn to_eui64(self) -> [u8; 8]
pub fn to_eui64(self) -> [u8; 8]
Returns the RFC 4291 EUI-64 interface identifier for this MAC address with the default EUI magic value.
mac.to_eui64()
is equivalent to
mac.to_eui64_with_magic(Mac::DEFAULT_EUI_MAGIC)
.
Sourcepub fn to_ipv6_link_local(
self,
) -> AddrSubnet<Ipv6Addr, LinkLocalUnicastAddr<Ipv6Addr>>
pub fn to_ipv6_link_local( self, ) -> AddrSubnet<Ipv6Addr, LinkLocalUnicastAddr<Ipv6Addr>>
Returns the link-local unicast IPv6 address and subnet for this MAC address, as per [RFC 4862], with the default EUI magic value.
mac.to_ipv6_link_local()
is equivalent to
mac.to_ipv6_link_local_with_magic(Mac::DEFAULT_EUI_MAGIC)
.
Sourcepub fn to_ipv6_link_local_with_magic(
self,
eui_magic: [u8; 2],
) -> AddrSubnet<Ipv6Addr, LinkLocalUnicastAddr<Ipv6Addr>>
pub fn to_ipv6_link_local_with_magic( self, eui_magic: [u8; 2], ) -> AddrSubnet<Ipv6Addr, LinkLocalUnicastAddr<Ipv6Addr>>
Returns the link-local unicast IPv6 address and subnet for this MAC address, as per RFC 4862.
eui_magic
is the two bytes that are inserted between the bytes of the
MAC address to form the identifier. Also see the to_ipv6_link_local
method, which uses the default magic value of 0xFFFE.
The subnet prefix length is 128 -
Ipv6::UNICAST_INTERFACE_IDENTIFIER_BITS
.
Trait Implementations§
Source§impl BroadcastAddress for Mac
impl BroadcastAddress for Mac
Source§fn is_broadcast(&self) -> bool
fn is_broadcast(&self) -> bool
Is this the broadcast MAC address?
Returns true if this is the broadcast MAC address, FF:FF:FF:FF:FF:FF.
Note that the broadcast address is also considered a multicast address,
so addr.is_broadcast()
implies addr.is_multicast()
.
Source§impl<'a, A: IpAddress> From<&'a MulticastAddr<A>> for Mac
impl<'a, A: IpAddress> From<&'a MulticastAddr<A>> for Mac
Source§fn from(addr: &'a MulticastAddr<A>) -> Mac
fn from(addr: &'a MulticastAddr<A>) -> Mac
Converts a multicast IP address to a MAC address.
This method is equivalent to MulticastAddr::<Mac>::from(addr).get()
.
Source§impl<A: IpAddress> From<MulticastAddr<A>> for Mac
impl<A: IpAddress> From<MulticastAddr<A>> for Mac
Source§fn from(addr: MulticastAddr<A>) -> Mac
fn from(addr: MulticastAddr<A>) -> Mac
Converts a multicast IP address to a MAC address.
This method is equivalent to (&addr).into()
.
Source§impl FromBytes for Mac
impl FromBytes for Mac
§fn ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
fn ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
§fn ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
fn ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: KnownLayout + Immutable,
§fn ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: Immutable + KnownLayout,
fn ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, Infallible>>where
Self: Immutable + KnownLayout,
&Self
. Read more§fn mut_from_bytes(
source: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
fn mut_from_bytes(
source: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
§fn mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
fn mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
§fn mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
fn mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, Infallible>>where
Self: IntoBytes + KnownLayout,
Source§impl IntoBytes for Mac
impl IntoBytes for Mac
§fn as_mut_bytes(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
fn as_mut_bytes(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
§fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
fn write_to(&self, dst: &mut [u8]) -> Result<(), SizeError<&Self, &mut [u8]>>where
Self: Immutable,
Source§impl KnownLayout for Macwhere
Self: Sized,
impl KnownLayout for Macwhere
Self: Sized,
Source§type PointerMetadata = ()
type PointerMetadata = ()
Self
. Read moreSource§impl MulticastAddress for Mac
impl MulticastAddress for Mac
Source§fn is_multicast(&self) -> bool
fn is_multicast(&self) -> bool
Is this a multicast MAC address?
Returns true if the least significant bit of the first byte of the address is 1.
Source§fn is_non_multicast(&self) -> bool
fn is_non_multicast(&self) -> bool
is_multicast()
.Source§impl TryFromBytes for Mac
impl TryFromBytes for Mac
§fn try_ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
fn try_ref_from_bytes(
source: &[u8],
) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
§fn try_ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
fn try_ref_from_prefix(
source: &[u8],
) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
§fn try_ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
fn try_ref_from_suffix(
source: &[u8],
) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: KnownLayout + Immutable,
§fn try_mut_from_bytes(
bytes: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout,
fn try_mut_from_bytes(
bytes: &mut [u8],
) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout,
§fn try_mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout,
fn try_mut_from_prefix(
source: &mut [u8],
) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout,
§fn try_mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout,
fn try_mut_from_suffix(
source: &mut [u8],
) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>where
Self: KnownLayout,
§fn try_read_from_bytes(
source: &[u8],
) -> Result<Self, ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
fn try_read_from_bytes(
source: &[u8],
) -> Result<Self, ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
§fn try_read_from_prefix(
source: &[u8],
) -> Result<(Self, &[u8]), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
fn try_read_from_prefix(
source: &[u8],
) -> Result<(Self, &[u8]), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
§fn try_read_from_suffix(
source: &[u8],
) -> Result<(&[u8], Self), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
fn try_read_from_suffix(
source: &[u8],
) -> Result<(&[u8], Self), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>where
Self: Sized,
Source§impl UnicastAddress for Mac
impl UnicastAddress for Mac
Source§fn is_unicast(&self) -> bool
fn is_unicast(&self) -> bool
Is this a unicast MAC address?
Returns true if the least significant bit of the first byte of the address is 0.