.\" Copyright (c) 1983, 1987, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" @(#)gethostbyname.3 8.1 (Berkeley) 6/4/93
.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.
opens and/or rewinds the file
the file will not be closed after each call to
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.