Struct net_types::ethernet::Mac

source ·
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

source

pub const BYTES: usize = 6usize

The number of bytes in a Mac address.

source

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.

source

pub const DEFAULT_EUI_MAGIC: [u8; 2] = _

The default RFC 4291 EUI-64 magic value used by the to_eui64 method.

source

pub const UNSPECIFIED: Mac = _

The all-zeroes MAC address.

source

pub const fn new(bytes: [u8; 6]) -> Mac

Constructs a new MAC address.

source

pub const fn bytes(self) -> [u8; 6]

Gets the bytes of the MAC address.

source

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).

source

pub fn to_eui64_with_magic(self, eui_magic: [u8; 2]) -> [u8; 8]

Returns the RFC 4291 EUI-64 interface identifier for this MAC address with a custom EUI magic value.

eui_magic is the two bytes that are inserted between the bytes of the MAC address to form the identifier. Also see the to_eui64 method, which uses the default magic value of 0xFFFE.

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).

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 AsMut<[u8]> for Mac

source§

fn as_mut(&mut self) -> &mut [u8]

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<[u8]> for Mac

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl BroadcastAddress for Mac

source§

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 Clone for Mac

source§

fn clone(&self) -> Mac

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Mac

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Mac

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, A: IpAddress> From<&'a MulticastAddr<A>> for Mac

source§

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 From<BroadcastAddr<Mac>> for Mac

source§

fn from(addr: BroadcastAddr<Mac>) -> Mac

Converts to this type from the input type.
source§

impl<A: IpAddress> From<MulticastAddr<A>> for Mac

source§

fn from(addr: MulticastAddr<A>) -> Mac

Converts a multicast IP address to a MAC address.

This method is equivalent to (&addr).into().

source§

impl From<MulticastAddr<Mac>> for Mac

source§

fn from(addr: MulticastAddr<Mac>) -> Mac

Converts to this type from the input type.
source§

impl From<UnicastAddr<Mac>> for Mac

source§

fn from(addr: UnicastAddr<Mac>) -> Mac

Converts to this type from the input type.
source§

impl FromBytes for Mac
where [u8; 6]: FromBytes,

§

fn ref_from(bytes: &[u8]) -> Option<&Self>
where Self: NoCell + Sized,

Interprets the given bytes as a &Self without copying. Read more
§

fn ref_from_prefix(bytes: &[u8]) -> Option<&Self>
where Self: Sized + NoCell,

Interprets the prefix of the given bytes as a &Self without copying. Read more
§

fn ref_from_suffix(bytes: &[u8]) -> Option<&Self>
where Self: Sized + NoCell,

Interprets the suffix of the given bytes as a &Self without copying. Read more
§

fn mut_from(bytes: &mut [u8]) -> Option<&mut Self>
where Self: Sized + IntoBytes + NoCell,

Interprets the given bytes as a &mut Self without copying. Read more
§

fn mut_from_prefix(bytes: &mut [u8]) -> Option<&mut Self>
where Self: Sized + IntoBytes + NoCell,

Interprets the prefix of the given bytes as a &mut Self without copying. Read more
§

fn mut_from_suffix(bytes: &mut [u8]) -> Option<&mut Self>
where Self: Sized + IntoBytes + NoCell,

Interprets the suffix of the given bytes as a &mut Self without copying. Read more
§

fn slice_from(bytes: &[u8]) -> Option<&[Self]>
where Self: Sized + NoCell,

Interprets the given bytes as a &[Self] without copying. Read more
§

fn slice_from_prefix(bytes: &[u8], count: usize) -> Option<(&[Self], &[u8])>
where Self: Sized + NoCell,

Interprets the prefix of the given bytes as a &[Self] with length equal to count without copying. Read more
§

fn slice_from_suffix(bytes: &[u8], count: usize) -> Option<(&[u8], &[Self])>
where Self: Sized + NoCell,

Interprets the suffix of the given bytes as a &[Self] with length equal to count without copying. Read more
§

fn mut_slice_from(bytes: &mut [u8]) -> Option<&mut [Self]>
where Self: Sized + IntoBytes + NoCell,

Interprets the given bytes as a &mut [Self] without copying. Read more
§

fn mut_slice_from_prefix( bytes: &mut [u8], count: usize ) -> Option<(&mut [Self], &mut [u8])>
where Self: Sized + IntoBytes + NoCell,

Interprets the prefix of the given bytes as a &mut [Self] with length equal to count without copying. Read more
§

fn mut_slice_from_suffix( bytes: &mut [u8], count: usize ) -> Option<(&mut [u8], &mut [Self])>
where Self: Sized + IntoBytes + NoCell,

Interprets the suffix of the given bytes as a &mut [Self] with length equal to count without copying. Read more
§

fn read_from(bytes: &[u8]) -> Option<Self>
where Self: Sized,

Reads a copy of Self from bytes. Read more
§

fn read_from_prefix(bytes: &[u8]) -> Option<Self>
where Self: Sized,

Reads a copy of Self from the prefix of bytes. Read more
§

fn read_from_suffix(bytes: &[u8]) -> Option<Self>
where Self: Sized,

Reads a copy of Self from the suffix of bytes. Read more
source§

impl FromZeros for Mac
where [u8; 6]: FromZeros,

§

fn zero(&mut self)

Overwrites self with zeros. Read more
§

fn new_zeroed() -> Self
where Self: Sized,

Creates an instance of Self from zeroed bytes. Read more
source§

impl Hash for Mac

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl IntoBytes for Mac
where [u8; 6]: IntoBytes,

§

fn as_bytes(&self) -> &[u8]
where Self: NoCell,

Gets the bytes of this value. Read more
§

fn as_bytes_mut(&mut self) -> &mut [u8]
where Self: FromBytes + NoCell,

Gets the bytes of this value mutably. Read more
§

fn write_to(&self, bytes: &mut [u8]) -> Option<()>
where Self: NoCell,

Writes a copy of self to bytes. Read more
§

fn write_to_prefix(&self, bytes: &mut [u8]) -> Option<()>
where Self: NoCell,

Writes a copy of self to the prefix of bytes. Read more
§

fn write_to_suffix(&self, bytes: &mut [u8]) -> Option<()>
where Self: NoCell,

Writes a copy of self to the suffix of bytes. Read more
source§

impl MulticastAddress for Mac

source§

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 PartialEq for Mac

source§

fn eq(&self, other: &Mac) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl UnicastAddress for Mac

source§

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.

source§

impl Copy for Mac

source§

impl Eq for Mac

source§

impl StructuralPartialEq for Mac

source§

impl Unaligned for Mac
where [u8; 6]: Unaligned,

Auto Trait Implementations§

§

impl RefUnwindSafe for Mac

§

impl Send for Mac

§

impl Sync for Mac

§

impl Unpin for Mac

§

impl UnwindSafe for Mac

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.