Async 1.8.0
Async::IpAddress Class Reference

A class for representing an IP address in an OS independent way. More...

#include <AsyncIpAddress.h>

Public Types

typedef struct in_addr Ip4Addr
 The type for the OS specific representation of an IP address.
 

Public Member Functions

 IpAddress (void)
 Default constructor for the IpAddress class.
 
 IpAddress (const std::string &addr)
 Constructor for the IpAddress class.
 
 IpAddress (const Ip4Addr &addr)
 Constructor for the IpAddress class.
 
 IpAddress (const IpAddress &addr)
 Copy contructor.
 
 ~IpAddress (void)
 Destructor.
 
Ip4Addr ip4Addr (void) const
 Return the IP address in OS specific representation.
 
bool isUnicast (void) const
 Check if this is a unicast IP address.
 
bool isWithinSubet (const std::string &subnet) const
 Check if the IP address is within the given netmask.
 
bool isEmpty (void) const
 Check if an invalid IP address has been assigned.
 
void clear (void)
 Invalidate the IP address value.
 
std::string toString (void) const
 Return the string representation of the IP address.
 
void setIp (const Ip4Addr &addr)
 Set the IP address.
 
bool setIpFromString (const std::string &str)
 Set the IP address from a string.
 
IpAddressoperator= (const IpAddress &rhs)
 Assignment operator.
 
bool operator== (const IpAddress &rhs) const
 Equality operator.
 
bool operator!= (const IpAddress &rhs) const
 Unequality operator.
 
bool operator< (const IpAddress &rhs) const
 Less than operator.
 

Friends

std::ostream & operator<< (std::ostream &os, const Async::IpAddress &ip)
 Output stream operator.
 
std::istream & operator>> (std::istream &is, Async::IpAddress &ip)
 Input stream operator.
 

Detailed Description

A class for representing an IP address in an OS independent way.

Examples
AsyncTcpPrioClient_demo.cpp, and AsyncUdpSocket_demo.cpp.

Definition at line 104 of file AsyncIpAddress.h.

Member Typedef Documentation

◆ Ip4Addr

struct in_addr Async::IpAddress::Ip4Addr

The type for the OS specific representation of an IP address.

Definition at line 110 of file AsyncIpAddress.h.

Constructor & Destructor Documentation

◆ IpAddress() [1/4]

Async::IpAddress::IpAddress ( void )

Default constructor for the IpAddress class.

◆ IpAddress() [2/4]

Async::IpAddress::IpAddress ( const std::string & addr)

Constructor for the IpAddress class.

Parameters
addrThe string representation of an IP address

◆ IpAddress() [3/4]

Async::IpAddress::IpAddress ( const Ip4Addr & addr)

Constructor for the IpAddress class.

Parameters
addrThe IP address in OS specific representation

◆ IpAddress() [4/4]

Async::IpAddress::IpAddress ( const IpAddress & addr)
inline

Copy contructor.

Parameters
addrAn IpAddress object to construct the new object from

Definition at line 133 of file AsyncIpAddress.h.

◆ ~IpAddress()

Async::IpAddress::~IpAddress ( void )
inline

Destructor.

Definition at line 138 of file AsyncIpAddress.h.

Member Function Documentation

◆ clear()

void Async::IpAddress::clear ( void )
inline

Invalidate the IP address value.

Definition at line 172 of file AsyncIpAddress.h.

◆ ip4Addr()

Ip4Addr Async::IpAddress::ip4Addr ( void ) const
inline

Return the IP address in OS specific representation.

Returns
The IP address

Definition at line 144 of file AsyncIpAddress.h.

◆ isEmpty()

bool Async::IpAddress::isEmpty ( void ) const
inline

Check if an invalid IP address has been assigned.

Returns
Return true if this is an invalid address or false if a valid address has been assigned.

Definition at line 167 of file AsyncIpAddress.h.

◆ isUnicast()

bool Async::IpAddress::isUnicast ( void ) const

Check if this is a unicast IP address.

Returns
Return true if this is a unicast address or false if it is some other type.

◆ isWithinSubet()

bool Async::IpAddress::isWithinSubet ( const std::string & subnet) const

Check if the IP address is within the given netmask.

Parameters
subnetThe subnet to use in the check. The subnet should be given on the form a.b.c.d/m (e.g. 192.168.1.0/24).
Returns
Return true if within the given subnet or false if it is not.

◆ operator!=()

bool Async::IpAddress::operator!= ( const IpAddress & rhs) const
inline

Unequality operator.

Parameters
rhsRight hand side expression
Returns
Returns true if the right hand side object is unequal to this object, or else returns false.

Definition at line 221 of file AsyncIpAddress.h.

◆ operator<()

bool Async::IpAddress::operator< ( const IpAddress & rhs) const
inline

Less than operator.

Parameters
rhsRight hand side expression
Returns
Returns true if the right hand side object is less than this object, or else returns false.

Definition at line 232 of file AsyncIpAddress.h.

◆ operator=()

IpAddress & Async::IpAddress::operator= ( const IpAddress & rhs)
inline

Assignment operator.

Parameters
rhsThe address object to assign to this object
Returns
Returns the new IP address

Definition at line 198 of file AsyncIpAddress.h.

◆ operator==()

bool Async::IpAddress::operator== ( const IpAddress & rhs) const
inline

Equality operator.

Parameters
rhsRight hand side expression
Returns
Returns true if the right hand side object is equal to this object, or else returns false.

Definition at line 210 of file AsyncIpAddress.h.

◆ setIp()

void Async::IpAddress::setIp ( const Ip4Addr & addr)
inline

Set the IP address.

Parameters
addrThe IP address to set

Definition at line 184 of file AsyncIpAddress.h.

◆ setIpFromString()

bool Async::IpAddress::setIpFromString ( const std::string & str)

Set the IP address from a string.

Parameters
strThe string to parse (e.g. "192.168.0.1")
Returns
Returns true on success or else false

◆ toString()

std::string Async::IpAddress::toString ( void ) const

Return the string representation of the IP address.

Returns
The IP address string
Examples
AsyncFramedTcpServer_demo.cpp, and AsyncTcpServer_demo.cpp.

Referenced by Async::SslX509ExtSubjectAltName::forEach(), Async::SslX509::matchIp(), and Async::TcpClientBase::remoteHostName().

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const Async::IpAddress & ip )
friend

Output stream operator.

Parameters
osThe stream to output data to
ipThe IP address to output to the stream

◆ operator>>

std::istream & operator>> ( std::istream & is,
Async::IpAddress & ip )
friend

Input stream operator.

Parameters
isThe stream to input data from
ipThe IP address object to store information in

The documentation for this class was generated from the following file: