PcapPlusPlus  22.11
pcpp::IPAddress Class Reference

#include <IpAddress.h>

Public Types

enum  AddressType { IPv4AddressType, IPv6AddressType }
 

Public Member Functions

 IPAddress ()
 
 IPAddress (const IPv4Address &addr)
 
 IPAddress (const IPv6Address &addr)
 
 IPAddress (const std::string &addrAsString)
 
IPAddressoperator= (const IPv4Address &addr)
 
IPAddressoperator= (const IPv6Address &addr)
 
AddressType getType () const
 
std::string toString () const
 
bool isValid () const
 
bool isIPv4 () const
 
bool isIPv6 () const
 
bool isMulticast () const
 
const IPv4AddressgetIPv4 () const
 
const IPv6AddressgetIPv6 () const
 
bool operator== (const IPAddress &rhs) const
 
bool operator< (const IPAddress &rhs) const
 
bool operator!= (const IPAddress &rhs) const
 

Detailed Description

The class is a version-independent representation for an IP address

Member Enumeration Documentation

◆ AddressType

An enum representing the address type: IPv4 or IPv6

Enumerator
IPv4AddressType 

IPv4 address type

IPv6AddressType 

IPv6 address type

Constructor & Destructor Documentation

◆ IPAddress() [1/4]

pcpp::IPAddress::IPAddress ( )
inline

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

◆ IPAddress() [2/4]

pcpp::IPAddress::IPAddress ( const IPv4Address addr)
inline

A constructor that creates an instance of the class out of IPv4Address.

Parameters
[in]addrA const reference to instance of IPv4Address

◆ IPAddress() [3/4]

pcpp::IPAddress::IPAddress ( const IPv6Address addr)
inline

A constructor that creates an instance of the class out of IPv6Address.

Parameters
[in]addrA const reference to instance of IPv6Address

◆ IPAddress() [4/4]

pcpp::IPAddress::IPAddress ( 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 or IPv6 address, an instance will store an unspecified address

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

Member Function Documentation

◆ getIPv4()

const IPv4Address& pcpp::IPAddress::getIPv4 ( ) const
inline

Get a reference to IPv4 address instance

Returns
The const reference to IPv4Address instance

◆ getIPv6()

const IPv6Address& pcpp::IPAddress::getIPv6 ( ) const
inline

Get a reference to IPv6 address instance

Returns
The const reference to IPv6Address instance

◆ getType()

AddressType pcpp::IPAddress::getType ( ) const
inline

Gets the address type: IPv4 or IPv6

Returns
The address type

◆ isIPv4()

bool pcpp::IPAddress::isIPv4 ( ) const
inline
Returns
Determine whether the object contains an IP version 4 address

◆ isIPv6()

bool pcpp::IPAddress::isIPv6 ( ) const
inline
Returns
Determine whether the object contains an IP version 6 address

◆ isMulticast()

bool pcpp::IPAddress::isMulticast ( ) const
inline

Determine whether the address is a multicast address

Returns
True if an address is multicast

◆ isValid()

bool pcpp::IPAddress::isValid ( ) const
inline
Returns
Determine whether the address is unspecified

◆ operator!=()

bool pcpp::IPAddress::operator!= ( const IPAddress 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::IPAddress::operator< ( const IPAddress 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=() [1/2]

IPAddress & pcpp::IPAddress::operator= ( const IPv4Address addr)
inline

Overload of an assignment operator.

Parameters
[in]addrA const reference to instance of IPv4Address
Returns
A reference to the assignee

◆ operator=() [2/2]

IPAddress & pcpp::IPAddress::operator= ( const IPv6Address addr)
inline

Overload of an assignment operator.

Parameters
[in]addrA const reference to instance of IPv6Address
Returns
A reference to the assignee

◆ operator==()

bool pcpp::IPAddress::operator== ( const IPAddress 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

◆ toString()

std::string pcpp::IPAddress::toString ( ) const
inline

Returns a std::string representation of the address

Returns
A string representation of the address