Rudiments
Public Member Functions | Static Public Member Functions
hostentry Class Reference

List of all members.

Public Member Functions

 hostentry ()
 hostentry (const hostentry &h)
hostentryoperator= (const hostentry &h)
 ~hostentry ()
bool initialize (const char *hostname)
bool initialize (const char *address, int32_t len, int32_t type)
const char * getName () const
const char *const getAliasList () const
int32_t getAddressType () const
int32_t getAddressLength () const
const char *const getAddressList () const
char * getAddressString (int32_t index) const
void print () const

Static Public Member Functions

static bool getAliasList (const char *hostname, char ***aliaslist)
static bool getAddressType (const char *hostname, int32_t *addresstype)
static bool getAddressLength (const char *hostname, int32_t *addresslength)
static bool getAddressList (const char *hostname, char ***addresslist)
static bool getAddressString (const char *hostname, int32_t index, char **addressstring)
static bool getName (const char *address, int32_t len, int32_t type, char **name)
static bool getAliasList (const char *address, int32_t len, int32_t type, char ***aliaslist)
static bool getAddressList (const char *address, int32_t len, int32_t type, char ***addresslist)
static bool getAddressString (const char *address, int32_t len, int32_t type, int32_t index, char **addressstring)
static bool needsMutex ()
static void setMutex (mutex *mtx)

Detailed Description

The hostentry class provides methods for retrieving entries from the host file (/etc/hosts on unix).


Constructor & Destructor Documentation

hostentry::hostentry ( )

Creates an instance of the hostentry class.

hostentry::hostentry ( const hostentry h)

Creates an instance of the hostentry class that is a copy of "h".

hostentry::~hostentry ( )

Deletes this instance of the hostentry class.


Member Function Documentation

static bool hostentry::getAddressLength ( const char *  hostname,
int32_t *  addresslength 
) [static]

Sets "addresslength" to the length of the address for "hostname".

int32_t hostentry::getAddressLength ( ) const

Returns the address length of the host entry.

static bool hostentry::getAddressList ( const char *  hostname,
char ***  addresslist 
) [static]

Sets "addresslist" to a NULL-terminated list of addresses for "hostname".

Note that "addresslist" is allocated internally and returned. The calling program must free each element and the array itself.

Returns true on success and false otherwise.

static bool hostentry::getAddressList ( const char *  address,
int32_t  len,
int32_t  type,
char ***  addresslist 
) [static]

Sets "addresslist" to a NULL-terminated list of addresses for "address" of length "len" and type "type".

Note that "address" must be a binary representation of the address. This is why "len" and "type" are also required.

Note that "addresslist" is allocated internally and returned. The calling program must free each element and the array itself.

const char* const hostentry::getAddressList ( ) const

Returns a NULL-terminated list of addresses for the host entry.

static bool hostentry::getAddressString ( const char *  address,
int32_t  len,
int32_t  type,
int32_t  index,
char **  addressstring 
) [static]

Sets "addressstring" to a string representation of "address" of length "len" and type "type".

Note that "address" must be a binary representation of the address. This is why "len" and "type" are also required.

Note that "addressstring" is allocated internally and returned. The calling program must free the buffer.

char* hostentry::getAddressString ( int32_t  index) const

Returns the "index"'th address of the host entry.

Note that this method allocated a buffer internally and returns it. The calling program must free the buffer.

static bool hostentry::getAddressString ( const char *  hostname,
int32_t  index,
char **  addressstring 
) [static]

Sets "addressstring" to the "index"'th address of "hostname". Note that "addressstring" is allocated internally and returned. The calling program must free the buffer.

static bool hostentry::getAddressType ( const char *  hostname,
int32_t *  addresstype 
) [static]

Sets "addresstype" to the address type of "hostname".

int32_t hostentry::getAddressType ( ) const

Returns the address type of the host entry.

static bool hostentry::getAliasList ( const char *  address,
int32_t  len,
int32_t  type,
char ***  aliaslist 
) [static]

Sets "aliaslist" to a NULL-terminated list of aliases for "address" of length "len" and type "type".

Note that "address" must be a binary representation of the address. This is why "len" and "type" are also required.

Note that "aliaslist" is allocated internally and returned. The calling program must free each element and the array itself.

static bool hostentry::getAliasList ( const char *  hostname,
char ***  aliaslist 
) [static]

Sets "aliaslist" to a NULL-terminated list of aliases for "hostname". Note that "aliaslist" is allocated internally and returned. The calling program must free each element and the array itself.

Returns true on success and false otherwise.

const char* const hostentry::getAliasList ( ) const

Returns a NULL-terminated list of aliases for the host entry.

static bool hostentry::getName ( const char *  address,
int32_t  len,
int32_t  type,
char **  name 
) [static]

Sets "name" to the primary hostname of "address" of length "len" and type "type".

Note that "address" must be a binary representation of the address. This is why "len" and "type" are also required.

Note that "name" is allocated internally and returned. The calling program must free the buffer.

const char* hostentry::getName ( ) const

Returns the primary hostname of the host entry.

bool hostentry::initialize ( const char *  address,
int32_t  len,
int32_t  type 
)

Looks up a host entry by address.

Note that "address" must be a binary representation of the address. This is why "len" and "type" are also required.

bool hostentry::initialize ( const char *  hostname)

Looks up a host entry by name.

static bool hostentry::needsMutex ( ) [static]

Returns true if this class needs a mutex to operate safely in a threaded environment and false otherwise.

hostentry& hostentry::operator= ( const hostentry h)

Makes this instance of the hostentry class identical to "h".

void hostentry::print ( ) const

Prints out the representation of the host entry.

static void hostentry::setMutex ( mutex mtx) [static]

Allows you to supply a mutex is the class needs it. (see needsMutex()). If your application is not multithreaded, then there is no need to supply a mutex.