PcapPlusPlus
pcpp::IPv4Address Class Reference

#include <IpAddress.h>

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

Public Member Functions

 IPv4Address (uint32_t addressAsInt)
 
 IPv4Address (char *addressAsString)
 
 IPv4Address (std::string addressAsString)
 
 IPv4Address (in_addr *inAddr)
 
 IPv4Address (const IPv4Address &other)
 
AddressType getType () const
 
IPAddressclone () const
 
uint32_t toInt () const
 
in_addr * toInAddr ()
 
bool operator== (const IPv4Address &other) const
 
bool operator!= (const IPv4Address &other) const
 
IPv4Addressoperator= (const IPv4Address &other)
 
bool matchSubnet (const IPv4Address &subnet, const std::string &subnetMask)
 
- Public Member Functions inherited from pcpp::IPAddress
std::string toString () const
 
bool isValid ()
 
bool equals (const IPAddress *other)
 

Static Public Attributes

static IPv4Address Zero
 

Additional Inherited Members

- Public Types inherited from pcpp::IPAddress
enum  AddressType { IPv4AddressType, IPv6AddressType }
 
- Static Public Member Functions inherited from pcpp::IPAddress
static Ptr_t fromString (char *addressAsString)
 
static Ptr_t fromString (std::string addressAsString)
 

Detailed Description

Represents an IPv4 address (of type XXX.XXX.XXX.XXX). An instance of this class can be constructed from string, 4-byte integer or from the in_addr struct. It can be converted to each of these types

Constructor & Destructor Documentation

◆ IPv4Address() [1/5]

pcpp::IPv4Address::IPv4Address ( uint32_t  addressAsInt)

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

Parameters
[in]addressAsIntThe address as 4-byte integer

◆ IPv4Address() [2/5]

pcpp::IPv4Address::IPv4Address ( char *  addressAsString)

A constructor that creates an instance of the class out of string (char*) value If the string doesn't represent a valid IPv4 address, instance will be invalid, meaning isValid() will return false

Parameters
[in]addressAsStringThe string (char*) representation of the address

◆ IPv4Address() [3/5]

pcpp::IPv4Address::IPv4Address ( std::string  addressAsString)

A constructor that creates an instance of the class out of std::string value If the string doesn't represent a valid IPv4 address, instance will be invalid, meaning isValid() will return false

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

◆ IPv4Address() [4/5]

pcpp::IPv4Address::IPv4Address ( in_addr *  inAddr)

A constructor that creates an instance of the class out of in_addr struct pointer

Parameters
[in]inAddrThe in_addr struct representation of the address

◆ IPv4Address() [5/5]

pcpp::IPv4Address::IPv4Address ( const IPv4Address other)

A copy constructor for this class

Member Function Documentation

◆ clone()

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

Clone the object

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

Implements pcpp::IPAddress.

◆ getType()

AddressType pcpp::IPv4Address::getType ( ) const
inlinevirtual
Returns
IPv4AddressType

Implements pcpp::IPAddress.

◆ matchSubnet()

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

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

◆ operator!=()

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

Overload of the non-equal operator

Returns
true if 2 addresses are not equal. False otherwise

◆ operator=()

IPv4Address& pcpp::IPv4Address::operator= ( const IPv4Address other)

Overload of the assignment operator

◆ operator==()

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

Overload of the comparison operator

Returns
true if 2 addresses are equal. False otherwise

◆ toInAddr()

in_addr* pcpp::IPv4Address::toInAddr ( )
inline

Returns a in_addr struct pointer representing the IPv4 address

Returns
a in_addr struct pointer representing the IPv4 address

◆ toInt()

uint32_t pcpp::IPv4Address::toInt ( ) const

Converts the IPv4 address into a 4B integer

Returns
a 4B integer representing the IPv4 address

Member Data Documentation

◆ Zero

IPv4Address pcpp::IPv4Address::Zero
static

A static value representing a zero value of IPv4 address, meaning address of value "0.0.0.0"