PcapPlusPlus  Next
pcpp::IPv4Network Class Reference

#include <IpAddress.h>

Public Member Functions

 IPv4Network (const IPv4Address &address)
 
 IPv4Network (const IPv4Address &address, uint8_t prefixLen)
 
 IPv4Network (const IPv4Address &address, const std::string &netmask)
 
 IPv4Network (const std::string &addressAndNetmask)
 
uint8_t getPrefixLen () const
 
std::string getNetmask () const
 
IPv4Address getNetworkPrefix () const
 
IPv4Address getLowestAddress () const
 
IPv4Address getHighestAddress () const
 
uint64_t getTotalAddressCount () const
 
bool includes (const IPv4Address &address) const
 
bool includes (const IPv4Network &network) const
 
std::string toString () const
 

Detailed Description

A class representing IPv4 network definition

Constructor & Destructor Documentation

◆ IPv4Network() [1/4]

pcpp::IPv4Network::IPv4Network ( const IPv4Address address)
inlineexplicit

A constructor that creates an instance of the class out of an address and a full prefix length, essentially making a network of consisting of only 1 address.

Parameters
addressAn address representing the network prefix.

◆ IPv4Network() [2/4]

pcpp::IPv4Network::IPv4Network ( const IPv4Address address,
uint8_t  prefixLen 
)

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 between 0 and 32 representing the prefix length.
Exceptions
std::invalid_argumentPrefix length is out of acceptable range.

◆ IPv4Network() [3/4]

pcpp::IPv4Network::IPv4Network ( const IPv4Address address,
const std::string &  netmask 
)

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 the format of X.X.X.X, for example: 255.255.0.0. Please notice that netmasks that start with zeros are invalid, for example: 0.0.255.255. The only netmask starting with zeros that is valid is 0.0.0.0.
Exceptions
std::invalid_argumentThe provided netmask is invalid.

◆ IPv4Network() [4/4]

pcpp::IPv4Network::IPv4Network ( const std::string &  addressAndNetmask)

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:
  • X.X.X.X/Y where X.X.X.X is a valid IPv4 address representing the network prefix and Y is a number between 0 and 32 representing the network prefix
  • X.X.X.X/Y.Y.Y.Y where X.X.X.X is a valid IPv4 address representing the network prefix and Y.Y.Y.Y is a valid netmask
Exceptions
std::invalid_argumentThe provided string does not represent a valid address and netmask format.

Member Function Documentation

◆ getHighestAddress()

IPv4Address pcpp::IPv4Network::getHighestAddress ( ) const
Returns
The highest non-reserved IPv4 address in this network, for example: the highest address in 10.10.10.10/16 is 10.10.255.254

◆ getLowestAddress()

IPv4Address pcpp::IPv4Network::getLowestAddress ( ) const
Returns
The lowest non-reserved IPv4 address in this network, for example: the lowest address in 10.10.10.10/16 is 10.10.0.1

◆ getNetmask()

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

◆ getNetworkPrefix()

IPv4Address pcpp::IPv4Network::getNetworkPrefix ( ) const
inline
Returns
The network prefix, for example: the network prefix of 10.10.10.10/16 is 10.10.0.0

◆ getPrefixLen()

uint8_t pcpp::IPv4Network::getPrefixLen ( ) const
Returns
The prefix length, for example: the prefix length of 10.10.10.10/255.0.0.0 is 8

◆ getTotalAddressCount()

uint64_t pcpp::IPv4Network::getTotalAddressCount ( ) const
Returns
The number of addresses in this network including reserved addresses, for example: the number of addresses in 10.10.0.0/24 is 256

◆ includes() [1/2]

bool pcpp::IPv4Network::includes ( const IPv4Address address) const
Parameters
addressAn IPv4 address
Returns
True is the address belongs to the network, false otherwise or if the address isn't valid

◆ includes() [2/2]

bool pcpp::IPv4Network::includes ( const IPv4Network network) const
Parameters
networkAn IPv4 network
Returns
True is the input network is completely included within this network, false otherwise, for example: 10.10.10.10/16 includes 10.10.10.10/24 but doesn't include 10.10.10.10/8

◆ toString()

std::string pcpp::IPv4Network::toString ( ) const
Returns
A string representation of the network in a format of NETWORK_PREFIX/PREFIX_LEN, for example: 192.168.0.0/16