1 #ifndef PCAPPP_MACADDRESS
2 #define PCAPPP_MACADDRESS
8 #if __cplusplus > 199711L || _MSC_VER >= 1800
9 #include <initializer_list>
34 MacAddress() : m_IsValid(true) { memset(m_Address, 0,
sizeof(m_Address)); }
42 MacAddress(
const uint8_t* addr) : m_IsValid(true) { memcpy(m_Address, addr,
sizeof(m_Address)); }
56 MacAddress(
const std::string& addr) { init(addr.c_str()); }
67 inline MacAddress(uint8_t firstOctest, uint8_t secondOctet, uint8_t thirdOctet, uint8_t fourthOctet, uint8_t fifthOctet, uint8_t sixthOctet);
69 #if __cplusplus > 199711L || _MSC_VER >= 1800
74 MacAddress(std::initializer_list<uint8_t> octets) : m_IsValid { octets.size() ==
sizeof(m_Address) }
79 std::copy(octets.begin(), octets.end(), stdext::checked_array_iterator<uint8_t*>(m_Address, 6));
81 std::copy(octets.begin(), octets.end(), std::begin(m_Address));
85 memset(m_Address, 0,
sizeof(m_Address));
93 bool operator==(
const MacAddress& other)
const {
return memcmp(m_Address, other.m_Address,
sizeof(m_Address)) == 0; }
101 #if __cplusplus > 199711L || _MSC_VER >= 1800
105 MacAddress& operator=(std::initializer_list<uint8_t> octets)
107 m_IsValid = (octets.size() ==
sizeof m_Address);
111 std::copy(octets.begin(), octets.end(), stdext::checked_array_iterator<uint8_t*>(m_Address,
sizeof(m_Address)));
113 std::copy(octets.begin(), octets.end(), std::begin(m_Address));
145 *arr =
new uint8_t[
sizeof(m_Address)];
146 memcpy(*arr, m_Address,
sizeof(m_Address));
154 void copyTo(uint8_t* arr)
const { memcpy(arr, m_Address,
sizeof(m_Address)); }
162 uint8_t m_Address[6];
164 void init(
const char* addr);
167 MacAddress::MacAddress(uint8_t firstOctest, uint8_t secondOctet, uint8_t thirdOctet, uint8_t fourthOctet, uint8_t fifthOctet, uint8_t sixthOctet)
170 m_Address[0] = firstOctest;
171 m_Address[1] = secondOctet;
172 m_Address[2] = thirdOctet;
173 m_Address[3] = fourthOctet;
174 m_Address[4] = fifthOctet;
175 m_Address[5] = sixthOctet;