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..389906d8a3
--- /dev/null
+++ b/src/lib/libc/net/resolver.3
@@ -0,0 +1,345 @@
1.\" $OpenBSD: resolver.3,v 1.6 1999/02/27 21:55:34 deraadt 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 BSD 4.3
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.Fo res_query
52.Fa "char *dname"
53.Fa "int class"
54.Fa "int type"
55.Fa "u_char *answer"
56.Fa "int anslen"
57.Fc
58.Fo res_search
59.Fa "char *dname"
60.Fa "int class"
61.Fa "int type"
62.Fa "u_char *answer"
63.Fa "int anslen"
64.Fc
65.Fo res_mkquery
66.Fa "int op"
67.Fa "char *dname"
68.Fa "int class"
69.Fa "int type"
70.Fa "char *data"
71.Fa "int datalen"
72.Fa "struct rrec *newrr"
73.Fa "char *buf"
74.Fa "int buflen"
75.Fc
76.Fo res_send
77.Fa "char *msg"
78.Fa "int msglen"
79.Fa "char *answer"
80.Fa "int anslen"
81.Fc
82.Fn res_init
83.Fo dn_comp
84.Fa "char *exp_dn"
85.Fa "char *comp_dn"
86.Fa "int length"
87.Fa "char **dnptrs"
88.Fa "char **lastdnptr"
89.Fc
90.Fo dn_expand
91.Fa "u_char *msg"
92.Fa "u_char *eomorig"
93.Fa "u_char *comp_dn"
94.Fa "u_char *exp_dn"
95.Fa "int length"
96.Fc
97.Sh DESCRIPTION
98These routines are used for making, sending and interpreting
99query and reply messages with Internet domain name servers.
100.Pp
101Global configuration and state information that is used by the
102resolver routines is kept in the structure
103.Em _res .
104Most of the values have reasonable defaults and can be ignored.
105Options
106stored in
107.Em _res.options
108are defined in
109.Pa resolv.h
110and are as follows.
111Options are stored as a simple bit mask containing the bitwise ``or''
112of the options enabled.
113.Bl -tag -width RES_USE_INET6
114.It Dv RES_INIT
115True if the initial name server address and default domain name are
116initialized (i.e.,
117.Fn res_init
118has been called).
119.It Dv RES_DEBUG
120Print debugging messages.
121.It Dv RES_AAONLY
122Accept authoritative answers only.
123With this option,
124.Fn res_send
125should continue until it finds an authoritative answer or finds an error.
126Currently this is not implemented.
127.It Dv RES_USEVC
128Use
129.Tn TCP
130connections for queries instead of
131.Tn UDP
132datagrams.
133.It Dv RES_STAYOPEN
134Used with
135.Dv RES_USEVC
136to keep the
137.Tn TCP
138connection open between
139queries.
140This is useful only in programs that regularly do many queries.
141.Tn UDP
142should be the normal mode used.
143.It Dv RES_IGNTC
144Unused currently (ignore truncation errors, i.e., don't retry with
145.Tn TCP ) .
146.It Dv RES_RECURSE
147Set the recursion-desired bit in queries.
148This is the default.
149.Pf ( Fn res_send
150does not do iterative queries and expects the name server
151to handle recursion.)
152.It Dv RES_DEFNAMES
153If set,
154.Fn res_search
155will append the default domain name to single-component names
156(those that do not contain a dot).
157This option is enabled by default.
158.It Dv RES_DNSRCH
159If this option is set,
160.Fn res_search
161will search for host names in the current domain and in parent domains; see
162.Xr hostname 7 .
163This is used by the standard host lookup routine
164.Xr gethostbyname 3 .
165This option is enabled by default.
166.It Dv RES_USE_INET6
167Enable support for IPv6 addresses.
168.El
169.Pp
170The
171.Fn res_init
172routine
173reads the configuration file (if any; see
174.Xr resolv.conf 5 )
175to get the default domain name,
176search list and
177the Internet address of the local name server(s).
178If no server is configured, the host running
179the resolver is tried.
180The current domain name is defined by the hostname
181if not specified in the configuration file;
182it can be overridden by the environment variable
183.Ev LOCALDOMAIN .
184This environment variable may contain several blank-separated
185tokens if you wish to override the
186.Fa search list
187on a per-process basis.
188This is similar to the
189.Fa search
190command in the configuration file.
191Another environment variable
192.Ev RES_OPTIONS
193can be set to override certain internal resolver options which
194are otherwise set by changing fields in the
195.Fa _res
196structure or are inherited from the configuration file's
197.Fa options
198command.
199The syntax of the
200.Ev RES_OPTIONS
201environment variable is explained in
202.Xr resolv.conf 5 .
203Initialization normally occurs on the first call
204to one of the following routines.
205.Pp
206The
207.Fn res_query
208function provides an interface to the server query mechanism.
209It constructs a query, sends it to the local server,
210awaits a response, and makes preliminary checks on the reply.
211The query requests information of the specified
212.Fa type
213and
214.Fa class
215for the specified fully-qualified domain name
216.Fa dname .
217The reply message is left in the
218.Fa answer
219buffer with length
220.Fa anslen
221supplied by the caller.
222.Pp
223The
224.Fn res_search
225routine makes a query and awaits a response like
226.Fn res_query ,
227but in addition, it implements the default and search rules
228controlled by the
229.Dv RES_DEFNAMES
230and
231.Dv RES_DNSRCH
232options.
233It returns the first successful reply.
234.Pp
235The remaining routines are lower-level routines used by
236.Fn res_query .
237The
238.Fn res_mkquery
239function
240constructs a standard query message and places it in
241.Fa buf .
242It returns the size of the query, or \-1 if the query is
243larger than
244.Fa buflen .
245The query type
246.Fa op
247is usually
248.Dv QUERY ,
249but can be any of the query types defined in
250.Aq Pa arpa/nameser.h .
251The domain name for the query is given by
252.Fa dname .
253.Fa newrr
254is currently unused but is intended for making update messages.
255.Pp
256The
257.Fn res_send
258routine
259sends 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
267\-1 if there were errors.
268.Pp
269The
270.Fn dn_comp
271function
272compresses the domain name
273.Fa exp_dn
274and stores it in
275.Fa comp_dn .
276The size of the compressed name is returned or \-1 if there were errors.
277The size of the array pointed to by
278.Fa comp_dn
279is given by
280.Fa length .
281The compression uses
282an array of pointers
283.Fa dnptrs
284to previously-compressed names in the current message.
285The first pointer points
286to the beginning of the message and the list ends with
287.Dv NULL .
288The limit to the array is specified by
289.Fa lastdnptr .
290A side effect of
291.Fn dn_comp
292is to update the list of pointers for
293labels inserted into the message
294as the name is compressed.
295If
296.Em dnptr
297is
298.Dv NULL, names are not compressed.
299If
300.Fa lastdnptr
301is
302.Dv NULL ,
303the list of labels is not updated.
304.Pp
305The
306.Fn dn_expand
307entry
308expands 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
322The configuration file
323see
324.Xr resolv.conf 5 .
325.El
326.Sh SEE ALSO
327.Xr gethostbyname 3 ,
328.Xr named 8 ,
329.Xr resolv.conf 5 ,
330.Xr hostname 7 ,
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 .