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