21 #ifndef INCLUDE_OLA_NETWORK_MACADDRESS_H_
22 #define INCLUDE_OLA_NETWORK_MACADDRESS_H_
36 #include <sys/types.h>
37 #include <net/ethernet.h>
46 #define ether_addr_octet octet
70 enum { LENGTH = ETHER_ADDR_LEN };
73 memset(m_address.ether_addr_octet, 0, LENGTH);
76 explicit MACAddress(
const struct ether_addr &address)
77 : m_address(address) {
86 memcpy(m_address.ether_addr_octet, data, LENGTH);
90 : m_address(other.m_address) {
93 MACAddress& operator=(
const MACAddress &other) {
95 m_address = other.m_address;
100 bool operator==(
const MACAddress &other)
const {
101 return (memcmp(m_address.ether_addr_octet,
102 other.m_address.ether_addr_octet,
106 bool operator!=(
const MACAddress &other)
const {
107 return !(*
this == other);
116 return (memcmp(m_address.ether_addr_octet,
117 other.m_address.ether_addr_octet,
121 bool operator>(
const MACAddress &other)
const {
122 return (memcmp(m_address.ether_addr_octet,
123 other.m_address.ether_addr_octet,
127 const struct ether_addr& Address()
const {
133 void Get(uint8_t ptr[LENGTH])
const {
135 reinterpret_cast<const uint8_t*>(&m_address),
145 bool Pack(uint8_t *buffer,
unsigned int length)
const {
155 friend std::ostream&
operator<< (std::ostream &out,
166 static MACAddress*
FromString(
const std::string &address);
175 static bool FromString(
const std::string &address, MACAddress *target);
178 static MACAddress FromStringOrDie(
const std::string &address);
181 struct ether_addr m_address;
188 #endif // INCLUDE_OLA_NETWORK_MACADDRESS_H_