1 #ifndef PCAPPP_IP_ADDRESSES 2 #define PCAPPP_IP_ADDRESSES 39 IPv4Address(uint32_t addrAsInt) { memcpy(m_Bytes, &addrAsInt,
sizeof(m_Bytes)); }
45 IPv4Address(
const uint8_t bytes[4]) { memcpy(m_Bytes, bytes,
sizeof(m_Bytes)); }
58 inline uint32_t
toInt()
const;
63 const uint8_t*
toBytes()
const {
return m_Bytes; }
97 uint32_t intVal =
toInt();
98 std::reverse((uint8_t*)(&intVal), (uint8_t*)(&intVal) +
sizeof(intVal));
100 uint32_t rhsIntVal = rhs.
toInt();
101 std::reverse((uint8_t*)(&rhsIntVal), (uint8_t*)(&rhsIntVal) +
sizeof(rhsIntVal));
103 return intVal < rhsIntVal;
159 memcpy(&addr, m_Bytes,
sizeof(m_Bytes));
179 IPv6Address(
const uint8_t bytes[16]) { memcpy(m_Bytes, bytes,
sizeof(m_Bytes)); }
191 const uint8_t*
toBytes()
const {
return m_Bytes; }
237 void copyTo(uint8_t** arr,
size_t& length)
const;
244 void copyTo(uint8_t* arr)
const { memcpy(arr, m_Bytes,
sizeof(m_Bytes)); }
318 IPAddress(
const std::string& addrAsString);
344 std::string
toString()
const {
return (getType() == IPv4AddressType) ? m_IPv4.toString() : m_IPv6.toString(); }
349 bool isValid()
const {
return (getType() == IPv4AddressType) ? m_IPv4.isValid() : m_IPv6.isValid(); }
354 bool isIPv4()
const {
return getType() == IPv4AddressType; }
359 bool isIPv6()
const {
return getType() == IPv6AddressType; }
365 bool isMulticast()
const {
return (getType() == IPv4AddressType) ? m_IPv4.isMulticast() : m_IPv6.isMulticast(); }
412 return rhs.
isIPv4() ? (m_IPv4 == rhs.m_IPv4) :
false;
414 return rhs.
isIPv6() ? m_IPv6 == rhs.m_IPv6 :
false;
423 return rhs.
isIPv4() ? (m_IPv4 < rhs.m_IPv4) :
true;
425 return rhs.
isIPv6() ? m_IPv6 < rhs.m_IPv6 :
false;
430 m_Type = IPv4AddressType;
437 m_Type = IPv6AddressType;
444 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPv4Address& ipv4Address)
450 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPv6Address& ipv6Address)
456 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPAddress& ipAddress)
The main namespace for the PcapPlusPlus lib.
const uint8_t * toBytes() const
Definition: IpAddress.h:191
IPv4Address()
Definition: IpAddress.h:33
IPv4Address(const uint8_t bytes[4])
Definition: IpAddress.h:45
static const IPv6Address MulticastRangeLowerBound
Definition: IpAddress.h:267
AddressType
Definition: IpAddress.h:284
bool isIPv4() const
Definition: IpAddress.h:354
bool isValid() const
Definition: IpAddress.h:81
static const IPv4Address Zero
Definition: IpAddress.h:138
bool operator==(const IPv4Address &rhs) const
Definition: IpAddress.h:88
const uint8_t * toBytes() const
Definition: IpAddress.h:63
bool operator<(const IPAddress &rhs) const
Definition: IpAddress.h:417
bool operator==(const IPAddress &rhs) const
Definition: IpAddress.h:409
static const IPv4Address MulticastRangeLowerBound
Definition: IpAddress.h:146
bool operator!=(const IPAddress &rhs) const
Definition: IpAddress.h:398
bool operator<(const IPv6Address &rhs) const
Definition: IpAddress.h:222
static const IPv6Address Zero
Definition: IpAddress.h:260
IPv4Address(uint32_t addrAsInt)
Definition: IpAddress.h:39
bool isMulticast() const
Definition: IpAddress.h:365
bool isIPv6() const
Definition: IpAddress.h:359
Definition: IpAddress.h:27
Definition: IpAddress.h:167
const IPv6Address & getIPv6() const
Definition: IpAddress.h:377
std::string toString() const
const IPv4Address & getIPv4() const
Definition: IpAddress.h:371
bool isValid() const
Definition: IpAddress.h:349
std::string toString() const
Definition: IpAddress.h:344
IPv6Address()
Definition: IpAddress.h:173
bool operator!=(const IPv4Address &rhs) const
Definition: IpAddress.h:111
void copyTo(uint8_t *arr) const
Definition: IpAddress.h:244
IPAddress()
Definition: IpAddress.h:299
bool operator==(const IPv6Address &rhs) const
Definition: IpAddress.h:215
bool operator<(const IPv4Address &rhs) const
Definition: IpAddress.h:95
bool operator!=(const IPv6Address &rhs) const
Definition: IpAddress.h:229
IPAddress(const IPv6Address &addr)
Definition: IpAddress.h:311
IPv6Address(const uint8_t bytes[16])
Definition: IpAddress.h:179
bool isValid() const
Definition: IpAddress.h:208
IPAddress & operator=(const IPv4Address &addr)
Definition: IpAddress.h:428
Definition: IpAddress.h:278
std::string toString() const
bool matchSubnet(const IPv4Address &subnet, const std::string &subnetMask) const
Definition: IpAddress.h:289
IPAddress(const IPv4Address &addr)
Definition: IpAddress.h:305
AddressType getType() const
Definition: IpAddress.h:338
uint32_t toInt() const
Definition: IpAddress.h:156