45 memcpy(m_Bytes.data(), &addrAsInt,
sizeof(addrAsInt));
54 memcpy(m_Bytes.data(), bytes, 4 *
sizeof(uint8_t));
61 IPv4Address(
const std::array<uint8_t, 4>& bytes) : m_Bytes(bytes)
75 inline uint32_t
toInt()
const;
82 return m_Bytes.data();
120 uint32_t intVal =
toInt();
121 std::reverse(
reinterpret_cast<uint8_t*
>(&intVal),
reinterpret_cast<uint8_t*
>(&intVal) +
sizeof(intVal));
123 uint32_t rhsIntVal = rhs.
toInt();
124 std::reverse(
reinterpret_cast<uint8_t*
>(&rhsIntVal),
125 reinterpret_cast<uint8_t*
>(&rhsIntVal) +
sizeof(rhsIntVal));
127 return intVal < rhsIntVal;
137 return !(*
this == rhs);
182 std::array<uint8_t, 4> m_Bytes = { 0 };
190 memcpy(&addr, m_Bytes.data(), m_Bytes.size() *
sizeof(uint8_t));
212 memcpy(m_Bytes.data(), bytes, 16 *
sizeof(uint8_t));
219 IPv6Address(
const std::array<uint8_t, 16>& bytes) : m_Bytes(bytes)
236 return m_Bytes.data();
287 return !(*
this == rhs);
295 void copyTo(uint8_t** arr,
size_t& length)
const;
304 memcpy(arr, m_Bytes.data(), m_Bytes.size() *
sizeof(uint8_t));
350 std::array<uint8_t, 16> m_Bytes = { 0 };
507 return !(*
this == rhs);
521 return rhs.
isIPv4() ? (m_IPv4 == rhs.m_IPv4) :
false;
523 return rhs.
isIPv6() ? m_IPv6 == rhs.m_IPv6 :
false;
532 return rhs.
isIPv4() ? (m_IPv4 < rhs.m_IPv4) :
true;
534 return rhs.
isIPv6() ? m_IPv6 < rhs.m_IPv6 :
false;
660 uint32_t m_NetworkPrefix;
663 bool isValidNetmask(
const IPv4Address& netmaskAddress);
664 void initFromAddressAndPrefixLength(
const IPv4Address& address, uint8_t prefixLen);
777 uint8_t m_NetworkPrefix[16];
780 bool isValidNetmask(
const IPv6Address& netmaskAddress);
781 void initFromAddressAndPrefixLength(
const IPv6Address& address, uint8_t prefixLen);
814 m_IPv4Network = std::unique_ptr<IPv4Network>(
new IPv4Network(address.
getIPv4(), prefixLen));
818 m_IPv6Network = std::unique_ptr<IPv6Network>(
new IPv6Network(address.
getIPv6(), prefixLen));
837 m_IPv4Network = std::unique_ptr<IPv4Network>(
new IPv4Network(address.
getIPv4(), netmask));
841 m_IPv6Network = std::unique_ptr<IPv6Network>(
new IPv6Network(address.
getIPv6(), netmask));
859 m_IPv4Network = std::unique_ptr<IPv4Network>(
new IPv4Network(addressAndNetmask));
861 catch (
const std::invalid_argument&)
863 m_IPv6Network = std::unique_ptr<IPv6Network>(
new IPv6Network(addressAndNetmask));
873 if (other.m_IPv4Network)
875 m_IPv4Network = std::unique_ptr<IPv4Network>(
new IPv4Network(*other.m_IPv4Network));
878 if (other.m_IPv6Network)
880 m_IPv6Network = std::unique_ptr<IPv6Network>(
new IPv6Network(*other.m_IPv6Network));
893 return this->
operator=(*other.m_IPv4Network);
897 return this->
operator=(*other.m_IPv6Network);
910 m_IPv4Network =
nullptr;
915 m_IPv6Network =
nullptr;
918 m_IPv4Network = std::unique_ptr<IPv4Network>(
new IPv4Network(other));
932 m_IPv4Network =
nullptr;
937 m_IPv6Network =
nullptr;
940 m_IPv6Network = std::unique_ptr<IPv6Network>(
new IPv6Network(other));
951 return (m_IPv4Network !=
nullptr ? m_IPv4Network->getPrefixLen() : m_IPv6Network->getPrefixLen());
960 return (m_IPv4Network !=
nullptr ? m_IPv4Network->getNetmask() : m_IPv6Network->getNetmask());
969 return (m_IPv4Network !=
nullptr ?
IPAddress(m_IPv4Network->getNetworkPrefix())
970 :
IPAddress(m_IPv6Network->getNetworkPrefix()));
979 return (m_IPv4Network !=
nullptr ?
IPAddress(m_IPv4Network->getLowestAddress())
980 :
IPAddress(m_IPv6Network->getLowestAddress()));
989 return (m_IPv4Network !=
nullptr ?
IPAddress(m_IPv4Network->getHighestAddress())
990 :
IPAddress(m_IPv6Network->getHighestAddress()));
1000 return (m_IPv4Network !=
nullptr ? m_IPv4Network->getTotalAddressCount()
1001 : m_IPv6Network->getTotalAddressCount());
1009 return m_IPv4Network !=
nullptr;
1017 return m_IPv6Network !=
nullptr;
1026 if (m_IPv4Network !=
nullptr)
1033 return m_IPv4Network->includes(address.
getIPv4());
1042 return m_IPv6Network->includes(address.
getIPv6());
1052 if (m_IPv4Network !=
nullptr)
1059 return m_IPv4Network->includes(*network.m_IPv4Network);
1068 return m_IPv6Network->includes(*network.m_IPv6Network);
1078 return (m_IPv4Network !=
nullptr ? m_IPv4Network->toString() : m_IPv6Network->toString());
1082 std::unique_ptr<IPv4Network> m_IPv4Network;
1083 std::unique_ptr<IPv6Network> m_IPv6Network;
1087 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPv4Address& ipv4Address)
1093 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPv6Address& ipv6Address)
1099 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPAddress& ipAddress)
1105 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPv4Network& network)
1111 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPv6Network& network)
1117 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPNetwork& network)
Definition: IpAddress.h:358
IPAddress()
Definition: IpAddress.h:378
std::string toString() const
Definition: IpAddress.h:430
const IPv4Address & getIPv4() const
Definition: IpAddress.h:464
bool operator!=(const IPAddress &rhs) const
Definition: IpAddress.h:505
const IPv6Address & getIPv6() const
Definition: IpAddress.h:473
IPAddress(const std::string &addrAsString)
IPAddress(const IPv4Address &addr)
Definition: IpAddress.h:385
AddressType getType() const
Definition: IpAddress.h:421
bool operator<(const IPAddress &rhs) const
Definition: IpAddress.h:526
bool isIPv4() const
Definition: IpAddress.h:438
bool isZero() const
Definition: IpAddress.h:481
AddressType
Definition: IpAddress.h:364
@ IPv6AddressType
Definition: IpAddress.h:372
@ IPv4AddressType
Definition: IpAddress.h:368
IPAddress & operator=(const IPv4Address &addr)
Definition: IpAddress.h:537
bool isIPv6() const
Definition: IpAddress.h:446
bool isMulticast() const
Definition: IpAddress.h:455
bool operator==(const IPAddress &rhs) const
Definition: IpAddress.h:518
IPAddress(const IPv6Address &addr)
Definition: IpAddress.h:392
Definition: IpAddress.h:790
IPAddress getHighestAddress() const
Definition: IpAddress.h:987
IPNetwork & operator=(const IPv6Network &other)
Definition: IpAddress.h:928
IPAddress getLowestAddress() const
Definition: IpAddress.h:977
bool includes(const IPAddress &address) const
Definition: IpAddress.h:1024
bool isIPv6Network() const
Definition: IpAddress.h:1015
bool includes(const IPNetwork &network) const
Definition: IpAddress.h:1050
std::string toString() const
Definition: IpAddress.h:1076
bool isIPv4Network() const
Definition: IpAddress.h:1007
IPNetwork & operator=(const IPNetwork &other)
Definition: IpAddress.h:889
IPNetwork(const IPNetwork &other)
Definition: IpAddress.h:871
IPAddress getNetworkPrefix() const
Definition: IpAddress.h:967
IPNetwork(const IPAddress &address, const std::string &netmask)
Definition: IpAddress.h:833
uint64_t getTotalAddressCount() const
Definition: IpAddress.h:998
std::string getNetmask() const
Definition: IpAddress.h:958
uint8_t getPrefixLen() const
Definition: IpAddress.h:949
IPNetwork & operator=(const IPv4Network &other)
Definition: IpAddress.h:906
IPNetwork(const IPAddress &address)
Definition: IpAddress.h:798
IPNetwork(const std::string &addressAndNetmask)
Definition: IpAddress.h:855
IPNetwork(const IPAddress &address, uint8_t prefixLen)
Definition: IpAddress.h:810
Definition: IpAddress.h:32
static bool isValidIPv4Address(const std::string &addrAsString)
bool matchNetwork(const std::string &network) const
static const IPv4Address MulticastRangeLowerBound
Definition: IpAddress.h:178
IPv4Address(const std::array< uint8_t, 4 > &bytes)
Definition: IpAddress.h:61
bool matchNetwork(const IPv4Network &network) const
std::string toString() const
IPv4Address(const std::string &addrAsString)
const uint8_t * toBytes() const
Definition: IpAddress.h:80
bool operator!=(const IPv4Address &rhs) const
Definition: IpAddress.h:135
IPv4Address(const uint32_t addrAsInt)
Definition: IpAddress.h:43
IPv4Address(const uint8_t bytes[4])
Definition: IpAddress.h:52
bool operator==(const IPv4Address &rhs) const
Definition: IpAddress.h:108
bool operator<(const IPv4Address &rhs) const
Definition: IpAddress.h:118
const std::array< uint8_t, 4 > & toByteArray() const
Definition: IpAddress.h:88
uint32_t toInt() const
Definition: IpAddress.h:187
static const IPv4Address Zero
Definition: IpAddress.h:170
Definition: IpAddress.h:556
IPv4Network(const IPv4Address &address)
Definition: IpAddress.h:564
IPv4Address getLowestAddress() const
std::string getNetmask() const
Definition: IpAddress.h:609
IPv4Network(const IPv4Address &address, const std::string &netmask)
IPv4Address getHighestAddress() const
std::string toString() const
uint8_t getPrefixLen() const
bool includes(const IPv4Address &address) const
uint64_t getTotalAddressCount() const
IPv4Network(const IPv4Address &address, uint8_t prefixLen)
IPv4Address getNetworkPrefix() const
Definition: IpAddress.h:617
IPv4Network(const std::string &addressAndNetmask)
bool includes(const IPv4Network &network) const
Definition: IpAddress.h:199
static const IPv6Address MulticastRangeLowerBound
Definition: IpAddress.h:347
void copyTo(uint8_t *arr) const
Definition: IpAddress.h:302
void copyTo(uint8_t **arr, size_t &length) const
const uint8_t * toBytes() const
Definition: IpAddress.h:234
bool matchNetwork(const IPv6Network &network) const
IPv6Address(const uint8_t bytes[16])
Definition: IpAddress.h:210
static const IPv6Address Zero
Definition: IpAddress.h:340
bool matchNetwork(const std::string &network) const
bool operator<(const IPv6Address &rhs) const
Definition: IpAddress.h:275
bool operator!=(const IPv6Address &rhs) const
Definition: IpAddress.h:285
const std::array< uint8_t, 16 > & toByteArray() const
Definition: IpAddress.h:243
IPv6Address(const std::string &addrAsString)
static bool isValidIPv6Address(const std::string &addrAsString)
std::string toString() const
bool operator==(const IPv6Address &rhs) const
Definition: IpAddress.h:265
IPv6Address(const std::array< uint8_t, 16 > &bytes)
Definition: IpAddress.h:219
Definition: IpAddress.h:673
IPv6Network(const std::string &addressAndNetmask)
IPv6Address getHighestAddress() const
uint8_t getPrefixLen() const
std::string getNetmask() const
Definition: IpAddress.h:726
bool includes(const IPv6Network &network) const
IPv6Address getLowestAddress() const
IPv6Network(const IPv6Address &address, const std::string &netmask)
IPv6Network(const IPv6Address &address, uint8_t prefixLen)
uint64_t getTotalAddressCount() const
IPv6Address getNetworkPrefix() const
Definition: IpAddress.h:734
std::string toString() const
bool includes(const IPv6Address &address) const
IPv6Network(const IPv6Address &address)
Definition: IpAddress.h:681
The main namespace for the PcapPlusPlus lib.