-
Notifications
You must be signed in to change notification settings - Fork 14
/
DlepMac.cpp
46 lines (39 loc) · 939 Bytes
/
DlepMac.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* Dynamic Link Exchange Protocol (DLEP)
*
* Copyright (C) 2015, 2016, 2018 Massachusetts Institute of Technology
*/
#include <sstream>
#include <iomanip>
#include "DlepCommon.h"
namespace LLDLEP
{
/// Return true iff mac1 < mac2
bool operator<(const DlepMac & mac1, const DlepMac & mac2)
{
return (mac1.mac_addr < mac2.mac_addr);
}
/// Return true iff mac1 == mac2
bool operator==(const DlepMac & mac1, const DlepMac & mac2)
{
return (mac1.mac_addr == mac2.mac_addr);
}
std::ostream & operator<<(std::ostream & os, const DlepMac & mac)
{
os << mac.to_string();
return os;
}
std::string DlepMac::to_string() const
{
std::ostringstream s;
s << std::hex << std::setfill('0');
std::string colon = "";
for (auto mac_byte : mac_addr)
{
s << std::setw(0) << colon
<< std::setw(2) << (unsigned int)mac_byte;
colon = ":";
}
return s.str();
}
} // namespace LLDLEP