[Previous] [Contents] [Index] [Next]

gethostent_r()

Read the next line of the host database file

Synopsis:

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

struct hostent * gethostent_r( FILE ** hostf,
                               struct hostent * result,
                               char * buffer,
                               int buflen,
                               int * h_errnop );

Library:

socket3r.lib, socket3s.lib

Description:

The gethostent_r() function is a thread-safe version of the gethostent() function. This function gets the local host's entry. If the pointer pointed to by hostf is NULL, gethostent_r() opens /etc/hosts and returns its file pointer in hostf for later use. It's the calling process's responsibility to close the host file with fclose().


Note: The first call to gethostent_r() should pass NULL in the pointer pointed to by hostf.

The host entry is returned in the struct hostent pointed to by result. During the operation, buffer (and char buffer of at least buflen bytes) is used to store host database entries; buffer should be large enough to hold all of the data associated with the host entry. A 2K buffer is usually more than enough, and a 256 byte buffer is safe in most cases.

The int pointed to by h_errnop is set to an herrno value if an error occurs.

Returns:

A pointer to result, or NULL if an error occurs.

Errors:

If an error occurs, the int pointed to by h_errnop is set to:

ERANGE
The supplied buffer isn't large enough to store the result.
HOST_NOT_FOUND
Authoritative answer: Unknown host.
NO_ADDRESS
No address associated with name, look for an MX record.
NO_DATA
Valid name, no data record of the requested type. The name is known to the name server, but has no IP address associated with it-this isn't a temporary error. Another type of request to the name server using this domain name will result in an answer (e.g. a mail-forwarder may be registered for this domain).
NO_RECOVERY
Unknown server error. An unexpected server failure was encountered. This is a nonrecoverable network error.
TRY_AGAIN
Nonauthoritative answer: Host name lookup failure. This is usually a temporary error and means that the local server didn't receive a response from an authoritative server. A retry at some later time may succeed.

Files:

/etc/hosts
Local host database file.

Classification:

Unix

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

endhostent(), gethostent(), sethostent()


[Previous] [Contents] [Index] [Next]