]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - 6/lib/libc/net/resolver.3
Clone Kip's Xen on stable/6 tree so that I can work on improving FreeBSD/amd64
[FreeBSD/FreeBSD.git] / 6 / lib / libc / net / resolver.3
1 .\" Copyright (c) 1985, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)resolver.3  8.1 (Berkeley) 6/4/93
33 .\" $FreeBSD$
34 .\"
35 .Dd November 4, 2006
36 .Dt RESOLVER 3
37 .Os
38 .Sh NAME
39 .Nm res_query ,
40 .Nm res_search ,
41 .Nm res_mkquery ,
42 .Nm res_send ,
43 .Nm res_init ,
44 .Nm dn_comp ,
45 .Nm dn_expand ,
46 .Nm dn_skipname ,
47 .Nm ns_get16 ,
48 .Nm ns_get32 ,
49 .Nm ns_put16 ,
50 .Nm ns_put32
51 .Nd resolver routines
52 .Sh LIBRARY
53 .Lb libc
54 .Sh SYNOPSIS
55 .In sys/types.h
56 .In netinet/in.h
57 .In arpa/nameser.h
58 .In resolv.h
59 .Ft int
60 .Fo res_query
61 .Fa "const 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_search
69 .Fa "const char *dname"
70 .Fa "int class"
71 .Fa "int type"
72 .Fa "u_char *answer"
73 .Fa "int anslen"
74 .Fc
75 .Ft int
76 .Fo res_mkquery
77 .Fa "int op"
78 .Fa "const char *dname"
79 .Fa "int class"
80 .Fa "int type"
81 .Fa "const u_char *data"
82 .Fa "int datalen"
83 .Fa "const u_char *newrr_in"
84 .Fa "u_char *buf"
85 .Fa "int buflen"
86 .Fc
87 .Ft int
88 .Fo res_send
89 .Fa "const u_char *msg"
90 .Fa "int msglen"
91 .Fa "u_char *answer"
92 .Fa "int anslen"
93 .Fc
94 .Ft int
95 .Fn res_init void
96 .Ft int
97 .Fo dn_comp
98 .Fa "const char *exp_dn"
99 .Fa "u_char *comp_dn"
100 .Fa "int length"
101 .Fa "u_char **dnptrs"
102 .Fa "u_char **lastdnptr"
103 .Fc
104 .Ft int
105 .Fo dn_expand
106 .Fa "const u_char *msg"
107 .Fa "const u_char *eomorig"
108 .Fa "const u_char *comp_dn"
109 .Fa "char *exp_dn"
110 .Fa "int length"
111 .Fc
112 .Ft int
113 .Fn dn_skipname "const u_char *comp_dn" "const u_char *eom"
114 .Ft u_int
115 .Fn ns_get16 "const u_char *src"
116 .Ft u_long
117 .Fn ns_get32 "const u_char *src"
118 .Ft void
119 .Fn ns_put16 "u_int src" "u_char *dst"
120 .Ft void
121 .Fn ns_put32 "u_long src" "u_char *dst"
122 .Sh DESCRIPTION
123 These routines are used for making, sending and interpreting
124 query and reply messages with Internet domain name servers.
125 .Pp
126 Global configuration and state information that is used by the
127 resolver routines is kept in the structure
128 .Va _res .
129 Most of the values have reasonable defaults and can be ignored.
130 Options
131 stored in
132 .Va _res.options
133 are defined in
134 .In resolv.h
135 and are as follows.
136 Options are stored as a simple bit mask containing the bitwise ``or''
137 of the options enabled.
138 .Bl -tag -width RES_USE_INET6
139 .It Dv RES_INIT
140 True if the initial name server address and default domain name are
141 initialized (i.e.,
142 .Fn res_init
143 has been called).
144 .It Dv RES_DEBUG
145 Print debugging messages.
146 .It Dv RES_AAONLY
147 Accept authoritative answers only.
148 With this option,
149 .Fn res_send
150 should continue until it finds an authoritative answer or finds an error.
151 Currently this is not implemented.
152 .It Dv RES_USEVC
153 Use
154 .Tn TCP
155 connections for queries instead of
156 .Tn UDP
157 datagrams.
158 .It Dv RES_STAYOPEN
159 Used with
160 .Dv RES_USEVC
161 to keep the
162 .Tn TCP
163 connection open between
164 queries.
165 This is useful only in programs that regularly do many queries.
166 .Tn UDP
167 should be the normal mode used.
168 .It Dv RES_IGNTC
169 Unused currently (ignore truncation errors, i.e., do not retry with
170 .Tn TCP ) .
171 .It Dv RES_RECURSE
172 Set the recursion-desired bit in queries.
173 This is the default.
174 .Pf ( Fn res_send
175 does not do iterative queries and expects the name server
176 to handle recursion.)
177 .It Dv RES_DEFNAMES
178 If set,
179 .Fn res_search
180 will append the default domain name to single-component names
181 (those that do not contain a dot).
182 This option is enabled by default.
183 .It Dv RES_DNSRCH
184 If this option is set,
185 .Fn res_search
186 will search for host names in the current domain and in parent domains; see
187 .Xr hostname 7 .
188 This is used by the standard host lookup routine
189 .Xr gethostbyname 3 .
190 This option is enabled by default.
191 .It Dv RES_NOALIASES
192 This option turns off the user level aliasing feature controlled by the
193 .Dq Ev HOSTALIASES
194 environment variable.
195 Network daemons should set this option.
196 .It Dv RES_USE_INET6
197 Enables support for IPv6-only applications.
198 This causes IPv4 addresses to be returned as an IPv4 mapped address.
199 For example,
200 .Li 10.1.1.1
201 will be returned as
202 .Li ::ffff:10.1.1.1 .
203 The option is meaningful with certain kernel configuration only.
204 .It Dv RES_USE_EDNS0
205 Enables support for OPT pseudo-RR for EDNS0 extension.
206 With the option, resolver code will attach OPT pseudo-RR into DNS queries,
207 to inform of our receive buffer size.
208 The option will allow DNS servers to take advantage of non-default receive
209 buffer size, and to send larger replies.
210 DNS query packets with EDNS0 extension is not compatible with
211 non-EDNS0 DNS servers.
212 .El
213 .Pp
214 The
215 .Fn res_init
216 routine
217 reads the configuration file (if any; see
218 .Xr resolver 5 )
219 to get the default domain name,
220 search list and
221 the Internet address of the local name server(s).
222 If no server is configured, the host running
223 the resolver is tried.
224 The current domain name is defined by the hostname
225 if not specified in the configuration file;
226 it can be overridden by the environment variable
227 .Ev LOCALDOMAIN .
228 This environment variable may contain several blank-separated
229 tokens if you wish to override the
230 .Em "search list"
231 on a per-process basis.
232 This is similar to the
233 .Ic search
234 command in the configuration file.
235 Another environment variable
236 .Dq Ev RES_OPTIONS
237 can be set to
238 override certain internal resolver options which are otherwise
239 set by changing fields in the
240 .Va _res
241 structure or are inherited from the configuration file's
242 .Ic options
243 command.
244 The syntax of the
245 .Dq Ev RES_OPTIONS
246 environment variable is explained in
247 .Xr resolver 5 .
248 Initialization normally occurs on the first call
249 to one of the following routines.
250 .Pp
251 The
252 .Fn res_query
253 function provides an interface to the server query mechanism.
254 It constructs a query, sends it to the local server,
255 awaits a response, and makes preliminary checks on the reply.
256 The query requests information of the specified
257 .Fa type
258 and
259 .Fa class
260 for the specified fully-qualified domain name
261 .Fa dname .
262 The reply message is left in the
263 .Fa answer
264 buffer with length
265 .Fa anslen
266 supplied by the caller.
267 .Pp
268 The
269 .Fn res_search
270 routine makes a query and awaits a response like
271 .Fn res_query ,
272 but in addition, it implements the default and search rules
273 controlled by the
274 .Dv RES_DEFNAMES
275 and
276 .Dv RES_DNSRCH
277 options.
278 It returns the first successful reply.
279 .Pp
280 The remaining routines are lower-level routines used by
281 .Fn res_query .
282 The
283 .Fn res_mkquery
284 function
285 constructs a standard query message and places it in
286 .Fa buf .
287 It returns the size of the query, or \-1 if the query is
288 larger than
289 .Fa buflen .
290 The query type
291 .Fa op
292 is usually
293 .Dv QUERY ,
294 but can be any of the query types defined in
295 .In arpa/nameser.h .
296 The domain name for the query is given by
297 .Fa dname .
298 The
299 .Fa newrr_in
300 argument
301 is currently unused but is intended for making update messages.
302 .Pp
303 The
304 .Fn res_send
305 routine
306 sends a pre-formatted query and returns an answer.
307 It will call
308 .Fn res_init
309 if
310 .Dv RES_INIT
311 is not set, send the query to the local name server, and
312 handle timeouts and retries.
313 The length of the reply message is returned, or
314 \-1 if there were errors.
315 .Pp
316 The
317 .Fn dn_comp
318 function
319 compresses the domain name
320 .Fa exp_dn
321 and stores it in
322 .Fa comp_dn .
323 The size of the compressed name is returned or \-1 if there were errors.
324 The size of the array pointed to by
325 .Fa comp_dn
326 is given by
327 .Fa length .
328 The compression uses
329 an array of pointers
330 .Fa dnptrs
331 to previously-compressed names in the current message.
332 The first pointer points to
333 the beginning of the message and the list ends with
334 .Dv NULL .
335 The limit to the array is specified by
336 .Fa lastdnptr .
337 A side effect of
338 .Fn dn_comp
339 is to update the list of pointers for
340 labels inserted into the message
341 as the name is compressed.
342 If
343 .Fa dnptr
344 is
345 .Dv NULL ,
346 names are not compressed.
347 If
348 .Fa lastdnptr
349 is
350 .Dv NULL ,
351 the list of labels is not updated.
352 .Pp
353 The
354 .Fn dn_expand
355 entry
356 expands the compressed domain name
357 .Fa comp_dn
358 to a full domain name
359 The compressed name is contained in a query or reply message;
360 .Fa msg
361 is a pointer to the beginning of the message.
362 The uncompressed name is placed in the buffer indicated by
363 .Fa exp_dn
364 which is of size
365 .Fa length .
366 The size of compressed name is returned or \-1 if there was an error.
367 .Pp
368 The
369 .Fn dn_skipname
370 function skips over a compressed domain name, which starts at a location
371 pointed to by
372 .Fa comp_dn .
373 The compressed name is contained in a query or reply message;
374 .Fa eom
375 is a pointer to the end of the message.
376 The size of compressed name is returned or \-1 if there was
377 an error.
378 .Pp
379 The
380 .Fn ns_get16
381 function gets a 16-bit quantity from a buffer pointed to by
382 .Fa src .
383 .Pp
384 The
385 .Fn ns_get32
386 function gets a 32-bit quantity from a buffer pointed to by
387 .Fa src .
388 .Pp
389 The
390 .Fn ns_put16
391 function puts a 16-bit quantity
392 .Fa src
393 to a buffer pointed to by
394 .Fa dst .
395 .Pp
396 The
397 .Fn ns_put32
398 function puts a 32-bit quantity
399 .Fa src
400 to a buffer pointed to by
401 .Fa dst .
402 .Sh IMPLEMENTATION NOTES
403 This implementation of the resolver is thread-safe, but it will not
404 function properly if the programmer attempts to declare his or her own
405 .Va _res
406 structure in an attempt to replace the per-thread version referred to
407 by that macro.
408 .Sh RETURN VALUES
409 The
410 .Fn res_init
411 function will return 0 on success, or \-1 in a threaded program if
412 per-thread storage could not be allocated.
413 .Pp
414 The
415 .Fn res_mkquery ,
416 .Fn res_search ,
417 and
418 .Fn res_query
419 functions return the size of the response on success, or \-1 if an
420 error occurs.
421 The integer
422 .Vt h_errno
423 may be checked to determine the reason for error.
424 See
425 .Xr gethostbyname 3
426 for more information.
427 .Sh FILES
428 .Bl -tag -width /etc/resolv.conf
429 .It Pa /etc/resolv.conf
430 The configuration file,
431 see
432 .Xr resolver 5 .
433 .El
434 .Sh SEE ALSO
435 .Xr gethostbyname 3 ,
436 .Xr resolver 5 ,
437 .Xr hostname 7 ,
438 .Xr named 8
439 .Pp
440 .%T RFC1032 ,
441 .%T RFC1033 ,
442 .%T RFC1034 ,
443 .%T RFC1035 ,
444 .%T RFC974
445 .Rs
446 .%T "Name Server Operations Guide for BIND"
447 .Re
448 .Sh HISTORY
449 The
450 .Nm
451 function appeared in
452 .Bx 4.3 .