.\" Copyright (c) 1983, 1987, 1991 The Regents of the University of California.
.\" %sccs.include.redist.man%
.\" @(#)gethostbyname.3 6.14 (Berkeley) %G%
.Nd get network host entry
.Fd extern struct h_errno;
.Fn gethostbyname "char *name"
.Fn gethostbyaddr "char *addr" "int len" "int type"
.Fn sethostent "int stayopen"
.Fn herror "char *string"
each return a pointer to an object with the
following structure describing an internet host
referenced by name or by address, respectively.
This structure contains either the information obtained from the name server,
or broken-out fields from a line in
If the local name server is not running these routines do a lookup in
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses from name server */
#define h_addr h_addr_list[0] /* address, for backward compatibility */
The members of this structure are:
.Bl -tag -width h_addr_list
Official name of the host.
A zero terminated array of alternate names for the host.
The type of address being returned; currently always
The length, in bytes, of the address.
A zero terminated array of network addresses for the host.
Host addresses are returned in network byte order.
this is for backward compatiblity.
When using the nameserver,
will search for the named host in the current domain and its parents
unless the name ends in a dot.
If the name contains no dot, and if the environment variable
contains the name of an alias file, the alias file will first be searched
for an alias matching the input name.
for the domain search procedure and the alias file format.
may be used to request the use of a connected
this sets the option to send all queries to the name server using
and to retain the connection after each call to
Otherwise, queries are performed using
.Bl -tag -width /etc/hosts -compact
is indicated by return of a null pointer.
may then be checked to see whether this is a temporary failure
or an invalid or unknown host.
can be used to print an error message describing the failure.
it is printed, followed by a colon and a space.
The error message is printed with a trailing newline.
can have the following values:
.Bl -tag -width HOST_NOT_FOUND
This 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.
Some unexpected server failure was encountered.
This is a non-recoverable error.
The requested name is valid but does not have an IP address;
this is not a temporary error.
This means that the name is known to the name server but there is no address
associated with this name.
Another type of request to the name server using this domain name
will result in an answer;
for example, a mail-forwarder may be registered for this domain.
is built to use only the routines to lookup in
opening the file if necessary.
is redefined to open and rewind the file. If the
the hosts data base will not be closed after each call to
is redefined to close the file.
These functions use static data storage;
if the data is needed for future use, it should be
copied before any subsequent calls overwrite it.
address format is currently understood.