10 # include <netinet/ether.h>
22 memset(&addr_, 0,
sizeof(addr_));
26 memcpy(&addr_, data,
sizeof(addr_));
42 unsigned int d,
unsigned int e,
unsigned int f) {
43 u_int8_t *p = (u_int8_t *)&addr_;
45 p[0] = a; p[1] = b; p[2] = c; p[3] = d; p[4] = e; p[5] = f;
49 boost::system::error_code *errorp) {
54 static char hexchars[] = {
55 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
56 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
59 const u_int8_t *addr = (u_int8_t *) &addr_;
61 for (
int bidx = 0; bidx < 6; ++bidx) {
64 temp[tidx++] = hexchars[(addr[bidx] >> 4) & 0x0F];
65 temp[tidx++] = hexchars[addr[bidx] & 0x0F];
72 boost::system::error_code *errorp) {
74 u_int8_t *p = (u_int8_t*)&a;
77 int ret = sscanf(str.c_str(),
"%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx%c",
78 &p[0], &p[1], &p[2], &p[3], &p[4], &p[5], &extra);
79 if ((
size_t)ret != size() || strchr(str.c_str(),
'x') || strchr(str.c_str(),
'X')) {
81 *errorp = make_error_code(boost::system::errc::invalid_argument);
89 return memcmp(&addr_, &rhs.
addr_,
sizeof(addr_));
90 return memcmp(&addr_, &rhs.
addr_, len);
96 memcpy(p, &addr_, size());
101 memcpy(&addr_, c, size());
106 memcpy(&addr_, sa->sa_data, size());
bool ToArray(u_int8_t *p, size_t s) const
static const MacAddress kMulticastMac
static const MacAddress kZeroMac
std::string ToString() const
static const MacAddress kBroadcastMac
int CompareTo(const MacAddress &rhs, int len=0) const
MacAddress & operator=(const u_int8_t *c)
static int CompareTo(const AuthenticationKey &lhs, const AuthenticationKey &rhs)
static MacAddress FromString(const std::string &str, boost::system::error_code *error=NULL)
static PhysicalDevice::ManagementProtocol FromString(const string &proto)