summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/resolver.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/resolver.3')
-rw-r--r--src/lib/libc/net/resolver.3345
1 files changed, 345 insertions, 0 deletions
diff --git a/src/lib/libc/net/resolver.3 b/src/lib/libc/net/resolver.3
new file mode 100644
index 0000000000..4d5402ed2d
--- /dev/null
+++ b/src/lib/libc/net/resolver.3
@@ -0,0 +1,345 @@
1.\" $OpenBSD: resolver.3,v 1.15 2001/04/03 20:09:08 aaron Exp $
2.\"
3.\" Copyright (c) 1985, 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 June 4, 1993
35.Dt RESOLVER 3
36.Os
37.Sh NAME
38.Nm res_query ,
39.Nm res_search ,
40.Nm res_mkquery ,
41.Nm res_send ,
42.Nm res_init ,
43.Nm dn_comp ,
44.Nm dn_expand
45.Nd resolver routines
46.Sh SYNOPSIS
47.Fd #include <sys/types.h>
48.Fd #include <netinet/in.h>
49.Fd #include <arpa/nameser.h>
50.Fd #include <resolv.h>
51.Ft int
52.Fo res_query
53.Fa "char *dname"
54.Fa "int class"
55.Fa "int type"
56.Fa "u_char *answer"
57.Fa "int anslen"
58.Fc
59.Ft int
60.Fo res_search
61.Fa "char *dname"
62.Fa "int class"
63.Fa "int type"
64.Fa "u_char *answer"
65.Fa "int anslen"
66.Fc
67.Ft int
68.Fo res_mkquery
69.Fa "int op"
70.Fa "char *dname"
71.Fa "int class"
72.Fa "int type"
73.Fa "char *data"
74.Fa "int datalen"
75.Fa "struct rrec *newrr"
76.Fa "char *buf"
77.Fa "int buflen"
78.Fc
79.Ft int
80.Fo res_send
81.Fa "char *msg"
82.Fa "int msglen"
83.Fa "char *answer"
84.Fa "int anslen"
85.Fc
86.Ft int
87.Fn res_init "void"
88.Ft int
89.Fo dn_comp
90.Fa "char *exp_dn"
91.Fa "char *comp_dn"
92.Fa "int length"
93.Fa "char **dnptrs"
94.Fa "char **lastdnptr"
95.Fc
96.Ft int
97.Fo dn_expand
98.Fa "u_char *msg"
99.Fa "u_char *eomorig"
100.Fa "u_char *comp_dn"
101.Fa "u_char *exp_dn"
102.Fa "int length"
103.Fc
104.Sh DESCRIPTION
105These routines are used for making, sending, and interpreting
106query and reply messages with Internet domain name servers.
107.Pp
108Global configuration and state information that is used by the
109resolver routines is kept in the structure
110.Li _res .
111Most of the values have reasonable defaults and can be ignored.
112Options stored in
113.Li _res.options
114are defined in
115.Aq Pa resolv.h
116and are as follows.
117Options are stored as a simple bit mask containing the bitwise
118.Tn OR
119of the options enabled.
120.Bl -tag -width RES_USE_INET6
121.It Dv RES_INIT
122True if the initial name server address and default domain name are
123initialized (i.e.,
124.Fn res_init
125has been called).
126.It Dv RES_DEBUG
127Print debugging messages.
128.It Dv RES_AAONLY
129Accept authoritative answers only.
130With this option,
131.Fn res_send
132should continue until it finds an authoritative answer or finds an error.
133Currently this is not implemented.
134.It Dv RES_USEVC
135Use
136.Tn TCP
137connections for queries instead of
138.Tn UDP
139datagrams.
140.It Dv RES_STAYOPEN
141Used with
142.Dv RES_USEVC
143to keep the
144.Tn TCP
145connection open between queries.
146This is useful only in programs that regularly do many queries.
147.Tn UDP
148should be the normal mode used.
149.It Dv RES_IGNTC
150Unused currently (ignore truncation errors, i.e., don't retry with
151.Tn TCP ) .
152.It Dv RES_RECURSE
153Set the recursion-desired bit in queries.
154This is the default.
155.Pf ( Fn res_send
156does not do iterative queries and expects the name server
157to handle recursion.)
158.It Dv RES_DEFNAMES
159If set,
160.Fn res_search
161will append the default domain name to single-component names
162(those that do not contain a dot).
163This option is enabled by default.
164.It Dv RES_DNSRCH
165If this option is set,
166.Fn res_search
167will search for host names in the current domain and in parent domains; see
168.Xr hostname 7 .
169This is used by the standard host lookup routine
170.Xr gethostbyname 3 .
171This option is enabled by default.
172.It Dv RES_USE_INET6
173Enables support for IPv6-only applications.
174This causes IPv4 addresses to be returned as an IPv4 mapped address.
175For example, 10.1.1.1 will be returned as ::ffff:10.1.1.1.
176The option is not meaningful on
177.Ox .
178.El
179.Pp
180The
181.Fn res_init
182routine reads the configuration file (if any; see
183.Xr resolv.conf 5 )
184to get the default domain name, search list, and the Internet address
185of the local name server(s).
186If no server is configured, the host running
187the resolver is tried.
188The current domain name is defined by the hostname
189if not specified in the configuration file;
190it can be overridden by the environment variable
191.Ev LOCALDOMAIN .
192This environment variable may contain several blank-separated
193tokens if you wish to override the
194.Fa search list
195on a per-process basis.
196This is similar to the
197.Fa search
198command in the configuration file.
199Another environment variable
200.Ev RES_OPTIONS
201can be set to override certain internal resolver options which
202are otherwise set by changing fields in the
203.Fa _res
204structure or are inherited from the configuration file's
205.Fa options
206command.
207The syntax of the
208.Ev RES_OPTIONS
209environment variable is explained in
210.Xr resolv.conf 5 .
211Initialization normally occurs on the first call
212to one of the following routines.
213.Pp
214The
215.Fn res_query
216function provides an interface to the server query mechanism.
217It constructs a query, sends it to the local server,
218awaits a response, and makes preliminary checks on the reply.
219The query requests information of the specified
220.Fa type
221and
222.Fa class
223for the specified fully qualified domain name
224.Fa dname .
225The reply message is left in the
226.Fa answer
227buffer with length
228.Fa anslen
229supplied by the caller.
230.Pp
231The
232.Fn res_search
233routine makes a query and awaits a response like
234.Fn res_query ,
235but in addition, it implements the default and search rules controlled by the
236.Dv RES_DEFNAMES
237and
238.Dv RES_DNSRCH
239options.
240It returns the first successful reply.
241.Pp
242The remaining routines are lower-level routines used by
243.Fn res_query .
244The
245.Fn res_mkquery
246function constructs a standard query message and places it in
247.Fa buf .
248It returns the size of the query, or \-1 if the query is larger than
249.Fa buflen .
250The query type
251.Fa op
252is usually
253.Dv QUERY ,
254but can be any of the query types defined in
255.Aq Pa arpa/nameser.h .
256The domain name for the query is given by
257.Fa dname .
258.Fa newrr
259is currently unused but is intended for making update messages.
260.Pp
261The
262.Fn res_send
263routine sends a pre-formatted query and returns an answer.
264It will call
265.Fn res_init
266if
267.Dv RES_INIT
268is not set, send the query to the local name server, and
269handle timeouts and retries.
270The length of the reply message is returned, or \-1 if there were errors.
271.Pp
272The
273.Fn dn_comp
274function compresses the domain name
275.Fa exp_dn
276and stores it in
277.Fa comp_dn .
278The size of the compressed name is returned or \-1 if there were errors.
279The size of the array pointed to by
280.Fa comp_dn
281is given by
282.Fa length .
283The compression uses an array of pointers
284.Fa dnptrs
285to previously compressed names in the current message.
286The first pointer points
287to the beginning of the message and the list ends with
288.Dv NULL .
289The limit to the array is specified by
290.Fa lastdnptr .
291A side effect of
292.Fn dn_comp
293is to update the list of pointers for labels inserted into the message
294as the name is compressed.
295If
296.Em dnptr
297is
298.Dv NULL ,
299names are not compressed.
300If
301.Fa lastdnptr
302is
303.Dv NULL ,
304the list of labels is not updated.
305.Pp
306The
307.Fn dn_expand
308entry expands the compressed domain name
309.Fa comp_dn
310to a full domain name
311The compressed name is contained in a query or reply message;
312.Fa msg
313is a pointer to the beginning of the message.
314The uncompressed name is placed in the buffer indicated by
315.Fa exp_dn
316which is of size
317.Fa length .
318The size of compressed name is returned or \-1 if there was an error.
319.Sh FILES
320.Bl -tag -width Pa
321/etc/resolv.conf
322configuration file
323see
324.Xr resolv.conf 5 .
325.El
326.Sh SEE ALSO
327.Xr gethostbyname 3 ,
328.Xr resolv.conf 5 ,
329.Xr hostname 7 ,
330.Xr named 8
331.Pp
332.%T RFC1032 ,
333.%T RFC1033 ,
334.%T RFC1034 ,
335.%T RFC1035 ,
336.%T RFC1535 ,
337.%T RFC974
338.Rs
339.%T "Name Server Operations Guide for BIND"
340.Re
341.Sh HISTORY
342The
343.Nm
344function appeared in
345.Bx 4.3 .