PcapPlusPlus  21.05
pcpp::IPv4Address Class Reference

#include <IpAddress.h>

Public Member Functions

 IPv4Address ()
 
 IPv4Address (uint32_t addrAsInt)
 
 IPv4Address (const uint8_t bytes[4])
 
 IPv4Address (const std::string &addrAsString)
 
uint32_t toInt () const
 
const uint8_t * toBytes () const
 
std::string toString () const
 
bool isMulticast () const
 
bool isValid () const
 
bool operator== (const IPv4Address &rhs) const
 
bool operator< (const IPv4Address &rhs) const
 
bool operator!= (const IPv4Address &rhs) const
 
bool matchSubnet (const IPv4Address &subnet, const std::string &subnetMask) const
 
bool matchSubnet (const IPv4Address &subnet, const IPv4Address &subnetMask) const
 

Static Public Attributes

static const IPv4Address Zero
 
static const IPv4Address MulticastRangeLowerBound
 

Detailed Description

Represents an IPv4 address (of type XXX.XXX.XXX.XXX)

Constructor & Destructor Documentation

◆ IPv4Address() [1/4]

pcpp::IPv4Address::IPv4Address ( )
inline

A default constructor that creates an instance of the class with unspecified/zero address

◆ IPv4Address() [2/4]

pcpp::IPv4Address::IPv4Address ( uint32_t  addrAsInt)
inline

A constructor that creates an instance of the class out of 4-byte integer value.

Parameters
[in]addrAsIntThe address as 4-byte integer in network byte order

◆ IPv4Address() [3/4]

pcpp::IPv4Address::IPv4Address ( const uint8_t  bytes[4])
inline

A constructor that creates an instance of the class out of 4-byte array.

Parameters
[in]bytesThe address as 4-byte array in network byte order

◆ IPv4Address() [4/4]

pcpp::IPv4Address::IPv4Address ( const std::string &  addrAsString)

A constructor that creates an instance of the class out of std::string value If the string doesn't represent a valid IPv4 address, an instance will store an unspecified address

Parameters
[in]addrAsStringThe std::string representation of the address

Member Function Documentation

◆ isMulticast()

bool pcpp::IPv4Address::isMulticast ( ) const

Determine whether the address is a multicast address

Returns
True if an address is multicast

◆ isValid()

bool pcpp::IPv4Address::isValid ( ) const
inline

Determine whether the address is valid (it's not an unspecified/zero)

Returns
True if an address is not unspecified/zero

◆ matchSubnet() [1/2]

bool pcpp::IPv4Address::matchSubnet ( const IPv4Address subnet,
const std::string &  subnetMask 
) const

Checks whether the address matches a subnet. For example: if subnet is 10.1.1.X, subnet mask is 255.255.255.0 and address is 10.1.1.9 then the method will return true Another example: if subnet is 10.1.X.X, subnet mask is 255.0.0.0 and address is 11.1.1.9 then the method will return false

Parameters
[in]subnetThe subnet to be verified. Notice it's an IPv4Address type, so subnets with don't-cares (like 10.0.0.X) must have some number (it'll be ignored if subnet mask is correct)
[in]subnetMaskA string representing the subnet mask to compare the address with the subnet

◆ matchSubnet() [2/2]

bool pcpp::IPv4Address::matchSubnet ( const IPv4Address subnet,
const IPv4Address subnetMask 
) const

Checks whether the address matches a subnet. For example: if subnet is 10.1.1.X, subnet mask is 255.255.255.0 and address is 10.1.1.9 then the method will return true Another example: if subnet is 10.1.X.X, subnet mask is 255.0.0.0 and address is 11.1.1.9 then the method will return false

Parameters
[in]subnetThe subnet to be verified. Notice it's an IPv4Address type, so subnets with don't-cares (like 10.0.0.X) must have some number (it'll be ignored if subnet mask is correct)
[in]subnetMaskThe subnet mask to compare the address with the subnet

◆ operator!=()

bool pcpp::IPv4Address::operator!= ( const IPv4Address rhs) const
inline

Overload of the not-equal-to operator

◆ operator<()

bool pcpp::IPv4Address::operator< ( const IPv4Address rhs) const
inline

Overload of the less-than operator

◆ operator==()

bool pcpp::IPv4Address::operator== ( const IPv4Address rhs) const
inline

Overload of the equal-to operator

◆ toBytes()

const uint8_t* pcpp::IPv4Address::toBytes ( ) const
inline

Returns a pointer to 4-byte array representing the IPv4 address

◆ toInt()

uint32_t pcpp::IPv4Address::toInt ( ) const
inline

Converts the IPv4 address into a 4B integer

Returns
a 4B integer in network byte order representing the IPv4 address

◆ toString()

std::string pcpp::IPv4Address::toString ( ) const

Returns a std::string representation of the address

Returns
A string representation of the address

Member Data Documentation

◆ MulticastRangeLowerBound

const IPv4Address pcpp::IPv4Address::MulticastRangeLowerBound
static

A static values representing the lower and upper bound of IPv4 multicast ranges. The bounds are inclusive. MulticastRangeLowerBound is initialized to "224.0.0.0". MulticastRangeUpperBound is initialized to "239.255.255.255". In order to check whether the address is a multicast address the isMulticast method can be used.

◆ Zero

const IPv4Address pcpp::IPv4Address::Zero
static

A static value representing a zero value of IPv4 address, meaning address of value "0.0.0.0" Notice this value can be omitted in the user code because the default constructor creates an instance with an unspecified/zero address. In order to check whether the address is zero the method isValid can be used