Rudiments
Public Member Functions | Static Public Member Functions | List of all members
hostentry Class Reference

Inherits object.

Public Member Functions

 hostentry ()
 
 ~hostentry ()
 
bool open (const char *hostname)
 
bool open (const char *address, int32_t len, int32_t type)
 
const char * getName ()
 
const char *const * getAliasList ()
 
int32_t getAddressType ()
 
int32_t getAddressLength ()
 
const char *const * getAddressList ()
 
char * getAddressString (int32_t index)
 
- Public Member Functions inherited from object
virtual ~object ()
 

Static Public Member Functions

static char * getAddressString (const char *hostname)
 
static char * getName (const char *address, int32_t len, int32_t type)
 
static char * getAddressString (const char *address, int32_t len, int32_t type)
 
static bool getNeedsMutex ()
 
static void setMutex (threadmutex *mtx)
 

Detailed Description

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

Constructor & Destructor Documentation

◆ hostentry()

hostentry::hostentry ( )

Creates an instance of the hostentry class.

◆ ~hostentry()

hostentry::~hostentry ( )

Deletes this instance of the hostentry class.

Member Function Documentation

◆ getAddressLength()

int32_t hostentry::getAddressLength ( )

Returns the address length of the host entry.

◆ getAddressList()

const char* const* hostentry::getAddressList ( )

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

◆ getAddressString() [1/3]

static char* hostentry::getAddressString ( const char *  address,
int32_t  len,
int32_t  type 
)
static

Convenience method. Returns 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 the return value is allocated internally and returned. The calling program must free the buffer.

Returns NULL if an error occurred or "address" is invalid.

◆ getAddressString() [2/3]

static char* hostentry::getAddressString ( const char *  hostname)
static

Convenience method. Returns the address of "hostname".

Note that the return value is allocated internally and returned. The calling program must free the buffer.

Returns NULL if an error occurred or "hostname" is invalid.

◆ getAddressString() [3/3]

char* hostentry::getAddressString ( int32_t  index)

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.

◆ getAddressType()

int32_t hostentry::getAddressType ( )

Returns the address type of the host entry.

◆ getAliasList()

const char* const* hostentry::getAliasList ( )

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

◆ getName() [1/2]

const char* hostentry::getName ( )

Returns the primary hostname of the host entry.

◆ getName() [2/2]

static char* hostentry::getName ( const char *  address,
int32_t  len,
int32_t  type 
)
static

Convenience method. Returns 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 the return value is allocated internally and returned. The calling program must free the buffer.

Returns NULL if an error occurred or "address" is invalid.

◆ getNeedsMutex()

static bool hostentry::getNeedsMutex ( )
static

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

◆ open() [1/2]

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

Opens 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.

◆ open() [2/2]

bool hostentry::open ( const char *  hostname)

Opens a host entry by name.

◆ setMutex()

static void hostentry::setMutex ( threadmutex mtx)
static

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