37 memcpy(m_Bytes.data(), &addrAsInt,
sizeof(addrAsInt));
44 memcpy(m_Bytes.data(), bytes, 4 *
sizeof(uint8_t));
49 IPv4Address(
const std::array<uint8_t, 4>& bytes) : m_Bytes(bytes)
58 inline uint32_t
toInt()
const;
63 return m_Bytes.data();
91 uint32_t intVal =
toInt();
92 std::reverse(
reinterpret_cast<uint8_t*
>(&intVal),
reinterpret_cast<uint8_t*
>(&intVal) +
sizeof(intVal));
94 uint32_t rhsIntVal = rhs.
toInt();
95 std::reverse(
reinterpret_cast<uint8_t*
>(&rhsIntVal),
96 reinterpret_cast<uint8_t*
>(&rhsIntVal) +
sizeof(rhsIntVal));
98 return intVal < rhsIntVal;
106 return !(*
this == rhs);
141 std::array<uint8_t, 4> m_Bytes = { 0 };
149 memcpy(&addr, m_Bytes.data(), m_Bytes.size() *
sizeof(uint8_t));
165 memcpy(m_Bytes.data(), bytes, 16 *
sizeof(uint8_t));
170 IPv6Address(
const std::array<uint8_t, 16>& bytes) : m_Bytes(bytes)
182 return m_Bytes.data();
221 return !(*
this == rhs);
227 void copyTo(uint8_t** arr,
size_t& length)
const;
234 memcpy(arr, m_Bytes.data(), m_Bytes.size() *
sizeof(uint8_t));
270 std::array<uint8_t, 16> m_Bytes = { 0 };
384 return !(*
this == rhs);
398 return rhs.
isIPv4() ? (m_IPv4 == rhs.m_IPv4) :
false;
400 return rhs.
isIPv6() ? m_IPv6 == rhs.m_IPv6 :
false;
409 return rhs.
isIPv4() ? (m_IPv4 < rhs.m_IPv4) :
true;
411 return rhs.
isIPv6() ? m_IPv6 < rhs.m_IPv6 :
false;
508 uint32_t m_NetworkPrefix;
511 bool isValidNetmask(
const IPv4Address& netmaskAddress);
512 void initFromAddressAndPrefixLength(
const IPv4Address& address, uint8_t prefixLen);
596 uint8_t m_NetworkPrefix[16];
599 bool isValidNetmask(
const IPv6Address& netmaskAddress);
600 void initFromAddressAndPrefixLength(
const IPv6Address& address, uint8_t prefixLen);
626 m_IPv4Network = std::unique_ptr<IPv4Network>(
new IPv4Network(address.
getIPv4(), prefixLen));
630 m_IPv6Network = std::unique_ptr<IPv6Network>(
new IPv6Network(address.
getIPv6(), prefixLen));
647 m_IPv4Network = std::unique_ptr<IPv4Network>(
new IPv4Network(address.
getIPv4(), netmask));
651 m_IPv6Network = std::unique_ptr<IPv6Network>(
new IPv6Network(address.
getIPv6(), netmask));
667 m_IPv4Network = std::unique_ptr<IPv4Network>(
new IPv4Network(addressAndNetmask));
669 catch (
const std::invalid_argument&)
671 m_IPv6Network = std::unique_ptr<IPv6Network>(
new IPv6Network(addressAndNetmask));
679 if (other.m_IPv4Network)
681 m_IPv4Network = std::unique_ptr<IPv4Network>(
new IPv4Network(*other.m_IPv4Network));
684 if (other.m_IPv6Network)
686 m_IPv6Network = std::unique_ptr<IPv6Network>(
new IPv6Network(*other.m_IPv6Network));
697 return this->
operator=(*other.m_IPv4Network);
701 return this->
operator=(*other.m_IPv6Network);
711 m_IPv4Network = std::unique_ptr<IPv4Network>(
new IPv4Network(other));
712 m_IPv6Network =
nullptr;
722 m_IPv6Network = std::unique_ptr<IPv6Network>(
new IPv6Network(other));
723 m_IPv4Network =
nullptr;
731 return (m_IPv4Network !=
nullptr ? m_IPv4Network->getPrefixLen() : m_IPv6Network->getPrefixLen());
738 return (m_IPv4Network !=
nullptr ? m_IPv4Network->getNetmask() : m_IPv6Network->getNetmask());
745 return (m_IPv4Network !=
nullptr ?
IPAddress(m_IPv4Network->getNetworkPrefix())
746 :
IPAddress(m_IPv6Network->getNetworkPrefix()));
753 return (m_IPv4Network !=
nullptr ?
IPAddress(m_IPv4Network->getLowestAddress())
754 :
IPAddress(m_IPv6Network->getLowestAddress()));
761 return (m_IPv4Network !=
nullptr ?
IPAddress(m_IPv4Network->getHighestAddress())
762 :
IPAddress(m_IPv6Network->getHighestAddress()));
770 return (m_IPv4Network !=
nullptr ? m_IPv4Network->getTotalAddressCount()
771 : m_IPv6Network->getTotalAddressCount());
777 return m_IPv4Network !=
nullptr;
783 return m_IPv6Network !=
nullptr;
790 if (m_IPv4Network !=
nullptr)
797 return m_IPv4Network->includes(address.
getIPv4());
806 return m_IPv6Network->includes(address.
getIPv6());
814 if (m_IPv4Network !=
nullptr)
821 return m_IPv4Network->includes(*network.m_IPv4Network);
830 return m_IPv6Network->includes(*network.m_IPv6Network);
838 return (m_IPv4Network !=
nullptr ? m_IPv4Network->toString() : m_IPv6Network->toString());
842 std::unique_ptr<IPv4Network> m_IPv4Network;
843 std::unique_ptr<IPv6Network> m_IPv6Network;
846 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPv4Address& ipv4Address)
852 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPv6Address& ipv6Address)
858 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPAddress& ipAddress)
864 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPv4Network& network)
870 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPv6Network& network)
876 inline std::ostream& operator<<(std::ostream& os,
const pcpp::IPNetwork& network)
Definition: IpAddress.h:276
IPAddress()
A default constructor that creates an instance of the class with unspecified IPv4 address.
Definition: IpAddress.h:288
std::string toString() const
Definition: IpAddress.h:325
const IPv4Address & getIPv4() const
Definition: IpAddress.h:351
bool operator!=(const IPAddress &rhs) const
Definition: IpAddress.h:382
const IPv6Address & getIPv6() const
Definition: IpAddress.h:358
IPAddress(const std::string &addrAsString)
IPAddress(const IPv4Address &addr)
Definition: IpAddress.h:293
AddressType getType() const
Definition: IpAddress.h:318
bool operator<(const IPAddress &rhs) const
Definition: IpAddress.h:403
bool isIPv4() const
Definition: IpAddress.h:331
bool isZero() const
Definition: IpAddress.h:364
AddressType
An enum representing the address type: IPv4 or IPv6.
Definition: IpAddress.h:280
@ IPv6AddressType
IPv6 address type.
Definition: IpAddress.h:284
@ IPv4AddressType
IPv4 address type.
Definition: IpAddress.h:282
IPAddress & operator=(const IPv4Address &addr)
Definition: IpAddress.h:414
bool isIPv6() const
Definition: IpAddress.h:337
bool isMulticast() const
Definition: IpAddress.h:344
bool operator==(const IPAddress &rhs) const
Definition: IpAddress.h:395
IPAddress(const IPv6Address &addr)
Definition: IpAddress.h:298
Definition: IpAddress.h:607
IPAddress getHighestAddress() const
Definition: IpAddress.h:759
IPNetwork & operator=(const IPv6Network &other)
Definition: IpAddress.h:719
IPAddress getLowestAddress() const
Definition: IpAddress.h:751
bool includes(const IPAddress &address) const
Definition: IpAddress.h:788
bool isIPv6Network() const
Definition: IpAddress.h:781
bool includes(const IPNetwork &network) const
Definition: IpAddress.h:812
std::string toString() const
Definition: IpAddress.h:836
bool isIPv4Network() const
Definition: IpAddress.h:775
IPNetwork & operator=(const IPNetwork &other)
Definition: IpAddress.h:693
IPNetwork(const IPNetwork &other)
Definition: IpAddress.h:677
IPAddress getNetworkPrefix() const
Definition: IpAddress.h:743
IPNetwork(const IPAddress &address, const std::string &netmask)
Definition: IpAddress.h:643
uint64_t getTotalAddressCount() const
Definition: IpAddress.h:768
std::string getNetmask() const
Definition: IpAddress.h:736
uint8_t getPrefixLen() const
Definition: IpAddress.h:729
IPNetwork & operator=(const IPv4Network &other)
Definition: IpAddress.h:708
IPNetwork(const IPAddress &address)
Definition: IpAddress.h:612
IPNetwork(const std::string &addressAndNetmask)
Definition: IpAddress.h:663
IPNetwork(const IPAddress &address, uint8_t prefixLen)
Definition: IpAddress.h:622
Definition: IpAddress.h:28
static bool isValidIPv4Address(const std::string &addrAsString)
bool matchNetwork(const std::string &network) const
static const IPv4Address MulticastRangeLowerBound
Definition: IpAddress.h:137
IPv4Address(const std::array< uint8_t, 4 > &bytes)
Definition: IpAddress.h:49
bool matchNetwork(const IPv4Network &network) const
IPv4Address()=default
A default constructor that creates an instance of the class with the zero-initialized address.
std::string toString() const
IPv4Address(const std::string &addrAsString)
const uint8_t * toBytes() const
Definition: IpAddress.h:61
bool operator!=(const IPv4Address &rhs) const
Definition: IpAddress.h:104
IPv4Address(const uint32_t addrAsInt)
Definition: IpAddress.h:35
IPv4Address(const uint8_t bytes[4])
Definition: IpAddress.h:42
bool operator==(const IPv4Address &rhs) const
Definition: IpAddress.h:81
bool operator<(const IPv4Address &rhs) const
Definition: IpAddress.h:89
const std::array< uint8_t, 4 > & toByteArray() const
Definition: IpAddress.h:67
uint32_t toInt() const
Definition: IpAddress.h:146
static const IPv4Address Zero
A static value representing a zero value of IPv4 address, meaning address of value "0....
Definition: IpAddress.h:131
Definition: IpAddress.h:431
IPv4Network(const IPv4Address &address)
Definition: IpAddress.h:436
IPv4Address getLowestAddress() const
std::string getNetmask() const
Definition: IpAddress.h:471
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:477
IPv4Network(const std::string &addressAndNetmask)
bool includes(const IPv4Network &network) const
Definition: IpAddress.h:156
static const IPv6Address MulticastRangeLowerBound
Definition: IpAddress.h:267
void copyTo(uint8_t *arr) const
Definition: IpAddress.h:232
void copyTo(uint8_t **arr, size_t &length) const
const uint8_t * toBytes() const
Definition: IpAddress.h:180
bool matchNetwork(const IPv6Network &network) const
IPv6Address(const uint8_t bytes[16])
Definition: IpAddress.h:163
static const IPv6Address Zero
Definition: IpAddress.h:262
bool matchNetwork(const std::string &network) const
bool operator<(const IPv6Address &rhs) const
Definition: IpAddress.h:211
bool operator!=(const IPv6Address &rhs) const
Definition: IpAddress.h:219
const std::array< uint8_t, 16 > & toByteArray() const
Definition: IpAddress.h:187
IPv6Address(const std::string &addrAsString)
IPv6Address()=default
A default constructor that creates an instance of the class with the zero-initialized address.
static bool isValidIPv6Address(const std::string &addrAsString)
std::string toString() const
bool operator==(const IPv6Address &rhs) const
Definition: IpAddress.h:203
IPv6Address(const std::array< uint8_t, 16 > &bytes)
Definition: IpAddress.h:170
Definition: IpAddress.h:519
IPv6Network(const std::string &addressAndNetmask)
IPv6Address getHighestAddress() const
uint8_t getPrefixLen() const
std::string getNetmask() const
Definition: IpAddress.h:559
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:565
std::string toString() const
bool includes(const IPv6Address &address) const
IPv6Network(const IPv6Address &address)
Definition: IpAddress.h:524
The main namespace for the PcapPlusPlus lib.