summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/gethostbyname.3
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>1999-03-26 18:24:03 +0000
committercvs2svn <admin@example.com>1999-03-26 18:24:03 +0000
commit3fc228fb4c1a39aceaee3d7013365042a6077bd0 (patch)
treeaf769f6648929b3b2c1f9e053a3754fa989ce302 /src/lib/libc/net/gethostbyname.3
parent536c76cbb863bab152f19842ab88772c01e922c7 (diff)
downloadopenbsd-OPENBSD_2_5.tar.gz
openbsd-OPENBSD_2_5.tar.bz2
openbsd-OPENBSD_2_5.zip
This commit was manufactured by cvs2git to create branch 'OPENBSD_2_5'.OPENBSD_2_5
Diffstat (limited to 'src/lib/libc/net/gethostbyname.3')
-rw-r--r--src/lib/libc/net/gethostbyname.3266
1 files changed, 266 insertions, 0 deletions
diff --git a/src/lib/libc/net/gethostbyname.3 b/src/lib/libc/net/gethostbyname.3
new file mode 100644
index 0000000000..e28fed361c
--- /dev/null
+++ b/src/lib/libc/net/gethostbyname.3
@@ -0,0 +1,266 @@
1.\" $OpenBSD: gethostbyname.3,v 1.10 1999/02/27 21:55:27 deraadt Exp $
2.\"
3.\" Copyright (c) 1983, 1987, 1991, 1993
4.\" The Regents of the University of California. All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd March 13, 1997
35.Dt GETHOSTBYNAME 3
36.Os
37.Sh NAME
38.Nm gethostbyname ,
39.Nm gethostbyname2 ,
40.Nm gethostbyaddr ,
41.Nm gethostent ,
42.Nm sethostent ,
43.Nm endhostent ,
44.Nm hstrerror ,
45.Nm herror
46.Nd get network host entry
47.Sh SYNOPSIS
48.Fd #include <netdb.h>
49.Fd extern int h_errno;
50.Ft struct hostent *
51.Fn gethostbyname "const char *name"
52.Ft struct hostent *
53.Fn gethostbyname2 "const char *name" "int af"
54.Ft struct hostent *
55.Fn gethostbyaddr "const char *addr" "int len" "int type"
56.Ft struct hostent *
57.Fn gethostent void
58.Ft void
59.Fn sethostent "int stayopen"
60.Ft void
61.Fn endhostent void
62.Ft void
63.Fn herror "const char *string"
64.Ft const char *
65.Fn hstrerror "int err"
66.Sh DESCRIPTION
67The
68.Fn gethostbyname
69and
70.Fn gethostbyaddr
71functions
72each return a pointer to an object with the
73following structure describing an internet host
74referenced by name or by address, respectively.
75This structure contains either the information obtained from the name server,
76.Xr named 8 ,
77broken-out fields from a line in
78.Pa /etc/hosts ,
79or database entries supplied by the
80.Xr yp 8
81system .
82If the local name server is not running these routines do a lookup in
83.Pa /etc/hosts .
84.Bd -literal
85struct hostent {
86 char *h_name; /* official name of host */
87 char **h_aliases; /* alias list */
88 int h_addrtype; /* host address type */
89 int h_length; /* length of address */
90 char **h_addr_list; /* list of addresses from name server */
91};
92#define h_addr h_addr_list[0] /* address, for backward compatibility */
93.Ed
94.Pp
95The members of this structure are:
96.Bl -tag -width h_addr_list
97.It Fa h_name
98Official name of the host.
99.It Fa h_aliases
100A zero terminated array of alternate names for the host.
101.It Fa h_addrtype
102The type of address being returned.
103.It Fa h_length
104The length, in bytes, of the address.
105.It Fa h_addr_list
106A zero terminated array of network addresses for the host.
107Host addresses are returned in network byte order.
108.It Fa h_addr
109The first address in
110.Fa h_addr_list ;
111this is for backward compatibility.
112.El
113.Pp
114When using the nameserver,
115.Fn gethostbyname
116will search for the named host in the current domain and its parents
117unless the name ends in a dot.
118If the name contains no dot, and if the environment variable
119.Dq Ev HOSTALIASES
120contains the name of an alias file, the alias file will first be searched
121for an alias matching the input name.
122See
123.Xr hostname 7
124for the domain search procedure and the alias file format.
125.Pp
126.Fn gethostbyname2
127is an advanced form of
128.Fn gethostbyname
129which allows lookups in address families other than
130.Dv AF_INET ,
131for example
132.Dv AF_INET6 .
133.Pp
134The
135.Fn sethostent
136function
137may be used to request the use of a connected
138.Tn TCP
139socket for queries.
140If the
141.Fa stayopen
142flag is non-zero,
143this sets the option to send all queries to the name server using
144.Tn TCP
145and to retain the connection after each call to
146.Fn gethostbyname
147or
148.Fn gethostbyaddr .
149Otherwise, queries are performed using
150.Tn UDP
151datagrams.
152.Pp
153The
154.Fn endhostent
155function
156closes the
157.Tn TCP
158connection.
159.Pp
160The
161.Fn herror
162function prints an error message describing the failure. If its argument
163.Fa string
164is
165.Pf non Dv -NULL ,
166it is prepended to the message string and separated from it by a colon
167and a space. The error message is printed with a trailing newline.
168The contents of the error message is the same as that returned by
169.Fn hstrerror
170with argument
171.Fa h_errno .
172.Sh FILES
173.Bl -tag -width /etc/hosts -compact
174.It Pa /etc/hosts
175.El
176.Sh DIAGNOSTICS
177Error return status from
178.Fn gethostbyname ,
179.Fn gethostbyname2 ,
180and
181.Fn gethostbyaddr
182is indicated by return of a null pointer.
183The external integer
184.Va h_errno
185may then be checked to see whether this is a temporary failure
186or an invalid or unknown host.
187.Pp
188The variable
189.Va h_errno
190can have the following values:
191.Bl -tag -width HOST_NOT_FOUND
192.It Dv HOST_NOT_FOUND
193No such host is known.
194.It Dv TRY_AGAIN
195This is usually a temporary error
196and means that the local server did not receive
197a response from an authoritative server.
198A retry at some later time may succeed.
199.It Dv NO_RECOVERY
200Some unexpected server failure was encountered.
201This is a non-recoverable error.
202.It Dv NO_DATA
203The requested name is valid but does not have an IP address;
204this is not a temporary error.
205This means that the name is known to the name server but there is no address
206associated with this name.
207Another type of request to the name server using this domain name
208will result in an answer;
209for example, a mail-forwarder may be registered for this domain.
210.El
211.Sh SEE ALSO
212.Xr resolver 3 ,
213.Xr hosts 5 ,
214.Xr hostname 7 ,
215.Xr named 8
216.Sh CAVEAT
217The
218.Fn gethostent
219function
220reads the next line of
221.Pa /etc/hosts ,
222opening the file if necessary.
223.Pp
224The
225.Fn sethostent
226function
227opens and/or rewinds the file
228.Pa /etc/hosts .
229If the
230.Fa stayopen
231argument is non-zero,
232the file will not be closed after each call to
233.Fn gethostbyname ,
234.Fn gethostbyname2 ,
235or
236.Fn gethostbyaddr .
237.Pp
238The
239.Fn endhostent
240function
241closes the file.
242.Sh HISTORY
243The
244.Fn herror
245function appeared in
246.Bx 4.3 .
247The
248.Fn endhostent ,
249.Fn gethostbyaddr ,
250.Fn gethostbyname ,
251.Fn gethostent ,
252and
253.Fn sethostent
254functions appeared in
255.Bx 4.2 .
256.Sh BUGS
257These functions use static data storage;
258if the data is needed for future use, it should be
259copied before any subsequent calls overwrite it.
260Only the Internet
261address formats are currently understood.
262.Pp
263YP does not support any address families other than
264.Dv AF_INET
265and uses
266the traditional database format.