tzfile.5, tzselect.8: sync from tzdb upstream
[man-pages.git] / man3 / resolver.3
blobb19b89e542762f89d83bf036e035d77ba89c6aa7
1 '\" t
2 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" and (C) Copyright 2015 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .\" References consulted:
8 .\"     Linux libc source code
9 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
10 .\"     386BSD man pages
11 .\" Modified 1993-07-25 by Rik Faith (faith@cs.unc.edu)
12 .\" Modified 2004-10-31 by aeb
13 .\"
14 .TH resolver 3 (date) "Linux man-pages (unreleased)"
15 .SH NAME
16 res_ninit, res_nquery, res_nsearch, res_nquerydomain, res_nmkquery, res_nsend,
17 res_nclose,
18 res_init, res_query, res_search, res_querydomain, res_mkquery, res_send,
19 dn_comp, dn_expand \-
20 resolver routines
21 .SH LIBRARY
22 Resolver library
23 .RI ( libresolv ", " \-lresolv )
24 .SH SYNOPSIS
25 .nf
26 .B #include <netinet/in.h>
27 .B #include <arpa/nameser.h>
28 .B #include <resolv.h>
29 .PP
30 .B struct __res_state;
31 .B typedef struct __res_state *res_state;
32 .PP
33 .BI "int res_ninit(res_state " statep );
34 .PP
35 .BI "void res_nclose(res_state " statep );
36 .PP
37 .BI "int res_nquery(res_state " statep ,
38 .BI "           const char *" dname ", int " class ", int " type ,
39 .BI "           unsigned char " answer [. anslen "], int " anslen );
40 .PP
41 .BI "int res_nsearch(res_state " statep ,
42 .BI "           const char *" dname ", int " class ", int " type ,
43 .BI "           unsigned char " answer [. anslen "], int " anslen );
44 .PP
45 .BI "int res_nquerydomain(res_state " statep ,
46 .BI "           const char *" name ", const char *" domain ,
47 .BI "           int " class ", int " type ", unsigned char " answer [. anslen ],
48 .BI "           int " anslen );
49 .PP
50 .BI "int res_nmkquery(res_state " statep ,
51 .BI "           int " op ", const char *" dname ", int " class ,
52 .BI "           int " type ", const unsigned char " data [. datalen "], \
53 int " datalen ,
54 .BI "           const unsigned char *" newrr ,
55 .BI "           unsigned char " buf [. buflen "], int " buflen );
56 .PP
57 .BI "int res_nsend(res_state " statep ,
58 .BI "           const unsigned char " msg [. msglen "], int " msglen ,
59 .BI "           unsigned char " answer [. anslen "], int " anslen );
60 .PP
61 .BI "int dn_comp(const char *" exp_dn ", unsigned char " comp_dn [. length ],
62 .BI "           int " length ", unsigned char **" dnptrs ,
63 .BI "           unsigned char **" lastdnptr );
64 .PP
65 .BI "int dn_expand(const unsigned char *" msg ,
66 .BI "           const unsigned char *" eomorig ,
67 .BI "           const unsigned char *" comp_dn ", char " exp_dn [. length ],
68 .BI "           int " length );
69 .PP
70 .B [[deprecated]] extern struct __res_state _res;
71 .PP
72 .B [[deprecated]] int res_init(void);
73 .PP
74 .B [[deprecated]]
75 .BI "int res_query(const char *" dname ", int " class ", int " type ,
76 .BI "           unsigned char " answer [. anslen "], int " anslen );
77 .PP
78 .B [[deprecated]]
79 .BI "int res_search(const char *" dname ", int " class ", int " type ,
80 .BI "           unsigned char " answer [. anslen "], int " anslen );
81 .PP
82 .B [[deprecated]]
83 .BI "int res_querydomain(const char *" name ", const char *" domain ,
84 .BI "           int " class ", int " type ", unsigned char " answer [. anslen ],
85 .BI "           int " anslen );
86 .PP
87 .B [[deprecated]]
88 .BI "int res_mkquery(int " op ", const char *" dname ", int " class ,
89 .BI "           int " type ", const unsigned char " data [. datalen "], \
90 int " datalen ,
91 .BI "           const unsigned char *" newrr ,
92 .BI "           unsigned char " buf [. buflen "], int " buflen );
93 .PP
94 .B [[deprecated]]
95 .BI "int res_send(const unsigned char " msg [. msglen "], int " msglen ,
96 .BI "           unsigned char " answer [. anslen "], int " anslen );
97 .fi
98 .SH DESCRIPTION
99 .B Note:
100 This page is incomplete (various resolver functions provided by glibc
101 are not described) and likely out of date.
103 The functions described below make queries to and interpret
104 the responses from Internet domain name servers.
106 The API consists of a set of more modern, reentrant functions
107 and an older set of nonreentrant functions that have been superseded.
108 The traditional resolver interfaces such as
109 .BR res_init ()
111 .BR res_query ()
112 use some static (global) state stored in the
113 .I _res
114 structure, rendering these functions non-thread-safe.
115 BIND 8.2 introduced a set of new interfaces
116 .BR res_ninit (),
117 .BR res_nquery (),
118 and so on, which take a
119 .I res_state
120 as their first argument, so you can use a per-thread resolver state.
123 .BR res_ninit ()
125 .BR res_init ()
126 functions read the configuration files (see
127 .BR resolv.conf (5))
128 to get the default domain name and name
129 server address(es).
130 If no server is given, the local host is tried.
131 If no domain is given, that associated with the local host is used.
132 It can be overridden with the environment variable
133 .BR LOCALDOMAIN .
134 .BR res_ninit ()
136 .BR res_init ()
137 is normally executed by the first call to one of the
138 other functions.
139 Every call to
140 .BR res_ninit ()
141 requires a corresponding call to
142 .BR res_nclose ()
143 to free memory allocated by
144 .BR res_ninit ()
145 and subsequent calls to
146 .BR res_nquery ().
149 .BR res_nquery ()
151 .BR res_query ()
152 functions query the name server for the
153 fully qualified domain name \fIname\fP of specified \fItype\fP and
154 \fIclass\fP.
155 The reply is left in the buffer \fIanswer\fP of length
156 \fIanslen\fP supplied by the caller.
159 .BR res_nsearch ()
161 .BR res_search ()
162 functions make a query and waits for the response like
163 .BR res_nquery ()
165 .BR res_query (),
166 but in addition they implement the default and search
167 rules controlled by
168 .B RES_DEFNAMES
170 .B RES_DNSRCH
171 (see description of
172 \fI_res\fP options below).
175 .BR res_nquerydomain ()
177 .BR res_querydomain ()
178 functions make a query using
179 .BR res_nquery ()/ res_query ()
180 on the concatenation of \fIname\fP and \fIdomain\fP.
182 The following functions are lower-level routines used by
183 .BR res_nquery ()/ res_query ().
186 .BR res_nmkquery ()
188 .BR res_mkquery ()
189 functions construct a query message in \fIbuf\fP
190 of length \fIbuflen\fP for the domain name \fIdname\fP.
191 The query type
192 \fIop\fP is one of the following (typically
193 .BR QUERY ):
195 .B QUERY
196 Standard query.
198 .B IQUERY
199 Inverse query.
200 This option was removed in glibc 2.26,
201 .\" commit e4e794841e3140875f2aa86b90e2ada3d61e1244
202 since it has not been supported by DNS servers for a very long time.
204 .B NS_NOTIFY_OP
205 Notify secondary of SOA (Start of Authority) change.
207 \fInewrr\fP is currently unused.
210 .BR res_nsend ()
212 .BR res_send ()
213 function send a preformatted query given in
214 \fImsg\fP of length \fImsglen\fP and returns the answer in \fIanswer\fP
215 which is of length \fIanslen\fP.
216 They will call
217 .BR res_ninit ()/ res_init ()
218 if it has not already been called.
221 .BR dn_comp ()
222 function compresses the domain name \fIexp_dn\fP
223 and stores it in the buffer \fIcomp_dn\fP of length \fIlength\fP.
224 The compression uses an array of pointers \fIdnptrs\fP to previously
225 compressed names in the current message.
226 The first pointer points
227 to the beginning of the message and the list ends with NULL.
228 The limit of the array is specified by \fIlastdnptr\fP.
229 If \fIdnptr\fP is NULL, domain names are not compressed.
230 If \fIlastdnptr\fP is NULL, the list
231 of labels is not updated.
234 .BR dn_expand ()
235 function expands the compressed domain name
236 \fIcomp_dn\fP to a full domain name, which is placed in the buffer
237 \fIexp_dn\fP of size \fIlength\fP.
238 The compressed name is contained
239 in a query or reply message, and \fImsg\fP points to the beginning of
240 the message.
242 The resolver routines use configuration and state information
243 contained in a
244 .I __res_state
245 structure (either passed as the
246 .I statep
247 argument, or in the global variable
248 .IR _res ,
249 in the case of the older nonreentrant functions).
250 The only field of this structure that is normally manipulated by the
251 user is the
252 .I options
253 field.
254 This field can contain the bitwise "OR"
255 of the following options:
257 .B RES_INIT
258 True if
259 .BR res_ninit ()
261 .BR res_init ()
262 has been called.
264 .B RES_DEBUG
265 Print debugging messages.
266 This option is available only if glibc was built with debugging enabled,
267 .\" See resolv/README.
268 .\" Support for RES_DEBUG was made conditional in glibc 2.2.
269 which is not the default.
271 .BR RES_AAONLY " (unimplemented; deprecated in glibc 2.25)"
272 Accept authoritative answers only.
273 .BR res_send ()
274 continues until
275 it finds an authoritative answer or returns an error.
276 This option was present but unimplemented until glibc 2.24;
277 since glibc 2.25, it is deprecated, and its usage produces a warning.
279 .B RES_USEVC
280 Use TCP connections for queries rather than UDP datagrams.
282 .BR RES_PRIMARY " (unimplemented; deprecated in glibc 2.25)"
283 Query primary domain name server only.
284 This option was present but unimplemented until glibc 2.24;
285 since glibc 2.25, it is deprecated, and its usage produces a warning.
287 .B RES_IGNTC
288 Ignore truncation errors.
289 Don't retry with TCP.
291 .B RES_RECURSE
292 Set the recursion desired bit in queries.
293 Recursion is carried out
294 by the domain name server, not by
295 .BR res_send ().
296 [Enabled by default].
298 .B RES_DEFNAMES
299 If set,
300 .BR res_search ()
301 will append the default domain name to
302 single component names\[em]that is, those that do not contain a dot.
303 [Enabled by default].
305 .B RES_STAYOPEN
306 Used with
307 .B RES_USEVC
308 to keep the TCP connection open between queries.
310 .B RES_DNSRCH
311 If set,
312 .BR res_search ()
313 will search for hostnames in the current
314 domain and in parent domains.
315 This option is used by
316 .BR gethostbyname (3).
317 [Enabled by default].
319 .B RES_INSECURE1
320 Accept a response from a wrong server.
321 This can be used to detect potential security hazards,
322 but you need to compile glibc with debugging enabled and use
323 .B RES_DEBUG
324 option (for debug purpose only).
326 .B RES_INSECURE2
327 Accept a response which contains a wrong query.
328 This can be used to detect potential security hazards,
329 but you need to compile glibc with debugging enabled and use
330 .B RES_DEBUG
331 option (for debug purpose only).
333 .B RES_NOALIASES
334 Disable usage of
335 .B HOSTALIASES
336 environment variable.
338 .B RES_USE_INET6
339 Try an AAAA query before an A query inside the
340 .BR gethostbyname (3)
341 function, and map IPv4 responses in IPv6 "tunneled form" if no AAAA records
342 are found but an A record set exists.
343 Since glibc 2.25, this option is deprecated,
344 and its usage produces a warning;
345 applications should use
346 .BR getaddrinfo (3),
347 rather than
348 .BR gethostbyname (3).
350 .B RES_ROTATE
351 Causes round-robin selection of name servers from among those listed.
352 This has the effect of spreading the query load among all listed servers,
353 rather than having all clients try the first listed server first every
354 time.
356 .BR RES_NOCHECKNAME " (unimplemented; deprecated in glibc 2.25)"
357 Disable the modern BIND checking of incoming hostnames and mail names
358 for invalid characters such as underscore (_), non-ASCII,
359 or control characters.
360 This option was present until glibc 2.24;
361 since glibc 2.25, it is deprecated, and its usage produces a warning.
363 .BR RES_KEEPTSIG " (unimplemented; deprecated in glibc 2.25)"
364 Do not strip TSIG records.
365 This option was present but unimplemented until glibc 2.24;
366 since glibc 2.25, it is deprecated, and its usage produces a warning.
368 .BR RES_BLAST " (unimplemented; deprecated in glibc 2.25)"
369 Send each query simultaneously and recursively to all servers.
370 This option was present but unimplemented until glibc 2.24;
371 since glibc 2.25, it is deprecated, and its usage produces a warning.
373 .BR RES_USEBSTRING " (glibc 2.3.4 to glibc 2.24)"
374 Make reverse IPv6 lookups using the bit-label format described in RFC 2673;
375 if this option is not set (which is the default), then nibble format is used.
376 This option was removed in glibc 2.25,
377 since it relied on a backward-incompatible
378 DNS extension that was never deployed on the Internet.
380 .BR RES_NOIP6DOTINT " (glibc 2.24 and earlier)"
382 .I ip6.arpa
383 zone in IPv6 reverse lookup instead of
384 .IR ip6.int ,
385 which is deprecated since glibc 2.3.4.
386 This option is present up to and including glibc 2.24,
387 where it is enabled by default.
388 In glibc 2.25, this option was removed.
390 .BR RES_USE_EDNS0 " (since glibc 2.6)"
391 Enables support for the DNS extensions (EDNS0) described in RFC 2671.
393 .BR RES_SNGLKUP " (since glibc 2.10)"
394 By default, glibc performs IPv4 and IPv6 lookups in parallel
395 since glibc 2.9.
396 Some appliance DNS servers cannot handle these queries properly
397 and make the requests time out.
398 This option disables the behavior and makes glibc
399 perform the IPv6 and IPv4 requests sequentially
400 (at the cost of some slowdown of the resolving process).
402 .B RES_SNGLKUPREOP
403 When
404 .B RES_SNGLKUP
405 option is enabled, opens a new socket for the each request.
407 .B RES_USE_DNSSEC
408 Use DNSSEC with OK bit in OPT record.
409 This option implies
410 .BR RES_USE_EDNS0 .
412 .B RES_NOTLDQUERY
413 Do not look up unqualified name as a top-level domain (TLD).
415 .B RES_DEFAULT
416 Default option which implies:
417 .BR RES_RECURSE ,
418 .BR RES_DEFNAMES ,
419 .BR RES_DNSRCH ,
421 .BR RES_NOIP6DOTINT .
423 .SH RETURN VALUE
425 .BR res_ninit ()
427 .BR res_init ()
428 functions return 0 on success, or \-1 if an error
429 occurs.
432 .BR res_nquery (),
433 .BR res_query (),
434 .BR res_nsearch (),
435 .BR res_search (),
436 .BR res_nquerydomain (),
437 .BR res_querydomain (),
438 .BR res_nmkquery (),
439 .BR res_mkquery (),
440 .BR res_nsend (),
442 .BR res_send ()
443 functions return the length
444 of the response, or \-1 if an error occurs.
447 .BR dn_comp ()
449 .BR dn_expand ()
450 functions return the length
451 of the compressed name, or \-1 if an error occurs.
453 In the case of an error return from
454 .BR res_nquery (),
455 .BR res_query (),
456 .BR res_nsearch (),
457 .BR res_search (),
458 .BR res_nquerydomain (),
460 .BR res_querydomain (),
461 the global variable
462 .I h_errno
463 (see
464 .BR gethostbyname (3))
465 can be consulted to determine the cause of the error.
466 .SH FILES
468 .I /etc/resolv.conf
469 resolver configuration file
471 .I /etc/host.conf
472 resolver configuration file
473 .SH ATTRIBUTES
474 For an explanation of the terms used in this section, see
475 .BR attributes (7).
476 .ad l
479 allbox;
480 lbx lb lb
481 l l l.
482 Interface       Attribute       Value
484 .BR res_ninit (),
485 .BR res_nclose (),
486 .BR res_nquery (),
487 .BR res_nsearch (),
488 .BR res_nquerydomain (),
489 .BR res_nsend ()
490 T}      Thread safety   MT-Safe locale
492 .BR res_nmkquery (),
493 .BR dn_comp (),
494 .BR dn_expand ()
495 T}      Thread safety   MT-Safe
499 .sp 1
500 .SH STANDARDS
501 4.3BSD.
502 .SH SEE ALSO
503 .BR gethostbyname (3),
504 .BR resolv.conf (5),
505 .BR resolver (5),
506 .BR hostname (7),
507 .BR named (8)
509 The GNU C library source file
510 .IR resolv/README .