gethostbyaddr_r()

Get a network host entry, in a thread-safe manner

Synopsis:

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

struct hostent * gethostbyaddr_r(
                    const void * addr,
                    socklen_t length,
                    int type,
                    struct hostent * result,
                    char * buffer,
                    int buflen,
                    int * h_errnop );

Arguments:

addr
A pointer to the binary-format (i.e., not NULL-terminated) address in network byte order.
length
The length, in bytes, of addr.
type
The type of address. Currently, this must be AF_INET.
result
A pointer to a struct hostent where the function can store the host entry.
buffer
A pointer to a buffer that the function can use during the operation to store host database entries; buffer should be large enough to hold all of the data associated with the host entry. A 2 KB buffer is usually more than enough; a 256-byte buffer is safe in most cases.
buflen
The length of the area pointed to by buffer.
h_errnop
A pointer to a location where the function can store an herrno value if an error occurs.

Library:

libsocket

Use the -l socket option to qcc to link against this library.

Description:

The gethostbyaddr_r() function is a thread-safe version of gethostbyaddr(). This function gets the network host entry for the host specified by addr. The addr argument is the network address of the specified network family, type. The buffer for addr is at least length bytes.

If you need to convert a text-based address into the format necessary for use as gethostbyaddr_r()'s addr, see inet_pton().

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, but 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.
/etc/nsswitch.conf
Name-service switch configuration file.

Classification:

Unix

Safety:  
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes