-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.cpp
More file actions
28 lines (25 loc) · 1011 Bytes
/
Util.cpp
File metadata and controls
28 lines (25 loc) · 1011 Bytes
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
// arpbuddy - copyright 2021
#include <Util.h>
namespace Util
{
namespace
{
const char *const g_nibbleToHex = "0123456789abcdef";
}
void PrintHardwareAddr(std::ostream &os, const std::uint8_t addr[6])
{
os << g_nibbleToHex[(addr[0] >> 4) & 0xf] << g_nibbleToHex[addr[0] & 0xf] << ':';
os << g_nibbleToHex[(addr[1] >> 4) & 0xf] << g_nibbleToHex[addr[1] & 0xf] << ':';
os << g_nibbleToHex[(addr[2] >> 4) & 0xf] << g_nibbleToHex[addr[2] & 0xf] << ':';
os << g_nibbleToHex[(addr[3] >> 4) & 0xf] << g_nibbleToHex[addr[3] & 0xf] << ':';
os << g_nibbleToHex[(addr[4] >> 4) & 0xf] << g_nibbleToHex[addr[4] & 0xf] << ':';
os << g_nibbleToHex[(addr[5] >> 4) & 0xf] << g_nibbleToHex[addr[5] & 0xf];
}
void PrintProtocolAddr(std::ostream &os, const std::uint8_t addr[4])
{
os << int(addr[0]) << '.';
os << int(addr[1]) << '.';
os << int(addr[2]) << '.';
os << int(addr[3]);
}
} // namespace Util