.\" Copyright (c) 1983 Regents of the University of California.
.\" All rights reserved. The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\" @(#)gethostbyname.3 6.6 (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
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.
allows a request for the use of a connected socket using TCP 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
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 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
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.
of request to the name server will result in an answer.
hosts(5), resolver(3), 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.