UCommon
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
ost::IPV4Address Class Reference

The network name and address objects are all derived from a common IPV4Address base class. More...

#include <address.h>

Inheritance diagram for ost::IPV4Address:
Inheritance graph
[legend]

Public Member Functions

struct in_addr getAddress (void) const
 Provide a low level system usable struct in_addr object from the contents of IPV4Address. More...
 
struct in_addr getAddress (size_t i) const
 Provide a low level system usable struct in_addr object from the contents of IPV4Address. More...
 
size_t getAddressCount () const
 Returns the number of internet addresses that an IPV4Address object contains. More...
 
const char * getHostname (void) const
 Provide a string representation of the value (Internet Address) held in the IPV4Address object. More...
 
 IPV4Address (const IPV4Validator *validator=NULL)
 Create an Internet Address object with an empty (0.0.0.0) address. More...
 
 IPV4Address (struct in_addr addr, const IPV4Validator *validator=NULL)
 Convert the system internet address data type (struct in_addr) into a Common C++ IPV4Address object. More...
 
 IPV4Address (const char *address, const IPV4Validator *validator=NULL)
 Convert a null terminated ASCII host address string (example: "127.0.0.1") or host address name (example: "www.voxilla.org") directly into a Common C++ IPV4Address object. More...
 
 IPV4Address (const IPV4Address &rhs)
 Copy constructor.
 
bool isInetAddress (void) const
 May be used to verify if a given IPV4Address returned by another function contains a "valid" address, or "0.0.0.0" which is often used to mark "invalid" IPV4Address values. More...
 
 operator bool () const
 
bool operator! () const
 
bool operator!= (const IPV4Address &a) const
 Compare two internet addresses to see if they are not equal (if they each refer to unique and different physical ip addresses). More...
 
IPV4Addressoperator= (const char *str)
 
IPV4Addressoperator= (struct in_addr addr)
 
IPV4Addressoperator= (const IPV4Address &rhs)
 
IPV4Addressoperator= (in_addr_t addr)
 Allows assignment from the return of functions like inet_addr() or htonl()
 
bool operator== (const IPV4Address &a) const
 Compare two internet addresses to see if they are equal (if they specify the physical address of the same internet host). More...
 
virtual ~IPV4Address ()
 Destructor.
 

Protected Member Functions

void setAddress (const char *host)
 Used to specify a host name or numeric internet address. More...
 
bool setIPAddress (const char *host)
 Sets the IP address from a string representation of the numeric address, ie "127.0.0.1". More...
 

Protected Attributes

size_t addr_count
 
char * hostname
 
struct in_addr * ipaddr
 

Static Protected Attributes

static Mutex mutex
 

Detailed Description

The network name and address objects are all derived from a common IPV4Address base class.

Specific classes, such as IPV4Host, IPV4Mask, etc, are defined from IPV4Address entirely so that the manner a network address is being used can easily be documented and understood from the code and to avoid common errors and accidental misuse of the wrong address object. For example, a "connection" to something that is declared as a "IPV4Host" can be kept type-safe from a "connection" accidently being made to something that was declared a "IPV4Broadcast".

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m Internet Address binary data type.

Definition at line 362 of file address.h.

Constructor & Destructor Documentation

◆ IPV4Address() [1/3]

ost::IPV4Address::IPV4Address ( const IPV4Validator validator = NULL)

Create an Internet Address object with an empty (0.0.0.0) address.

Parameters
validatoroptional validator function object, intended for derived classes.

◆ IPV4Address() [2/3]

ost::IPV4Address::IPV4Address ( struct in_addr  addr,
const IPV4Validator validator = NULL 
)

Convert the system internet address data type (struct in_addr) into a Common C++ IPV4Address object.

Parameters
addrstruct of system used binary internet address.
validatoroptional validator function object, intended for derived classes.

◆ IPV4Address() [3/3]

ost::IPV4Address::IPV4Address ( const char *  address,
const IPV4Validator validator = NULL 
)

Convert a null terminated ASCII host address string (example: "127.0.0.1") or host address name (example: "www.voxilla.org") directly into a Common C++ IPV4Address object.

Parameters
addressnull terminated C string.
validatoroptional validator function object, intended for derived classes.

Member Function Documentation

◆ getAddress() [1/2]

struct in_addr ost::IPV4Address::getAddress ( void  ) const

Provide a low level system usable struct in_addr object from the contents of IPV4Address.

This is needed for services such as bind() and connect().

Returns
system binary coded internet address.

◆ getAddress() [2/2]

struct in_addr ost::IPV4Address::getAddress ( size_t  i) const

Provide a low level system usable struct in_addr object from the contents of IPV4Address.

This is needed for services such as bind() and connect().

Parameters
ifor IPV4Addresses with multiple addresses, returns the address at this index. User should call getAddressCount() to determine the number of address the object contains.
Returns
system binary coded internet address. If parameter i is out of range, the first address is returned.

◆ getAddressCount()

size_t ost::IPV4Address::getAddressCount ( ) const
inline

Returns the number of internet addresses that an IPV4Address object contains.

This usually only happens with IPV4Host objects where multiple IP addresses are returned for a DNS lookup

Definition at line 484 of file address.h.

◆ getHostname()

const char* ost::IPV4Address::getHostname ( void  ) const

Provide a string representation of the value (Internet Address) held in the IPV4Address object.

Returns
string representation of IPV4Address.

◆ isInetAddress()

bool ost::IPV4Address::isInetAddress ( void  ) const

May be used to verify if a given IPV4Address returned by another function contains a "valid" address, or "0.0.0.0" which is often used to mark "invalid" IPV4Address values.

Returns
true if address != 0.0.0.0.

◆ operator!=()

bool ost::IPV4Address::operator!= ( const IPV4Address a) const

Compare two internet addresses to see if they are not equal (if they each refer to unique and different physical ip addresses).

This is implimented in terms of operator==

◆ operator==()

bool ost::IPV4Address::operator== ( const IPV4Address a) const

Compare two internet addresses to see if they are equal (if they specify the physical address of the same internet host).

If there is more than one IP address in either IPV4Address object, this will return true if all of the IP addresses in the smaller are in the larger in any order.

◆ setAddress()

void ost::IPV4Address::setAddress ( const char *  host)
protected

Used to specify a host name or numeric internet address.

Parameters
hostThe string representation of the IP address or a hostname, , if NULL, it will default to INADDR_ANY

◆ setIPAddress()

bool ost::IPV4Address::setIPAddress ( const char *  host)
protected

Sets the IP address from a string representation of the numeric address, ie "127.0.0.1".

Parameters
hostThe string representation of the IP address
Returns
true if successful

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