IEEE 802 MAC (Ethernet hardware) address. More...
#include <macaddress.h>
Public Types | |
| using | DataFormat = Array< uint8_t, 6 > |
| Raw 6-byte storage format for a MAC address. | |
Public Member Functions | |
| MacAddress () | |
| Default constructor. Creates a null (00:00:00:00:00:00) address. | |
| MacAddress (const DataFormat &bytes) | |
| Constructs from raw 6-byte data. | |
| MacAddress (uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f) | |
| Constructs from six individual octets. | |
| bool | isNull () const |
| Returns true if all bytes are zero. | |
| bool | isBroadcast () const |
| Returns true if this is the Ethernet broadcast address (ff:ff:ff:ff:ff:ff). | |
| bool | isMulticast () const |
| Returns true if this is a group (multicast) address. | |
| bool | isGroupMulticast () const |
| Returns true if this is a group multicast address but NOT broadcast. | |
| bool | isIpv4Multicast () const |
| Returns true if this is an IPv4 multicast MAC address. | |
| bool | isIpv6Multicast () const |
| Returns true if this is an IPv6 multicast MAC address. | |
| bool | isUnicast () const |
| Returns true if this is a unicast address. | |
| bool | isLocallyAdministered () const |
| Returns true if this is a locally-administered address. | |
| const DataFormat & | data () const |
| Returns a const reference to the raw 6-byte data. | |
| const uint8_t * | raw () const |
| Returns a pointer to the raw byte data. | |
| uint8_t | octet (int index) const |
| Returns a single octet of the address. | |
| String | toString () const |
| Returns a colon-separated hex string. | |
| String | toString (char separator) const |
| Returns a hex string with a custom separator. | |
| bool | operator== (const MacAddress &other) const |
| Returns true if both addresses are equal. | |
| bool | operator!= (const MacAddress &other) const |
| Returns true if the addresses are not equal. | |
| bool | operator< (const MacAddress &other) const |
| Less-than comparison for ordering (lexicographic). | |
Static Public Member Functions | |
| static Result< MacAddress > | fromString (const String &str) |
| Parses a MAC address from a string. | |
| static MacAddress | broadcast () |
| Returns the Ethernet broadcast address (ff:ff:ff:ff:ff:ff). | |
| static MacAddress | fromIpv4Multicast (const Ipv4Address &addr) |
| Computes the multicast MAC address for an IPv4 multicast address. | |
| static MacAddress | fromIpv6Multicast (const Ipv6Address &addr) |
| Computes the multicast MAC address for an IPv6 multicast address. | |
IEEE 802 MAC (Ethernet hardware) address.
Simple value type representing a 48-bit MAC address. Provides parsing, formatting, and classification (broadcast, multicast, locally-administered).
This class is purely computational and requires no platform-specific headers or system calls.
This class is not thread-safe. Concurrent access to a single instance requires external synchronization.
|
inlineexplicit |
Constructs from raw 6-byte data.
| bytes | The 6 bytes of the MAC address. |
Constructs from six individual octets.
| a | First octet. |
| b | Second octet. |
| c | Third octet. |
| d | Fourth octet. |
| e | Fifth octet. |
| f | Sixth octet. |
|
inline |
Returns a const reference to the raw 6-byte data.
|
static |
Computes the multicast MAC address for an IPv4 multicast address.
Maps an IPv4 multicast address (224.0.0.0/4) to its corresponding Ethernet multicast MAC address per IANA (RFC 1112). The mapping uses the OUI 01:00:5e and the low-order 23 bits of the IPv4 address, meaning that 32 different multicast IP addresses map to each MAC.
| addr | An IPv4 multicast address. |
|
static |
Computes the multicast MAC address for an IPv6 multicast address.
Maps an IPv6 multicast address (ff00::/8) to its corresponding Ethernet multicast MAC address per RFC 2464. The mapping uses the prefix 33:33 and the low-order 32 bits of the IPv6 address.
| addr | An IPv6 multicast address. |
|
static |
Parses a MAC address from a string.
Accepts colon-separated ("aa:bb:cc:dd:ee:ff") or hyphen-separated ("aa-bb-cc-dd-ee-ff") hexadecimal notation. Case-insensitive.
| str | The string to parse. |
|
inline |
Returns true if this is the Ethernet broadcast address (ff:ff:ff:ff:ff:ff).
This is the Layer 2 broadcast address used for both Ethernet broadcast frames and IP-level broadcast (255.255.255.255). Note that the broadcast address also has the group/multicast bit set, so isMulticast() returns true for the broadcast address.
|
inline |
Returns true if this is a group multicast address but NOT broadcast.
Returns true when the I/G bit is set and the address is not ff:ff:ff:ff:ff:ff. This is the typical check for "is this a multicast destination" in the practical sense.
|
inline |
Returns true if this is an IPv4 multicast MAC address.
IPv4 multicast maps to the IANA OUI 01:00:5e with the high bit of the fourth octet clear, giving the range 01:00:5e:00:00:00 through 01:00:5e:7f:ff:ff (RFC 1112).
|
inline |
Returns true if this is an IPv6 multicast MAC address.
IPv6 multicast maps to the prefix 33:33 followed by the low-order 32 bits of the IPv6 address (RFC 2464).
|
inline |
Returns true if this is a locally-administered address.
The second-least-significant bit of the first octet indicates local administration.
|
inline |
Returns true if this is a group (multicast) address.
A MAC address is a group address when the least-significant bit of the first octet is set (IEEE 802 I/G bit). This includes both multicast addresses and the broadcast address (ff:ff:ff:ff:ff:ff). Use isBroadcast() to distinguish, or isGroupMulticast() to exclude broadcast.
|
inline |
Returns true if this is a unicast address.
A unicast address has the I/G bit clear (not multicast, not broadcast).
|
inline |
Returns a single octet of the address.
| index | Octet index (0-5). |
Returns a pointer to the raw byte data.
| String MacAddress::toString | ( | ) | const |
Returns a colon-separated hex string.
Returns a hex string with a custom separator.
| separator | The character to place between octets. |