PcapPlusPlus
pcpp::IPAddress Class Referenceabstract

#include <IpAddress.h>

Inheritance diagram for pcpp::IPAddress:
pcpp::IPv4Address pcpp::IPv6Address

Public Types

enum  AddressType { IPv4AddressType, IPv6AddressType }
 

Public Member Functions

virtual AddressType getType () const =0
 
std::string toString () const
 
bool isValid ()
 
virtual IPAddressclone () const =0
 
bool equals (const IPAddress *other)
 

Static Public Member Functions

static Ptr_t fromString (char *addressAsString)
 
static Ptr_t fromString (std::string addressAsString)
 

Detailed Description

Base class for IPv4Address and IPv6Address. It's an abstract class and cannot be used as is. The only useful method in this class are the 2 static methods that constructs an IP address class from string

Member Enumeration Documentation

An enum representing the address type: IPv4 or IPv6

Enumerator
IPv4AddressType 

IPv4 address type

IPv6AddressType 

IPv6 address type

Member Function Documentation

virtual IPAddress* pcpp::IPAddress::clone ( ) const
pure virtual

Clone the object

Returns
A newly allocated instance which is a clone of the current instance

Implemented in pcpp::IPv6Address, and pcpp::IPv4Address.

bool pcpp::IPAddress::equals ( const IPAddress other)

Compare between this IP address and another IP address. This method is different than operator==() implemented in IPv4Address and IPv6Address in the sense that you can compare any IP type: IPv6 to IPv6, IPv4 to IPv4 or IPv4 to IPv6. It fits cases when you're not sure which type you currently have

Returns
True if addresses match or false otherwise
static Ptr_t pcpp::IPAddress::fromString ( char *  addressAsString)
static

Constructs an IP address of type IPv4 or IPv6 from a string (char*) representation

Parameters
[in]addressAsStringThe address in string (char*) representation
Returns
an auto-pointer to IPv4Address or IPv6Address instance that the string address represents, or an auto-pointer to NULL if the string doesn't represent either of types
static Ptr_t pcpp::IPAddress::fromString ( std::string  addressAsString)
static

Constructs an IP address of type IPv4 or IPv6 from a std::string representation

Parameters
[in]addressAsStringThe address in std::string representation
Returns
an auto-pointer to IPv4Address or IPv6Address instance that the string address represents, or an auto-pointer to NULL if the string doesn't represent either of types
virtual AddressType pcpp::IPAddress::getType ( ) const
pure virtual

Gets the address type: IPv4 or IPv6

Returns
The address type

Implemented in pcpp::IPv6Address, and pcpp::IPv4Address.

bool pcpp::IPAddress::isValid ( )
inline

Get an indication if the address is valid. An address can be invalid if it was constructed from illegal input, for example: An IPv4 address that was constructed form the string "999.999.999.999"

Returns
True if the address is valid, false otherwise
std::string pcpp::IPAddress::toString ( ) const
inline

Returns a std::string representation of the address

Returns
A string representation of the address