Dv::Net::InetAddress Class Reference

A Dv::Net::InetAddress object represents a valid internet host. More...

#include <inetaddress.h>

List of all members.

Public Member Functions

 ~InetAddress ()
bool operator== (const InetAddress &) const
const char * host () const
 Find alphabetic hostname of this address.
unsigned long address () const
const std::string & dot_address () const

Static Public Member Functions

static Dv::shared_ptr
< InetAddress
by_name (const std::string &host)
 Factory method: return ref<InetAddress> corresponding with host or 0.
static Dv::shared_ptr
< InetAddress
by_address (unsigned long addr)
 Factory method: return ref<InetAddress> corresponding with addr or 0.
static std::string local_host ()

Private Member Functions

 InetAddress (const char *, unsigned long, const char *)
 Private constructor.

Static Private Member Functions

static const char * host_name_from_address (unsigned long addr)
 Use gethostbyaddr to find the hostname.

Private Attributes

const char * host_
unsigned long address_
std::string dot_address_

Detailed Description

A Dv::Net::InetAddress object represents a valid internet host.

Definition at line 17 of file inetaddress.h.


Constructor & Destructor Documentation

Dv::Net::InetAddress::~InetAddress (  ) 
Dv::Net::InetAddress::InetAddress ( const char *  ,
unsigned  long,
const char *   
) [private]

Private constructor.


Member Function Documentation

static Dv::shared_ptr<InetAddress> Dv::Net::InetAddress::by_name ( const std::string &  host  )  [static]

Factory method: return ref<InetAddress> corresponding with host or 0.

Parameters:
host string representation of host, of the form "tinf2.vub.ac.be" or "134.184.65.2". "localhost" is also a valid argument.
Returns:
reference to InetAddress representing the host with given name or 0

Example usage:

  Dv::Util::ref<InetAddress>  address(InetAddress::Net::by_name("tinf2.vub.ac.be"));
  if (address) 
    cout << address->dot_address() << endl;
static Dv::shared_ptr<InetAddress> Dv::Net::InetAddress::by_address ( unsigned long  addr  )  [static]

Factory method: return ref<InetAddress> corresponding with addr or 0.

Note that this function does not automatically fill in the alphabetic host, in order not to do a possibly superfluous DNS query.

Parameters:
addr numeric internet address
Returns:
reference to InetAddress representing the host with addr or 0.
See also:
Dv::Net::InetAddress::host
bool Dv::Net::InetAddress::operator== ( const InetAddress  )  const
Returns:
true iff the numeric addresses are the same.
const char* Dv::Net::InetAddress::host (  )  const

Find alphabetic hostname of this address.

Note that, if the Dv::Net::InetAddress object was created using Dv::Net::InetAddress::by_address, this call may result in a DNS query. This is because the (alphabetic) host is only obtained ``on demand'', i.e. by calling this function. This feature was introduced to avoid unnecessary DNS queries.

Returns:
0 if host name cannot be obtained using gethostbyaddr.
string representation of host, e.g. "tinf2.vub.ac.be."
See also:
Dv::Net::InetAddress::by_address
unsigned long Dv::Net::InetAddress::address (  )  const [inline]
Returns:
numeric address of host (in network order).

Definition at line 61 of file inetaddress.h.

References address_.

const std::string& Dv::Net::InetAddress::dot_address (  )  const [inline]
Returns:
dot address of host, e.g. "134.184.65.2".

Definition at line 63 of file inetaddress.h.

References dot_address_.

static std::string Dv::Net::InetAddress::local_host (  )  [static]
Returns:
name of local host or "localhost" if not found.
static const char* Dv::Net::InetAddress::host_name_from_address ( unsigned long  addr  )  [static, private]

Use gethostbyaddr to find the hostname.

Returns:
0 if not found
Warning:
the return value has been allocated using strdup

Member Data Documentation

const char* Dv::Net::InetAddress::host_ [mutable, private]

Definition at line 67 of file inetaddress.h.

unsigned long Dv::Net::InetAddress::address_ [private]

Definition at line 68 of file inetaddress.h.

Referenced by address().

std::string Dv::Net::InetAddress::dot_address_ [private]

Definition at line 69 of file inetaddress.h.

Referenced by dot_address().


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

dvnet-0.9.24 [ 5 December, 2009]