summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/gethostbyname.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/gethostbyname.3')
-rw-r--r--src/lib/libc/net/gethostbyname.3175
1 files changed, 98 insertions, 77 deletions
diff --git a/src/lib/libc/net/gethostbyname.3 b/src/lib/libc/net/gethostbyname.3
index bac0368296..d90ea55542 100644
--- a/src/lib/libc/net/gethostbyname.3
+++ b/src/lib/libc/net/gethostbyname.3
@@ -1,4 +1,4 @@
1.\" $NetBSD: gethostbyname.3,v 1.6 1995/02/25 06:20:28 cgd Exp $ 1.\" $OpenBSD: gethostbyname.3,v 1.17 2002/04/30 16:31:42 mpech Exp $
2.\" 2.\"
3.\" Copyright (c) 1983, 1987, 1991, 1993 3.\" Copyright (c) 1983, 1987, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
@@ -31,17 +31,17 @@
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE. 32.\" SUCH DAMAGE.
33.\" 33.\"
34.\" @(#)gethostbyname.3 8.2 (Berkeley) 4/19/94 34.Dd March 13, 1997
35.\"
36.Dd April 19, 1994
37.Dt GETHOSTBYNAME 3 35.Dt GETHOSTBYNAME 3
38.Os BSD 4.2 36.Os
39.Sh NAME 37.Sh NAME
40.Nm gethostbyname , 38.Nm gethostbyname ,
39.Nm gethostbyname2 ,
41.Nm gethostbyaddr , 40.Nm gethostbyaddr ,
42.Nm gethostent , 41.Nm gethostent ,
43.Nm sethostent , 42.Nm sethostent ,
44.Nm endhostent , 43.Nm endhostent ,
44.Nm hstrerror ,
45.Nm herror 45.Nm herror
46.Nd get network host entry 46.Nd get network host entry
47.Sh SYNOPSIS 47.Sh SYNOPSIS
@@ -50,30 +50,37 @@
50.Ft struct hostent * 50.Ft struct hostent *
51.Fn gethostbyname "const char *name" 51.Fn gethostbyname "const char *name"
52.Ft struct hostent * 52.Ft struct hostent *
53.Fn gethostbyaddr "const char *addr" "int len" "int type" 53.Fn gethostbyname2 "const char *name" "int af"
54.Ft struct hostent *
55.Fn gethostbyaddr "const char *addr" "int len" "int af"
54.Ft struct hostent * 56.Ft struct hostent *
55.Fn gethostent void 57.Fn gethostent void
58.Ft void
56.Fn sethostent "int stayopen" 59.Fn sethostent "int stayopen"
60.Ft void
57.Fn endhostent void 61.Fn endhostent void
58.Fn herror "char *string" 62.Ft void
63.Fn herror "const char *string"
64.Ft const char *
65.Fn hstrerror "int err"
59.Sh DESCRIPTION 66.Sh DESCRIPTION
60The 67The
61.Fn gethostbyname 68.Fn gethostbyname
62and 69and
63.Fn gethostbyaddr 70.Fn gethostbyaddr
64functions 71functions each return a pointer to an object with the following structure
65each return a pointer to an object with the 72describing an internet host referenced by name or by address, respectively.
66following structure describing an internet host 73This structure contains either information obtained from the name server (i.e.,
67referenced by name or by address, respectively. 74.Xr resolver 3
68This structure contains either the information obtained from the name server, 75and
69.Xr named 8 , 76.Xr named 8 ) ,
70broken-out fields from a line in 77broken-out fields from a line in
71.Pa /etc/hosts , 78.Pa /etc/hosts ,
72or database entries supplied by the 79or database entries supplied by the
73.Xr yp 8 80.Xr yp 8
74system . 81system.
75If the local name server is not running these routines do a lookup in 82.Xr resolv.conf 5
76.Pa /etc/hosts . 83describes how the particular database is chosen.
77.Bd -literal 84.Bd -literal
78struct hostent { 85struct hostent {
79 char *h_name; /* official name of host */ 86 char *h_name; /* official name of host */
@@ -90,36 +97,48 @@ The members of this structure are:
90.It Fa h_name 97.It Fa h_name
91Official name of the host. 98Official name of the host.
92.It Fa h_aliases 99.It Fa h_aliases
93A zero terminated array of alternate names for the host. 100A zero-terminated array of alternate names for the host.
94.It Fa h_addrtype 101.It Fa h_addrtype
95The type of address being returned; currently always 102The type of address being returned.
96.Dv AF_INET .
97.It Fa h_length 103.It Fa h_length
98The length, in bytes, of the address. 104The length, in bytes, of the address.
99.It Fa h_addr_list 105.It Fa h_addr_list
100A zero terminated array of network addresses for the host. 106A zero-terminated array of network addresses for the host.
101Host addresses are returned in network byte order. 107Host addresses are returned in network byte order.
102.It Fa h_addr 108.It Fa h_addr
103The first address in 109The first address in
104.Fa h_addr_list ; 110.Fa h_addr_list ;
105this is for backward compatibility. 111this is for backward compatibility.
112.El
106.Pp 113.Pp
107When using the nameserver, 114The function
108.Fn gethostbyname 115.Fn gethostbyname
109will search for the named host in the current domain and its parents 116will search for the named host in the current domain and its parents
110unless the name ends in a dot. 117using the search lookup semantics detailed in
111If the name contains no dot, and if the environment variable 118.Xr resolv.conf 5
112.Dq Ev HOSTALIASES 119and
113contains the name of an alias file, the alias file will first be searched 120.Xr hostname 7 .
114for an alias matching the input name. 121.Pp
115See 122.Fn gethostbyname2
116.Xr hostname 7 123is an advanced form of
117for the domain search procedure and the alias file format. 124.Fn gethostbyname
125which allows lookups in address families other than
126.Dv AF_INET ,
127for example
128.Dv AF_INET6 .
129.Pp
130The
131.Fn gethostbyaddr
132function will search for the specified address of length
133.Fa len
134in the address family
135.Fa af .
136The only address family currently supported is
137.Dv AF_INET .
118.Pp 138.Pp
119The 139The
120.Fn sethostent 140.Fn sethostent
121function 141function may be used to request the use of a connected
122may be used to request the use of a connected
123.Tn TCP 142.Tn TCP
124socket for queries. 143socket for queries.
125If the 144If the
@@ -127,7 +146,7 @@ If the
127flag is non-zero, 146flag is non-zero,
128this sets the option to send all queries to the name server using 147this sets the option to send all queries to the name server using
129.Tn TCP 148.Tn TCP
130and to retain the connection after each call to 149and to retain the connection after each call to
131.Fn gethostbyname 150.Fn gethostbyname
132or 151or
133.Fn gethostbyaddr . 152.Fn gethostbyaddr .
@@ -137,17 +156,33 @@ datagrams.
137.Pp 156.Pp
138The 157The
139.Fn endhostent 158.Fn endhostent
140function 159function closes the
141closes the
142.Tn TCP 160.Tn TCP
143connection. 161connection.
162.Pp
163The
164.Fn herror
165function prints an error message describing the failure.
166If its argument
167.Fa string
168is non-null,
169it is prepended to the message string and separated from it by a colon
170.Pq Ql \&:
171and a space.
172The error message is printed with a trailing newline.
173The contents of the error message is the same as that returned by
174.Fn hstrerror
175with argument
176.Fa h_errno .
144.Sh FILES 177.Sh FILES
145.Bl -tag -width /etc/hosts -compact 178.Bl -tag -width /etc/resolv.conf -compact
146.It Pa /etc/hosts 179.It Pa /etc/hosts
180.It Pa /etc/resolv.conf
147.El 181.El
148.Sh DIAGNOSTICS 182.Sh DIAGNOSTICS
149Error return status from 183Error return status from
150.Fn gethostbyname 184.Fn gethostbyname ,
185.Fn gethostbyname2 ,
151and 186and
152.Fn gethostbyaddr 187.Fn gethostbyaddr
153is indicated by return of a null pointer. 188is indicated by return of a null pointer.
@@ -155,15 +190,6 @@ The external integer
155.Va h_errno 190.Va h_errno
156may then be checked to see whether this is a temporary failure 191may then be checked to see whether this is a temporary failure
157or an invalid or unknown host. 192or an invalid or unknown host.
158The routine
159.Fn herror
160can be used to print an error message describing the failure.
161If its argument
162.Fa string
163is
164.Pf non Dv -NULL ,
165it is printed, followed by a colon and a space.
166The error message is printed with a trailing newline.
167.Pp 193.Pp
168The variable 194The variable
169.Va h_errno 195.Va h_errno
@@ -180,8 +206,8 @@ A retry at some later time may succeed.
180Some unexpected server failure was encountered. 206Some unexpected server failure was encountered.
181This is a non-recoverable error. 207This is a non-recoverable error.
182.It Dv NO_DATA 208.It Dv NO_DATA
183The requested name is valid but does not have an IP address; 209The requested name is valid but does not have an IP address;
184this is not a temporary error. 210this is not a temporary error.
185This means that the name is known to the name server but there is no address 211This means that the name is known to the name server but there is no address
186associated with this name. 212associated with this name.
187Another type of request to the name server using this domain name 213Another type of request to the name server using this domain name
@@ -190,52 +216,42 @@ for example, a mail-forwarder may be registered for this domain.
190.El 216.El
191.Sh SEE ALSO 217.Sh SEE ALSO
192.Xr resolver 3 , 218.Xr resolver 3 ,
219.Xr getaddrinfo 3 ,
220.Xr getnameinfo 3 ,
193.Xr hosts 5 , 221.Xr hosts 5 ,
222.Xr resolv.conf 5 ,
194.Xr hostname 7 , 223.Xr hostname 7 ,
195.Xr named 8 224.Xr named 8
196.Sh CAVEAT 225.Sh CAVEATS
197The 226If the search routines in
198.Fn gethostent 227.Xr resolv.conf 5
199function 228decide to read the
200is defined, and
201.Fn sethostent
202and
203.Fn endhostent
204are redefined,
205when
206.Xr libc 3
207is built to use only the routines to lookup in
208.Pa /etc/hosts 229.Pa /etc/hosts
209and not the name server. 230file,
210.Pp
211The
212.Fn gethostent 231.Fn gethostent
213function 232and other functions will
214reads the next line of 233read the next line of the file,
215.Pa /etc/hosts , 234re-opening the file if necessary.
216opening the file if necessary.
217.Pp 235.Pp
218The 236The
219.Fn sethostent 237.Fn sethostent
220function 238function opens and/or rewinds the file
221opens and/or rewinds the file
222.Pa /etc/hosts . 239.Pa /etc/hosts .
223If the 240If the
224.Fa stayopen 241.Fa stayopen
225argument is non-zero, 242argument is non-zero, the file will not be closed after each call to
226the file will not be closed after each call to 243.Fn gethostbyname ,
227.Fn gethostbyname 244.Fn gethostbyname2 ,
228or 245or
229.Fn gethostbyaddr . 246.Fn gethostbyaddr .
230.Pp 247.Pp
231The 248The
232.Fn endhostent 249.Fn endhostent
233function 250function closes the file.
234closes the file.
235.Sh HISTORY 251.Sh HISTORY
236The 252The
237.Fn herror 253.Fn herror
238function appeared in 254function appeared in
239.Bx 4.3 . 255.Bx 4.3 .
240The 256The
241.Fn endhostent , 257.Fn endhostent ,
@@ -251,4 +267,9 @@ These functions use static data storage;
251if the data is needed for future use, it should be 267if the data is needed for future use, it should be
252copied before any subsequent calls overwrite it. 268copied before any subsequent calls overwrite it.
253Only the Internet 269Only the Internet
254address format is currently understood. 270address formats are currently understood.
271.Pp
272YP does not support any address families other than
273.Dv AF_INET
274and uses
275the traditional database format.