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.3354
1 files changed, 354 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..e820ea25ed
--- /dev/null
+++ b/src/lib/libc/net/resolver.3
@@ -0,0 +1,354 @@
1.\" $OpenBSD: resolver.3,v 1.21 2007/05/31 19:19:30 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 $Mdocdate: May 31 2007 $
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 "const char *dname"
50.Fa "int class"
51.Fa "int type"
52.Fa "unsigned char *answer"
53.Fa "int anslen"
54.Fc
55.Ft int
56.Fo res_search
57.Fa "const char *dname"
58.Fa "int class"
59.Fa "int type"
60.Fa "unsigned char *answer"
61.Fa "int anslen"
62.Fc
63.Ft int
64.Fo res_mkquery
65.Fa "int op"
66.Fa "const char *dname"
67.Fa "int class"
68.Fa "int type"
69.Fa "const unsigned char *data"
70.Fa "int datalen"
71.Fa "const unsigned char *newrr"
72.Fa "unsigned char *buf"
73.Fa "int buflen"
74.Fc
75.Ft int
76.Fo res_send
77.Fa "const unsigned char *msg"
78.Fa "int msglen"
79.Fa "unsigned 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 "const char *exp_dn"
87.Fa "unsigned char *comp_dn"
88.Fa "int length"
89.Fa "unsigned char **dnptrs"
90.Fa "unsigned char **lastdnptr"
91.Fc
92.Ft int
93.Fo dn_expand
94.Fa "const unsigned char *msg"
95.Fa "const unsigned char *eomorig"
96.Fa "const unsigned char *comp_dn"
97.Fa "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.It Dv RES_USE_EDNS0
175Enables support for OPT pseudo-RR for EDNS0 extension.
176With this option, resolver code will attach OPT pseudo-RR into DNS queries,
177to inform of our receive buffer size.
178The option will allow DNS servers to take advantage of non-default receive
179buffer size, and to send larger replies.
180DNS query packets with EDNS0 extension is not compatible with
181non-EDNS0 DNS servers.
182.El
183.Pp
184The
185.Fn res_init
186routine reads the configuration file (if any; see
187.Xr resolv.conf 5 )
188to get the default domain name, search list, and the Internet address
189of the local name server(s).
190If no server is configured, the host running
191the resolver is tried.
192The current domain name is defined by the hostname
193if not specified in the configuration file;
194it can be overridden by the environment variable
195.Ev LOCALDOMAIN .
196This environment variable may contain several blank-separated
197tokens if you wish to override the
198.Fa search list
199on a per-process basis.
200This is similar to the
201.Fa search
202command in the configuration file.
203Another environment variable
204.Ev RES_OPTIONS
205can be set to override certain internal resolver options which
206are otherwise set by changing fields in the
207.Fa _res
208structure or are inherited from the configuration file's
209.Fa options
210command.
211The syntax of the
212.Ev RES_OPTIONS
213environment variable is explained in
214.Xr resolv.conf 5 .
215Initialization normally occurs on the first call
216to one of the following routines.
217.Pp
218The
219.Fn res_query
220function provides an interface to the server query mechanism.
221It constructs a query, sends it to the local server,
222awaits a response, and makes preliminary checks on the reply.
223The query requests information of the specified
224.Fa type
225and
226.Fa class
227for the specified fully qualified domain name
228.Fa dname .
229The reply message is left in the
230.Fa answer
231buffer with length
232.Fa anslen
233supplied by the caller.
234Values for the
235.Fa class
236and
237.Fa type
238fields
239are defined in
240.Aq Pa arpa/nameser.h .
241.Pp
242The
243.Fn res_search
244routine makes a query and awaits a response like
245.Fn res_query ,
246but in addition, it implements the default and search rules controlled by the
247.Dv RES_DEFNAMES
248and
249.Dv RES_DNSRCH
250options.
251It returns the first successful reply.
252.Pp
253The remaining routines are lower-level routines used by
254.Fn res_query .
255The
256.Fn res_mkquery
257function constructs a standard query message and places it in
258.Fa buf .
259It returns the size of the query, or \-1 if the query is larger than
260.Fa buflen .
261The query type
262.Fa op
263is usually
264.Dv QUERY ,
265but can be any of the query types defined in
266.Aq Pa arpa/nameser.h .
267The domain name for the query is given by
268.Fa dname .
269.Fa newrr
270is currently unused but is intended for making update messages.
271.Pp
272The
273.Fn res_send
274routine sends a pre-formatted query and returns an answer.
275It will call
276.Fn res_init
277if
278.Dv RES_INIT
279is not set, send the query to the local name server, and
280handle timeouts and retries.
281The length of the reply message is returned, or \-1 if there were errors.
282.Pp
283The
284.Fn dn_comp
285function compresses the domain name
286.Fa exp_dn
287and stores it in
288.Fa comp_dn .
289The size of the compressed name is returned or \-1 if there were errors.
290The size of the array pointed to by
291.Fa comp_dn
292is given by
293.Fa length .
294The compression uses an array of pointers
295.Fa dnptrs
296to previously compressed names in the current message.
297The first pointer points
298to the beginning of the message and the list ends with
299.Dv NULL .
300The limit to the array is specified by
301.Fa lastdnptr .
302A side effect of
303.Fn dn_comp
304is to update the list of pointers for labels inserted into the message
305as the name is compressed.
306If
307.Fa dnptrs
308is
309.Dv NULL ,
310names are not compressed.
311If
312.Fa lastdnptr
313is
314.Dv NULL ,
315the list of labels is not updated.
316.Pp
317The
318.Fn dn_expand
319entry expands the compressed domain name
320.Fa comp_dn
321to a full domain name.
322The compressed name is contained in a query or reply message;
323.Fa msg
324is a pointer to the beginning of the message.
325The uncompressed name is placed in the buffer indicated by
326.Fa exp_dn
327which is of size
328.Fa length .
329The size of compressed name is returned or \-1 if there was an error.
330.Sh FILES
331.Bl -tag -width "/etc/resolv.confXX"
332.It Pa /etc/resolv.conf
333The configuration file.
334.El
335.Sh SEE ALSO
336.Xr gethostbyname 3 ,
337.Xr resolv.conf 5 ,
338.Xr hostname 7 ,
339.Xr named 8
340.Pp
341.%T RFC 974 ,
342.%T RFC 1032 ,
343.%T RFC 1033 ,
344.%T RFC 1034 ,
345.%T RFC 1035 ,
346.%T RFC 1535
347.Rs
348.%T "Name Server Operations Guide for BIND"
349.Re
350.Sh HISTORY
351The
352.Nm
353function appeared in
354.Bx 4.3 .