return NO_DATA instead of HOST_NOT_FOUND from res_search
[unix-history] / usr / src / lib / libc / net / gethostbyname.3
CommitLineData
5cff1869 1.\" Copyright (c) 1983,1987 Regents of the University of California.
b9a6fdfb
KM
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
d97ed772 5.\" @(#)gethostbyname.3 6.8 (Berkeley) %G%
b9a6fdfb 6.\"
a7fb1b36 7.TH GETHOSTBYNAME 3N ""
b9a6fdfb
KM
8.UC 5
9.SH NAME
a7fb1b36 10gethostbyname, gethostbyaddr, gethostent, sethostent, endhostent \- get network host entry
b9a6fdfb
KM
11.SH SYNOPSIS
12.B "#include <netdb.h>
13.PP
a7fb1b36 14.B "extern int h_errno;
b9a6fdfb
KM
15.PP
16.B "struct hostent *gethostbyname(name)
17.br
18.B "char *name;
19.PP
20.B "struct hostent *gethostbyaddr(addr, len, type)
21.br
22.B "char *addr; int len, type;
23.PP
a7fb1b36
KD
24.B "struct hostent *gethostent()
25.PP
b9a6fdfb
KM
26.B "sethostent(stayopen)
27.br
92953539 28.B "int stayopen;
b9a6fdfb
KM
29.PP
30.B "endhostent()
92953539 31.PP
5cff1869
MK
32.B "herror(string)
33.br
34.B "char *string;
35.PP
b9a6fdfb 36.SH DESCRIPTION
a7fb1b36 37.I Gethostbyname
b9a6fdfb
KM
38and
39.I gethostbyaddr
40each return a pointer to an object with the
d97ed772
MK
41following structure describing an internet host
42referenced by name or by address, respectively.
a7fb1b36 43This structure contains either the information obtained from the name server,
576c34d8
JL
44.IR named (8),
45or broken-out fields from a line in
a7fb1b36
KD
46.IR /etc/hosts .
47If the local name server is not running these routines do a lookup in
48.IR /etc/hosts .
b9a6fdfb
KM
49.RS
50.PP
51.nf
52struct hostent {
53 char *h_name; /* official name of host */
54 char **h_aliases; /* alias list */
a7fb1b36 55 int h_addrtype; /* host address type */
b9a6fdfb 56 int h_length; /* length of address */
a7fb1b36 57 char **h_addr_list; /* list of addresses from name server */
b9a6fdfb 58};
a7fb1b36 59#define h_addr h_addr_list[0] /* address, for backward compatibility */
b9a6fdfb
KM
60.ft R
61.ad
62.fi
63.RE
64.PP
65The members of this structure are:
a7fb1b36 66.TP \w'h_addr_list'u+2n
b9a6fdfb
KM
67h_name
68Official name of the host.
a7fb1b36 69.TP \w'h_addr_list'u+2n
b9a6fdfb
KM
70h_aliases
71A zero terminated array of alternate names for the host.
a7fb1b36 72.TP \w'h_addr_list'u+2n
b9a6fdfb
KM
73h_addrtype
74The type of address being returned; currently always AF_INET.
a7fb1b36 75.TP \w'h_addr_list'u+2n
b9a6fdfb
KM
76h_length
77The length, in bytes, of the address.
a7fb1b36
KD
78.TP \w'h_addr_list'u+2n
79h_addr_list
80A zero terminated array of network addresses for the host.
81Host addresses are returned in network byte order.
82.TP \w'h_addr_list'u+2n
b9a6fdfb 83h_addr
a7fb1b36 84The first address in h_addr_list; this is for backward compatiblity.
b9a6fdfb 85.PP
d97ed772
MK
86When using the nameserver,
87.I gethostbyname
88will search for the named host in the current domain and its parents
89unless the name ends in a dot.
90If the name contains no dot, and if the environment variable ``HOSTALAIASES''
91contains the name of an alias file, the alias file will first be searched
92for an alias matching the input name.
93See
94.IR hostname (7)
95for the domain search procedure and the alias file format.
96.PP
b9a6fdfb 97.I Sethostent
d97ed772 98may be used to request the use of a connected TCP socket for queries.
a7fb1b36 99If the
b9a6fdfb
KM
100.I stayopen
101flag is non-zero,
a7fb1b36
KD
102this sets the option to send all queries to the name server using TCP
103and to retain the connection after each call to
16b80cdf 104.I gethostbyname
0d1b3ffd
JL
105or
106.IR gethostbyaddr .
d97ed772 107Otherwise, queries are performed using UDP datagrams.
b9a6fdfb
KM
108.PP
109.I Endhostent
a7fb1b36
KD
110closes the TCP connection.
111.SH DIAGNOSTICS
92953539 112.PP
a7fb1b36 113Error return status from
576c34d8 114.I gethostbyname
b9a6fdfb
KM
115and
116.I gethostbyaddr
a7fb1b36
KD
117is indicated by return of a null pointer.
118The external integer
119.IR h_errno
120may then be checked to see whether this is a temporary failure
121or an invalid or unknown host.
5cff1869
MK
122The routine
123.I herror
124can be used to print an error message describing the failure.
125If its argument
126.I string
127is non-NULL, it is printed, followed by a colon and a space.
128The error message is printed with a trailing newline.
a7fb1b36
KD
129.PP
130.IR h_errno
131can have the following values:
132.RS
133.IP HOST_NOT_FOUND \w'HOST_NOT_FOUND'u+2n
134No such host is known.
135.IP TRY_AGAIN \w'HOST_NOT_FOUND'u+2n
136This is usually a temporary error
137and means that the local server did not receive
138a response from an authoritative server.
139A retry at some later time may succeed.
140.IP NO_RECOVERY \w'HOST_NOT_FOUND'u+2n
5cff1869 141Some unexpected server failure was encountered.
a7fb1b36
KD
142This is a non-recoverable error.
143.IP NO_ADDRESS \w'HOST_NOT_FOUND'u+2n
144The requested name is valid but does not have an IP address;
145this is not a temporary error.
5cff1869
MK
146This means another type of request to the name server using this domain name
147will result in an answer;
148for example, a mail-forwarder may be registered for this domain.
a7fb1b36 149.RE
b9a6fdfb
KM
150.SH FILES
151/etc/hosts
152.SH "SEE ALSO"
5cff1869 153resolver(3), hosts(5), hostname(7), named(8)
a7fb1b36
KD
154.SH CAVEAT
155.PP
576c34d8 156.I Gethostent
a7fb1b36 157is defined, and
576c34d8
JL
158.I sethostent
159and
160.I endhostent
161are redefined,
a7fb1b36
KD
162when
163.IR libc
164is built to use only the routines to lookup in
165.IR /etc/hosts
166and not the name server.
167.PP
576c34d8 168.I Gethostent
a7fb1b36 169reads the next line of
576c34d8 170.IR /etc/hosts ,
a7fb1b36
KD
171opening the file if necessary.
172.PP
576c34d8
JL
173.I Sethostent
174is redefined to open and rewind the file. If the
a7fb1b36 175.I stayopen
576c34d8 176argument is non-zero,
a7fb1b36 177the hosts data base will not be closed after each call to
576c34d8 178.I gethostbyname
a7fb1b36 179or
576c34d8
JL
180.IR gethostbyaddr .
181.I Endhostent
182is redefined to close the file.
b9a6fdfb
KM
183.SH BUGS
184All information
185is contained in a static area
186so it must be copied if it is
187to be saved. Only the Internet
188address format is currently understood.