nidas v1.2.3
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
nidas::util::Inet4Address Class Reference

Support for IP version 4 host address. More...

#include <Inet4Address.h>

Public Member Functions

 Inet4Address ()
 Default constructor.
 
 Inet4Address (const struct in_addr *)
 Construct an address from a pointer to the C in_addr structure.
 
 Inet4Address (unsigned int addr)
 Construct an address.
 
std::string getHostAddress () const
 Return string containing address in dot notation: w.x.y.z.
 
std::string getHostName () const throw ()
 Return a hostname for this address.
 
const struct in_addr * getInAddrPtr () const
 Return const pointer to struct in_addr.
 
const struct in_addr getInAddr () const
 Get the structure containing the 4 byte internet version 4 address.
 
bool operator< (const Inet4Address &x) const
 Comparator operator for addresses.
 
bool operator== (const Inet4Address &x) const
 Equality operator for addresses.
 
bool operator!= (const Inet4Address &x) const
 Inequality operator for addresses.
 
bool isMultiCastAddress () const
 Is this address a multicast address? Multicast addresses are in the range 224.0.0.1 to 239.255.255.255, their first four bits are 1110=0xe.
 
int bitsMatch (const Inet4Address &x) const throw ()
 How many leading bits match in the two addresses?
 

Static Public Member Functions

static std::list< Inet4AddressgetAllByName (const std::string &hostname)
 Static method returning a list of addresses for a name.
 
static Inet4Address getByName (const std::string &hostname)
 Return an address of a name, the first one found by getAllByName.
 
static std::string getHostName (const Inet4Address &addr)
 Do reverse lookup of a name, given an address.
 

Protected Attributes

struct in_addr _inaddr
 The IP address, in network byte order.
 

Detailed Description

Support for IP version 4 host address.

This class provides by-name and by-address name service lookup, and caches the names and addresses in static maps.

Constructor & Destructor Documentation

◆ Inet4Address() [1/3]

Inet4Address::Inet4Address ( )

Default constructor.

Creates address: 0.0.0.0, aka: INADDR_ANY.

◆ Inet4Address() [2/3]

Inet4Address::Inet4Address ( const struct in_addr * a)

Construct an address from a pointer to the C in_addr structure.

◆ Inet4Address() [3/3]

Inet4Address::Inet4Address ( unsigned int addr)

Construct an address.

References _inaddr.

Member Function Documentation

◆ bitsMatch()

int Inet4Address::bitsMatch ( const Inet4Address & x) const
throw ( )

How many leading bits match in the two addresses?

◆ getAllByName()

list< Inet4Address > Inet4Address::getAllByName ( const std::string & hostname)
static

Static method returning a list of addresses for a name.

This is the name-to-address lookup method.

Parameters
hostnameeither a local hostname, like "linus", or a fully qualified name, "linus.atd.ucar.edu", or an address in dot notation: "128.117.80.208".
Exceptions
UnknownHostException;

Referenced by getByName().

◆ getByName()

Inet4Address Inet4Address::getByName ( const std::string & hostname)
static

Return an address of a name, the first one found by getAllByName.

Exceptions
UnknownHostException;

References getAllByName().

Referenced by nidas::util::SocketImpl::connect(), PConfig::loadRemoteXML(), and main().

◆ getHostAddress()

string Inet4Address::getHostAddress ( ) const

◆ getHostName() [1/2]

string Inet4Address::getHostName ( ) const
throw ( )

Return a hostname for this address.

Calls static getHostName() method.

References getHostName().

Referenced by getHostName().

◆ getHostName() [2/2]

string Inet4Address::getHostName ( const Inet4Address & addr)
static

Do reverse lookup of a name, given an address.

This is the address-to-name lookup method. If a host name is not found for the address, returns a string in dot notation: "x.x.x.x" using getHostAddress().

Exceptions

)

References _inaddr, ELOG, err, nidas::util::Exception::errnoToString(), getHostAddress(), getInAddr(), and WLOG.

Referenced by nidas::util::Inet4SocketAddress::toString().

◆ getInAddr()

const struct in_addr nidas::util::Inet4Address::getInAddr ( ) const
inline

Get the structure containing the 4 byte internet version 4 address.

To get the actual 4 byte integer value:

uint32_t addr = getInAddr().s_addr;
const struct in_addr getInAddr() const
Get the structure containing the 4 byte internet version 4 address.
Definition Inet4Address.h:114

Referenced by getHostName().

◆ getInAddrPtr()

const struct in_addr * nidas::util::Inet4Address::getInAddrPtr ( ) const
inline

Return const pointer to struct in_addr.

References _inaddr.

Referenced by nidas::util::Inet4SocketAddress::Inet4SocketAddress().

◆ isMultiCastAddress()

bool nidas::util::Inet4Address::isMultiCastAddress ( ) const
inline

Is this address a multicast address? Multicast addresses are in the range 224.0.0.1 to 239.255.255.255, their first four bits are 1110=0xe.

References _inaddr.

Referenced by nidas::util::McSocketListener::run().

◆ operator!=()

bool nidas::util::Inet4Address::operator!= ( const Inet4Address & x) const
inline

Inequality operator for addresses.

References _inaddr.

◆ operator<()

bool nidas::util::Inet4Address::operator< ( const Inet4Address & x) const
inline

Comparator operator for addresses.

References _inaddr.

◆ operator==()

bool nidas::util::Inet4Address::operator== ( const Inet4Address & x) const
inline

Equality operator for addresses.

References _inaddr.

Member Data Documentation

◆ _inaddr

struct in_addr nidas::util::Inet4Address::_inaddr
protected

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