PcapPlusPlus  Next
pcpp::IPv4Address Class Reference

#include <IpAddress.h>

Public Member Functions

 IPv4Address ()=default
 
 IPv4Address (const uint32_t addrAsInt)
 
 IPv4Address (const uint8_t bytes[4])
 
 IPv4Address (const std::array< uint8_t, 4 > &bytes)
 
 IPv4Address (const std::string &addrAsString)
 
uint32_t toInt () const
 
const uint8_t * toBytes () const
 
const std::array< uint8_t, 4 > & toByteArray () const
 
std::string toString () const
 
bool isMulticast () const
 
bool operator== (const IPv4Address &rhs) const
 
bool operator< (const IPv4Address &rhs) const
 
bool operator!= (const IPv4Address &rhs) const
 
bool matchNetwork (const IPv4Network &network) const
 
bool matchNetwork (const std::string &network) const
 

Static Public Member Functions

static bool isValidIPv4Address (const std::string &addrAsString)
 

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/5]

pcpp::IPv4Address::IPv4Address ( )
default

A default constructor that creates an instance of the class with the zero-initialized address

◆ IPv4Address() [2/5]

pcpp::IPv4Address::IPv4Address ( const 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/5]

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/5]

pcpp::IPv4Address::IPv4Address ( const std::array< uint8_t, 4 > &  bytes)
inline

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

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

◆ IPv4Address() [5/5]

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

A constructor that creates an instance of the class out of std::string value.

Parameters
[in]addrAsStringThe std::string representation of the address
Exceptions
std::invalid_argumentThe provided string does not represent a valid IPv4 address.

Member Function Documentation

◆ isMulticast()

bool pcpp::IPv4Address::isMulticast ( ) const
Returns
True if an address is multicast, false otherwise.

◆ isValidIPv4Address()

static bool pcpp::IPv4Address::isValidIPv4Address ( const std::string &  addrAsString)
static

A static method that checks whether a string represents a valid IPv4 address

Parameters
[in]addrAsStringThe std::string representation of the address
Returns
True if the address is valid, false otherwise

◆ matchNetwork() [1/2]

bool pcpp::IPv4Address::matchNetwork ( const IPv4Network network) const

Checks whether the address matches a network.

Parameters
networkAn IPv4Network network
Returns
True if the address matches the network or false otherwise

◆ matchNetwork() [2/2]

bool pcpp::IPv4Address::matchNetwork ( const std::string &  network) const

Checks whether the address matches a network. For example: this method will return true for address 10.1.1.9 and network which is one of: 10.1.1.1/24, 10.1.1.1/255.255.255.0 Another example: this method will return false for address 11.1.1.9 and network which is one of: 10.1.1.1/16, 10.1.1.1/255.255.0.0

Parameters
[in]networkA string in one of these formats:
  • X.X.X.X/Y where X.X.X.X is a valid IP address and Y is a number between 0 and 32
  • X.X.X.X/Y.Y.Y.Y where X.X.X.X is a valid IP address and Y.Y.Y.Y is a valid netmask
Returns
True if the address matches the network or false if it doesn't or if the network is invalid

◆ operator!=()

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

Overload of the not-equal-to operator

Parameters
[in]rhsThe object to compare with
Returns
True if the addresses are not equal, false otherwise

◆ operator<()

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

Overload of the less-than operator

Parameters
[in]rhsThe object to compare with
Returns
True if the address value is lower than the other address value, false otherwise

◆ operator==()

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

Overload of the equal-to operator

Parameters
[in]rhsThe object to compare with
Returns
True if the addresses are equal, false otherwise

◆ toByteArray()

const std::array<uint8_t, 4>& pcpp::IPv4Address::toByteArray ( ) const
inline
Returns
A reference to a 4-byte standard array representing the IPv4 address

◆ toBytes()

const uint8_t* pcpp::IPv4Address::toBytes ( ) const
inline
Returns
A non-owning pointer to 4-byte C-style array representing the IPv4 address

◆ toInt()

uint32_t pcpp::IPv4Address::toInt ( ) const
inline
Returns
A 4-byte integer in network byte order representing the IPv4 address

◆ toString()

std::string pcpp::IPv4Address::toString ( ) const
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".