gethostbyaddr()

The gethostbyaddr() call returns a pointer to information about a host specified by an internet address.

Syntax

#include <netdb.h>
struct hostent *gethostbyaddr(addr, addrlen, addrfam)
char *addr;
int addrlen;
int addrfam;

Parameters

addr

addrlen addrfam

Description

This call resolves the host name through a name server, if one is present. If a name server is not present or cannot resolve the host name, gethostbyaddr() uses the default name services ordering: first it queries DNS/BIND, then it searches the ETC\HOSTS file in sequence until a matching host address is found or an end-of-file (EOF) marker is reached. This search order can be reversed by adding the following statement in your CONFIG.SYS file:

SET USE_HOSTS_FIRST=1

When using DNS/BIND name service resolution, if the ETC\RESOLV file exists the gethostbyaddr() call queries the domain name server. The gethostbyaddr() call recognizes domain name servers as described in RFC 883.

The gethostbyaddr() call also searches the local ETC\HOSTS file when indicated to do so.

The gethostbyaddr() call returns a pointer to a hostent structure, which contains information obtained from one of the name resolutions services. The hostent structure is defined in the <NETDB.H> file.

Return Values

The return value points to static data that subsequent API calls can modify. This call returns a pointer to a hostent structure for the host address specified on the call and indicates success. A NULL pointer indicates an error.

The <NETDB.H> header file defines the hostent structure and contains the following elements:

Element

h _ name h _ aliases h _ addrtype h _ length h _ addr

The value of h_errno indicates the specific error.

 h_errno Value   Code  Description

 NETDB_INTERNAL   -1   Generic error value. Call sock_errno() or
                       psock_errno() to get a more detailed error
                       code (or error message).

 HOST_NOT_FOUND   1    The host specified by the addr parameter is
                       not found.

 TRY_AGAIN        2    The local server does not receive a response
                       from an authorized server. Try again later.

 NO_RECOVERY      3    This error code indicates an unrecoverable
                       error.

 NO_DATA          4    The requested addr is valid, but does not
                       have an Internet address at the name server.

 NO_ADDRESS       4    The requested addr is valid, but does not
                       have an Internet address at the name server.

Related Calls


[Back: endservent()]
[Next: gethostbyname()]