1 #ifndef PCAPPP_IP_ADDRESSES 2 #define PCAPPP_IP_ADDRESSES 38 IPv4Address(uint32_t addrAsInt) { memcpy(m_Bytes, &addrAsInt,
sizeof(m_Bytes)); }
44 IPv4Address(
const uint8_t bytes[4]) { memcpy(m_Bytes, bytes,
sizeof(m_Bytes)); }
57 inline uint32_t
toInt()
const;
62 const uint8_t*
toBytes()
const {
return m_Bytes; }
92 uint32_t intVal =
toInt();
93 std::reverse((uint8_t*)(&intVal), (uint8_t*)(&intVal) +
sizeof(intVal));
95 uint32_t rhsIntVal = rhs.
toInt();
96 std::reverse((uint8_t*)(&rhsIntVal), (uint8_t*)(&rhsIntVal) +
sizeof(rhsIntVal));
98 return intVal < rhsIntVal;
152 memcpy(&addr, m_Bytes,
sizeof(m_Bytes));
172 IPv6Address(
const uint8_t bytes[16]) { memcpy(m_Bytes, bytes,
sizeof(m_Bytes)); }
184 const uint8_t*
toBytes()
const {
return m_Bytes; }
224 void copyTo(uint8_t** arr,
size_t& length)
const;
231 void copyTo(uint8_t* arr)
const { memcpy(arr, m_Bytes,
sizeof(m_Bytes)); }
305 IPAddress(
const std::string& addrAsString);
329 std::string
toString()
const {
return (getType() == IPv4AddressType) ? m_IPv4.toString() : m_IPv6.toString(); }
334 bool isValid()
const {
return (getType() == IPv4AddressType) ? m_IPv4.isValid() : m_IPv6.isValid(); }
339 bool isIPv4()
const {
return getType() == IPv4AddressType; }
344 bool isIPv6()
const {
return getType() == IPv6AddressType; }
350 bool isMulticast()
const {
return (getType() == IPv4AddressType) ? m_IPv4.isMulticast() : m_IPv6.isMulticast(); }
391 return rhs.
isIPv4() ? (m_IPv4 == rhs.m_IPv4) :
false;
393 return rhs.
isIPv6() ? m_IPv6 == rhs.m_IPv6 :
false;
402 return rhs.
isIPv4() ? (m_IPv4 < rhs.m_IPv4) :
true;
404 return rhs.
isIPv6() ? m_IPv6 < rhs.m_IPv6 :
false;
409 m_Type = IPv4AddressType;
416 m_Type = IPv6AddressType;
The main namespace for the PcapPlusPlus lib.
const uint8_t * toBytes() const
Definition: IpAddress.h:184
IPv4Address()
Definition: IpAddress.h:32
IPv4Address(const uint8_t bytes[4])
Definition: IpAddress.h:44
static const IPv6Address MulticastRangeLowerBound
Definition: IpAddress.h:254
AddressType
Definition: IpAddress.h:271
bool isIPv4() const
Definition: IpAddress.h:339
bool isValid() const
Definition: IpAddress.h:80
static const IPv4Address Zero
Definition: IpAddress.h:131
bool operator==(const IPv4Address &rhs) const
Definition: IpAddress.h:85
const uint8_t * toBytes() const
Definition: IpAddress.h:62
bool operator<(const IPAddress &rhs) const
Definition: IpAddress.h:396
bool operator==(const IPAddress &rhs) const
Definition: IpAddress.h:388
static const IPv4Address MulticastRangeLowerBound
Definition: IpAddress.h:139
bool operator!=(const IPAddress &rhs) const
Definition: IpAddress.h:377
bool operator<(const IPv6Address &rhs) const
Definition: IpAddress.h:211
static const IPv6Address Zero
Definition: IpAddress.h:247
IPv4Address(uint32_t addrAsInt)
Definition: IpAddress.h:38
bool isMulticast() const
Definition: IpAddress.h:350
bool isIPv6() const
Definition: IpAddress.h:344
Definition: IpAddress.h:26
Definition: IpAddress.h:160
const IPv6Address & getIPv6() const
Definition: IpAddress.h:362
const IPv4Address & getIPv4() const
Definition: IpAddress.h:356
bool isValid() const
Definition: IpAddress.h:334
std::string toString() const
Definition: IpAddress.h:329
IPv6Address()
Definition: IpAddress.h:166
bool operator!=(const IPv4Address &rhs) const
Definition: IpAddress.h:104
void copyTo(uint8_t *arr) const
Definition: IpAddress.h:231
IPAddress()
Definition: IpAddress.h:286
bool operator==(const IPv6Address &rhs) const
Definition: IpAddress.h:206
bool operator<(const IPv4Address &rhs) const
Definition: IpAddress.h:90
bool operator!=(const IPv6Address &rhs) const
Definition: IpAddress.h:216
IPAddress(const IPv6Address &addr)
Definition: IpAddress.h:298
IPv6Address(const uint8_t bytes[16])
Definition: IpAddress.h:172
bool isValid() const
Definition: IpAddress.h:201
IPAddress & operator=(const IPv4Address &addr)
Definition: IpAddress.h:407
Definition: IpAddress.h:265
std::string toString() const
bool matchSubnet(const IPv4Address &subnet, const std::string &subnetMask) const
Definition: IpAddress.h:276
IPAddress(const IPv4Address &addr)
Definition: IpAddress.h:292
AddressType getType() const
Definition: IpAddress.h:323
uint32_t toInt() const
Definition: IpAddress.h:149