PcapPlusPlus  Next
pcpp::IPv6Network Class Reference

#include <IpAddress.h>

Public Member Functions

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

Detailed Description

A class representing IPv6 network definition

Constructor & Destructor Documentation

◆ IPv6Network() [1/4]

pcpp::IPv6Network::IPv6Network ( const IPv6Address 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.

◆ IPv6Network() [2/4]

pcpp::IPv6Network::IPv6Network ( const IPv6Address 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 128 representing the prefix length.
Exceptions
std::invalid_argumentPrefix length is out of acceptable range.

◆ IPv6Network() [3/4]

pcpp::IPv6Network::IPv6Network ( const IPv6Address 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 valid IPv6 format, for example: ffff:ffff::. Please notice that netmasks that start with zeros are invalid, for example: 0:ffff::. The only netmask starting with zeros that is valid is all zeros (::).
Exceptions
std::invalid_argumentThe provided netmask is invalid.

◆ IPv6Network() [4/4]

pcpp::IPv6Network::IPv6Network ( 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:
  • IPV6_ADDRESS/Y where IPV6_ADDRESS is a valid IPv6 address representing the network prefix and Y is a number between 0 and 128 representing the network prefix
  • IPV6_ADDRESS/IPV6_NETMASK where IPV6_ADDRESS is a valid IPv6 address representing the network prefix and IPV6_NETMASK is a valid IPv6 netmask
Exceptions
std::invalid_argumentThe provided string does not represent a valid address and netmask format.

Member Function Documentation

◆ getHighestAddress()

IPv6Address pcpp::IPv6Network::getHighestAddress ( ) const
Returns
The highest IPv6 address in this network, for example: the highest address in 3546::/16 is 3546:ffff:ffff:ffff:ffff:ffff:ffff:ffff

◆ getLowestAddress()

IPv6Address pcpp::IPv6Network::getLowestAddress ( ) const
Returns
The lowest non-reserved IPv6 address in this network, for example: the lowest address in 3546::/16 is 3546::1

◆ getNetmask()

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

◆ getNetworkPrefix()

IPv6Address pcpp::IPv6Network::getNetworkPrefix ( ) const
inline
Returns
The network prefix, for example: the network prefix of 3546:f321::/16 is 3546::

◆ getPrefixLen()

uint8_t pcpp::IPv6Network::getPrefixLen ( ) const
Returns
The prefix length, for example: the prefix length of 3546::/ffff:: is 16

◆ getTotalAddressCount()

uint64_t pcpp::IPv6Network::getTotalAddressCount ( ) const
Returns
The number of addresses in this network, for example: the number of addresses in 16ff::/120 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::IPv6Network::includes ( const IPv6Address address) const
Parameters
addressAn IPv6 address
Returns
True is the address belongs to the network, false otherwise or if the address isn't valid

◆ includes() [2/2]

bool pcpp::IPv6Network::includes ( const IPv6Network network) const
Parameters
networkAn IPv6 network
Returns
True is the input network is completely included within this network, false otherwise, for example: 3546::/64 includes 3546::/120 but doesn't include 3546::/16

◆ toString()

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