GETHOSTBYNAME(3N) — UNIX Programmer’s Manual
NAME
gethostbyname, gethostbyaddr, gethostent, sethostent, endhostent − get network host entry
SYNOPSIS
#include <netdb.h>
extern int h_errno;
struct hostent ∗gethostbyname(name)
char ∗name;
struct hostent ∗gethostbyaddr(addr, len, type)
char ∗addr; int len, type;
struct hostent ∗gethostent()
sethostent(stayopen)
int stayopen;
endhostent()
DESCRIPTION
Gethostbyname and gethostbyaddr each return a pointer to an object with the following structure. This structure contains either the information obtained from a name server, such as netinfod(8), named(8), or ypserv(8) or broken-out fields from a line in /etc/hosts.
If NetInfo is not running these routines do a lookup in /etc/hosts.
structhostent {
char∗h_name;/∗ official name of host ∗/
char∗∗h_aliases;/∗ alias list ∗/
inth_addrtype;/∗ host address type ∗/
inth_length;/∗ length of address ∗/
char∗∗h_addr_list;/∗ list of addresses from name server ∗/
};
#defineh_addr h_addr_list[0]/∗ address, for backward compatibility ∗/
The members of this structure are:
h_name Official name of the host.
h_aliases A zero terminated array of alternate names for the host.
h_addrtype The type of address being returned; currently always AF_INET.
h_length The length, in bytes, of the address.
h_addr_list A zero terminated array of network addresses for the host. Host addresses are returned in network byte order.
h_addr The first address in h_addr_list; this is for backward compatiblity.
DIAGNOSTICS
Error return status from gethostbyname and gethostbyaddr is indicated by return of a null pointer. The external integer h_errno may then be checked to see whether this is a temporary failure or an invalid or unknown host.
h_errno can have the following values:
HOST_NOT_FOUNDNo such host is known.
TRY_AGAINThis is usually a temporary error and means that the local server did not receive a response from an authoritative server. A retry at some later time may succeed.
NO_RECOVERYThis is a non-recoverable error.
NO_ADDRESSThe requested name is valid but does not have an IP address; this is not a temporary error. This means another type of request to the name server will result in an answer.
FILES
/etc/hosts - if NetInfo is not running
SEE ALSO
hosts(5), resolver(3), named(8), netinfo(5)
BUGS
All information is contained in a static area so it must be copied if it is to be saved. Only the Internet address format is currently understood.
4.2 Berkeley Distribution — May 20, 1986