#[repr(transparent)]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 AsBytes for Macwhere
[u8; 6]: AsBytes,
impl AsBytes for Macwhere [u8; 6]: AsBytes,
§fn as_bytes_mut(&mut self) -> &mut [u8] ⓘwhere
Self: FromBytes,
fn as_bytes_mut(&mut self) -> &mut [u8] ⓘwhere Self: FromBytes,
§fn write_to_prefix(&self, bytes: &mut [u8]) -> Option<()>
fn write_to_prefix(&self, bytes: &mut [u8]) -> Option<()>
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 Macwhere
[u8; 6]: FromBytes,
impl FromBytes for Macwhere [u8; 6]: FromBytes,
source§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§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.