1 #ifndef PCAPPP_MACADDRESS 2 #define PCAPPP_MACADDRESS 8 #if __cplusplus > 199711L || _MSC_VER >= 1800 9 #include <initializer_list> 35 MacAddress() : m_IsValid(true) { memset(m_Address, 0,
sizeof(m_Address)); }
43 MacAddress(
const uint8_t* addr) : m_IsValid(true) { memcpy(m_Address, addr,
sizeof(m_Address)); }
57 MacAddress(
const std::string& addr) { init(addr.c_str()); }
68 inline MacAddress(uint8_t firstOctest, uint8_t secondOctet, uint8_t thirdOctet, uint8_t fourthOctet, uint8_t fifthOctet, uint8_t sixthOctet);
70 #if __cplusplus > 199711L || _MSC_VER >= 1800 75 MacAddress(std::initializer_list<uint8_t> octets) : m_IsValid { octets.size() ==
sizeof(m_Address) }
80 std::copy(octets.begin(), octets.end(), stdext::checked_array_iterator<uint8_t*>(m_Address, 6));
82 std::copy(octets.begin(), octets.end(), std::begin(m_Address));
86 memset(m_Address, 0,
sizeof(m_Address));
95 bool operator==(
const MacAddress& other)
const {
return memcmp(m_Address, other.m_Address,
sizeof(m_Address)) == 0; }
104 #if __cplusplus > 199711L || _MSC_VER >= 1800 108 MacAddress& operator=(std::initializer_list<uint8_t> octets)
110 m_IsValid = (octets.size() ==
sizeof m_Address);
114 std::copy(octets.begin(), octets.end(), stdext::checked_array_iterator<uint8_t*>(m_Address,
sizeof(m_Address)));
116 std::copy(octets.begin(), octets.end(), std::begin(m_Address));
148 *arr =
new uint8_t[
sizeof(m_Address)];
149 memcpy(*arr, m_Address,
sizeof(m_Address));
157 void copyTo(uint8_t* arr)
const { memcpy(arr, m_Address,
sizeof(m_Address)); }
165 uint8_t m_Address[6];
167 void init(
const char* addr);
170 MacAddress::MacAddress(uint8_t firstOctest, uint8_t secondOctet, uint8_t thirdOctet, uint8_t fourthOctet, uint8_t fifthOctet, uint8_t sixthOctet)
173 m_Address[0] = firstOctest;
174 m_Address[1] = secondOctet;
175 m_Address[2] = thirdOctet;
176 m_Address[3] = fourthOctet;
177 m_Address[4] = fifthOctet;
178 m_Address[5] = sixthOctet;
183 inline std::ostream& operator<<(std::ostream& os,
const pcpp::MacAddress& macAddress)
The main namespace for the PcapPlusPlus lib.
bool operator!=(const MacAddress &other) const
Definition: MacAddress.h:102
bool isValid() const
Definition: MacAddress.h:134
static MacAddress Zero
Definition: MacAddress.h:162
MacAddress(const std::string &addr)
Definition: MacAddress.h:57
void copyTo(uint8_t **arr) const
Definition: MacAddress.h:146
bool operator==(const MacAddress &other) const
Definition: MacAddress.h:95
MacAddress()
Definition: MacAddress.h:35
const uint8_t * getRawData() const
Definition: MacAddress.h:127
MacAddress(const uint8_t *addr)
Definition: MacAddress.h:43
MacAddress(const char *addr)
Definition: MacAddress.h:50
std::string toString() const
void copyTo(uint8_t *arr) const
Definition: MacAddress.h:157
Definition: MacAddress.h:28