SourcePro® API Reference Guide

 
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Related Functions
RWInetHost Class Reference

Encapsulates an Internet host IP address and its names. More...

#include <rw/network/RWInetHost.h>

Public Types

enum  NameLookup { numeric }
 

Public Member Functions

 RWInetHost ()
 
 RWInetHost (unsigned long IPAddress)
 
 RWInetHost (const RWCString &hostname)
 
 RWInetHost (const char *)
 
unsigned long getAddress () const
 
RWTValVector< unsigned long > getAddresses () const
 
RWTValVector< RWCStringgetAliases () const
 
RWCString getName () const
 
RWCString id (unsigned level=0) const
 
bool operator!= (const RWInetHost &rhs) const
 
bool operator== (const RWInetHost &rhs) const
 
void prepare () const
 
void prepare (NameLookup lookup) const
 

Static Public Member Functions

static RWCString addressAsString (unsigned long IPAddress)
 
static RWInetHost me ()
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &strm, const RWInetHost &host)
 

Detailed Description

Encapsulates an Internet host IP address and its names. You can construct an RWInetHost from either an IP address or a symbolic name.

Note
Typically, Winsock implementations do not return a default alias. As a result, an RWInetHost object on a Windows platform includes alias names only if they have been explicitly defined.

Member Enumeration Documentation

Attributes to change name lookup behavior.

Enumerator
numeric 

If the host address is already known, a lookup will not be used to discover the host name. The dotted decimal form of the host address will be used as the host name.

Constructor & Destructor Documentation

RWInetHost::RWInetHost ( )

An Internet host can be specified as an actual address or through a string. The string can be either the symbolic name of the host or an IP address in dotted decimal notation. If an IP address is passed in as a long, it must be in network byte order. The default constructor creates a special host that represents an unspecified IP address on the current machine. This is useful when constructing servers. The RWCString should contain 7-bit US-ASCII data.

RWInetHost::RWInetHost ( unsigned long  IPAddress)

An Internet host can be specified as an actual address or through a string. The string can be either the symbolic name of the host or an IP address in dotted decimal notation. If an IP address is passed in as a long, it must be in network byte order. The default constructor creates a special host that represents an unspecified IP address on the current machine. This is useful when constructing servers. The RWCString should contain 7-bit US-ASCII data.

RWInetHost::RWInetHost ( const RWCString hostname)

An Internet host can be specified as an actual address or through a string. The string can be either the symbolic name of the host or an IP address in dotted decimal notation. If an IP address is passed in as a long, it must be in network byte order. The default constructor creates a special host that represents an unspecified IP address on the current machine. This is useful when constructing servers. The RWCString should contain 7-bit US-ASCII data.

RWInetHost::RWInetHost ( const char *  )

An Internet host can be specified as an actual address or through a string. The string can be either the symbolic name of the host or an IP address in dotted decimal notation. If an IP address is passed in as a long, it must be in network byte order. The default constructor creates a special host that represents an unspecified IP address on the current machine. This is useful when constructing servers. The RWCString should contain 7-bit US-ASCII data.

Member Function Documentation

static RWCString RWInetHost::addressAsString ( unsigned long  IPAddress)
static

Takes an address in network byte order and returns the dotted decimal string representation of the address. To go from a dotted decimal string to an address, build an RWInetHost object from the dotted decimal string. The RWCString should contain 7-bit US-ASCII data.

unsigned long RWInetHost::getAddress ( ) const

Returns the primary IP address for this host entry in network byte order. If you want to print out an IP address, use the addressAsString() static member function.

RWTValVector<unsigned long> RWInetHost::getAddresses ( ) const

Returns a list of addresses for this host entry. Addresses are returned in network byte order. If you want to print out an IP address, use the addressAsString() static member function. The primary address is the first entry in the getAddresses() array. This call may block if prepare() has not been called.

RWTValVector<RWCString> RWInetHost::getAliases ( ) const

Returns the list of aliases for this host entry. The official name is not included in the list of aliases. This call may block if prepare() has not been called. The RWCString should contain 7-bit US-ASCII data.

Note
Aliases are returned only if the RWInetHost was constructed with a hostname (as opposed to an IP Address). If the class was constructed with an IP address, no aliases are fetched.
RWCString RWInetHost::getName ( ) const

Returns the official name for this host entry. This call may block if prepare() has not been called. The RWCString should contain 7-bit US-ASCII data.

RWCString RWInetHost::id ( unsigned  level = 0) const

Returns a string describing self. The verbosity of the output is controlled by level, where level=0 is the most basic output, and level=9 is the most verbose. If not specified, a default value of 0 is used and is guaranteed not to block.

Depending on the level and the constructor the instance was instantiated with, the output may contain the host name or IP address, any known aliases for that name and any alternate IP addresses.

Grammar Definitions

ip-address ::= <ip address in dotted decimal notation>
ip-address-list ::= ip-address ("," ip-address)*
hostname ::= <domain name>
host ::= hostname | ip-address
alias-list ::= "(" hostname ("," hostname)* ")"
level Calls prepare() Output Grammar Sample Output for id(level) given RWInetHost("127.0.0.1")
0 host 127.0.0.1
1 host 127.0.0.1
2 host 127.0.0.1
3 X host localhost
4 X host "(" ip-address ")" localhost(127.0.0.1)
5 X host "(" ip-address ")" localhost(127.0.0.1)
6 X host localhost
7 X host "(" ip-address ")" localhost(127.0.0.1)
8 X host "(" ip-address ")" localhost(127.0.0.1)
9 X host (alias-list)? "(" ip-address-list ")" localhost(127.0.0.1)
static RWInetHost RWInetHost::me ( )
static

Returns the host object for the host on which this program is currently running.

bool RWInetHost::operator!= ( const RWInetHost rhs) const

Returns true if the two host objects are not equal.

bool RWInetHost::operator== ( const RWInetHost rhs) const

Returns true if the two host objects are equal.

void RWInetHost::prepare ( ) const

Ensures that no future operations block. The prepare() function calls the host database routines to gather information about this host. It is not necessary to explicitly call prepare() because it is called by other member functions if needed. No exceptions are thrown by prepare().

void RWInetHost::prepare ( NameLookup  lookup) const

Ensures that no future operations block. The prepare() function calls the host database routines to gather information about this host. It is not necessary to explicitly call prepare() because it is called by other member functions if needed. No exceptions are thrown by prepare().

Friends And Related Function Documentation

std::ostream & operator<< ( std::ostream &  strm,
const RWInetHost host 
)
related

Outputs a representation of host on strm. The representation is generated using the member function host.id() with level=0.

Note
This class does not have an extraction (>>) operator.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.