PcapPlusPlus  23.09
pcpp::IPNetwork Class Reference

#include <IpAddress.h>

Public Member Functions

 IPNetwork (const IPAddress &address, uint8_t prefixLen)
 
 IPNetwork (const IPAddress &address, const std::string &netmask)
 
 IPNetwork (const std::string &addressAndNetmask)
 
 IPNetwork (const IPNetwork &other)
 
 ~IPNetwork ()
 
IPNetworkoperator= (const IPNetwork &other)
 
IPNetworkoperator= (const IPv4Network &other)
 
IPNetworkoperator= (const IPv6Network &other)
 
uint8_t getPrefixLen () const
 
std::string getNetmask () const
 
IPAddress getNetworkPrefix () const
 
IPAddress getLowestAddress () const
 
IPAddress getHighestAddress () const
 
uint64_t getTotalAddressCount () const
 
bool isIPv4Network () const
 
bool isIPv6Network () const
 
bool includes (const IPAddress &address) const
 
bool includes (const IPNetwork &network) const
 
std::string toString () const
 

Detailed Description

A class representing version independent IP network definition, both IPv4 and IPv6 are included

Constructor & Destructor Documentation

◆ IPNetwork() [1/4]

pcpp::IPNetwork::IPNetwork ( const IPAddress address,
uint8_t  prefixLen 
)
inline

A constructor that creates an instance of the class out of an address representing the network prefix and a prefix length

Parameters
addressAn address representing the network prefix. If the address is invalid std::invalid_argument exception is thrown
prefixLenA number representing the prefix length. If the value isn't in the range allowed for the network (0 - 32 for IPv4 networks or 0 - 128 for IPv6 networks) and std::invalid_argument exception is thrown

◆ IPNetwork() [2/4]

pcpp::IPNetwork::IPNetwork ( const IPAddress address,
const std::string &  netmask 
)
inline

A constructor that creates an instance of the class out of an address representing the network prefix and a netmask

Parameters
addressAn address representing the network prefix. If the address is invalid std::invalid_argument exception is thrown
netmaskA string representing a netmask in valid format, for example: ffff:ffff:: for IPv6 networks or 255.255.0.0 for IPv4 networks. Please notice that netmasks that start with zeros are invalid, for example: 0:ffff:: or 0.255.255.255. The only netmask starting with zeros that is valid is all zeros (:: or 0.0.0.0). If the netmask is invalid std::invalid_argument exception is thrown

◆ IPNetwork() [3/4]

pcpp::IPNetwork::IPNetwork ( const std::string &  addressAndNetmask)
inline

A constructor that creates an instance of the class out of a string representing the network prefix and a prefix length or a netmask

Parameters
addressAndNetmaskA string in one of these formats:
  • IP_ADDRESS/Y where IP_ADDRESS is a valid IP address representing the network prefix and Y is a number representing the network prefix
  • IP_ADDRESS/NETMASK where IP_ADDRESS is a valid IP address representing the network prefix and NETMASK is a valid netmask for this type of network (IPv4 or IPv6 network) For any invalid value std::invalid_argument is thrown

◆ IPNetwork() [4/4]

pcpp::IPNetwork::IPNetwork ( const IPNetwork other)
inline

A copy c'tor for this class

Parameters
otherThe instance to copy from

◆ ~IPNetwork()

pcpp::IPNetwork::~IPNetwork ( )
inline

A destructor for this class

Member Function Documentation

◆ getHighestAddress()

IPAddress pcpp::IPNetwork::getHighestAddress ( ) const
inline
Returns
The highest non-reserved IP address in this network, for example: the highest address in 3546::/16 is 3546:ffff:ffff:ffff:ffff:ffff:ffff:ffff, the highest address in 10.10.10.10/16 is 10.10.255.254

◆ getLowestAddress()

IPAddress pcpp::IPNetwork::getLowestAddress ( ) const
inline
Returns
The lowest non-reserved IP address in this network, for example: the lowest address in 3546::/16 is 3546::1, the lowest address in 10.10.10.10/16 is 10.10.0.1

◆ getNetmask()

std::string pcpp::IPNetwork::getNetmask ( ) const
inline
Returns
The netmask, for example: the netmask of 3546::/16 is ffff::, the netmask of 10.10.10.10/8 is 255.0.0.0

◆ getNetworkPrefix()

IPAddress pcpp::IPNetwork::getNetworkPrefix ( ) const
inline
Returns
The network prefix, for example: the network prefix of 3546:f321::/16 is 3546::, the network prefix of 10.10.10.10/16 is 10.10.0.0

◆ getPrefixLen()

uint8_t pcpp::IPNetwork::getPrefixLen ( ) const
inline
Returns
The prefix length, for example: the prefix length of 3546::/ffff:: is 16, the prefix length of 10.10.10.10/255.0.0.0 is 8

◆ getTotalAddressCount()

uint64_t pcpp::IPNetwork::getTotalAddressCount ( ) const
inline
Returns
The number of addresses in this network, for example: the number of addresses in 16ff::/120 is 256, the number of addresses in 10.10.0.0/24 is 256. If the number of addresses exceeds the size of uint64_t a std::out_of_range exception is thrown

◆ includes() [1/2]

bool pcpp::IPNetwork::includes ( const IPAddress address) const
inline
Parameters
addressAn IP address
Returns
True is the address belongs to the network, false otherwise or if the address isn't valid

◆ includes() [2/2]

bool pcpp::IPNetwork::includes ( const IPNetwork network) const
inline
Parameters
networkAn IP network
Returns
True is the input network is completely included within this network, false otherwise

◆ isIPv4Network()

bool pcpp::IPNetwork::isIPv4Network ( ) const
inline
Returns
True if this is an IPv4 network, false otherwise

◆ isIPv6Network()

bool pcpp::IPNetwork::isIPv6Network ( ) const
inline
Returns
True if this is an IPv6 network, false otherwise

◆ operator=() [1/3]

IPNetwork& pcpp::IPNetwork::operator= ( const IPNetwork other)
inline

Overload of an assignment operator.

Parameters
[in]otherAn instance of IPNetwork to assign
Returns
A reference to the assignee

◆ operator=() [2/3]

IPNetwork& pcpp::IPNetwork::operator= ( const IPv4Network other)
inline

Overload of an assignment operator.

Parameters
[in]otherAn instance of IPv4Network to assign
Returns
A reference to the assignee

◆ operator=() [3/3]

IPNetwork& pcpp::IPNetwork::operator= ( const IPv6Network other)
inline

Overload of an assignment operator.

Parameters
[in]otherAn instance of IPv6Network to assign
Returns
A reference to the assignee

◆ toString()

std::string pcpp::IPNetwork::toString ( ) const
inline
Returns
A string representation of the network in a format of NETWORK_PREFIX/PREFIX_LEN, for example: fda7:9f81:6c23:275::/64 or 192.168.0.0/16