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