.\" Copyright (c) 1983,1987 Regents of the University of California.
.\" All rights reserved. The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\" @(#)gethostbyname.3 6.8 (Berkeley) %G%
gethostbyname, gethostbyaddr, gethostent, sethostent, endhostent \- get network host entry
.B "struct hostent *gethostbyname(name)
.B "struct hostent *gethostbyaddr(addr, len, type)
.B "char *addr; int len, type;
.B "struct hostent *gethostent()
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:
Official name of the host.
A zero terminated array of alternate names for the host.
The type of address being returned; currently always AF_INET.
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.
The first address in h_addr_list; 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 ``HOSTALAIASES''
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 TCP socket for queries.
this sets the option to send all queries to the name server using TCP
and to retain the connection after each call to
Otherwise, queries are performed using UDP datagrams.
closes the TCP connection.
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.
is non-NULL, it is printed, followed by a colon and a space.
The error message is printed with a trailing newline.
can have the following values:
.IP HOST_NOT_FOUND \w'HOST_NOT_FOUND'u+2n
.IP TRY_AGAIN \w'HOST_NOT_FOUND'u+2n
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.
.IP NO_RECOVERY \w'HOST_NOT_FOUND'u+2n
Some unexpected server failure was encountered.
This is a non-recoverable error.
.IP NO_ADDRESS \w'HOST_NOT_FOUND'u+2n
The 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 using this domain name
will result in an answer;
for example, a mail-forwarder may be registered for this domain.
resolver(3), hosts(5), hostname(7), named(8)
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.
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.