Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
mac_address.hpp
Go to the documentation of this file.
1#pragma once
2
8
9#include <array>
10#include <cstdint>
11#include <optional>
12#include <string>
13#include <string_view>
14
15namespace pulp::runtime {
16
26public:
27 constexpr MacAddress() = default;
28
30 constexpr MacAddress(uint8_t a, uint8_t b, uint8_t c,
31 uint8_t d, uint8_t e, uint8_t f)
32 : octets_{a, b, c, d, e, f} {}
33
37 static std::optional<MacAddress> parse(std::string_view text);
38
40 static bool is_valid(std::string_view text) {
41 return parse(text).has_value();
42 }
43
45 std::string to_string() const;
46
48 std::string to_string_hyphens() const;
49
51 const std::array<uint8_t, 6>& octets() const { return octets_; }
52
54 bool is_null() const;
55
57 bool is_multicast() const { return (octets_[0] & 0x01) != 0; }
58
61 bool is_locally_administered() const { return (octets_[0] & 0x02) != 0; }
62
64 bool is_broadcast() const;
65
69 uint32_t oui() const {
70 return (uint32_t(octets_[0]) << 16) |
71 (uint32_t(octets_[1]) << 8) |
72 uint32_t(octets_[2]);
73 }
74
75 bool operator==(const MacAddress& other) const {
76 return octets_ == other.octets_;
77 }
78 bool operator!=(const MacAddress& other) const {
79 return !(*this == other);
80 }
81
82private:
83 std::array<uint8_t, 6> octets_{};
84};
85
86} // namespace pulp::runtime
bool operator==(const MacAddress &other) const
Definition mac_address.hpp:75
std::string to_string() const
Canonical colon-separated lowercase form (e.g. aa:bb:cc:dd:ee:ff).
std::string to_string_hyphens() const
Same as to_string() but with hyphens (e.g. aa-bb-cc-dd-ee-ff).
constexpr MacAddress()=default
bool is_broadcast() const
ff:ff:ff:ff:ff:ff — the L2 broadcast address.
bool is_locally_administered() const
Local-administration bit (bit 1 of first octet).
Definition mac_address.hpp:61
bool is_null() const
All-zero address — typically used as a sentinel for "unknown".
bool operator!=(const MacAddress &other) const
Definition mac_address.hpp:78
bool is_multicast() const
Group bit (LSB of first octet). 0 = unicast, 1 = multicast / broadcast.
Definition mac_address.hpp:57
const std::array< uint8_t, 6 > & octets() const
Raw octets in transmission order.
Definition mac_address.hpp:51
constexpr MacAddress(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f)
Construct from 6 raw octets in transmission order.
Definition mac_address.hpp:30
uint32_t oui() const
Organisationally Unique Identifier — first 3 octets packed big-endian into the low 24 bits of a uint3...
Definition mac_address.hpp:69
static bool is_valid(std::string_view text)
True if text parses as a valid MAC address.
Definition mac_address.hpp:40
static std::optional< MacAddress > parse(std::string_view text)
Try to parse a MAC address.
Definition generated_event_source.hpp:33
@ other
Definition udev_monitor.hpp:26