1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and (C) Copyright 2015 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" References consulted:
27 .\" Linux libc source code
28 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
30 .\" Modified 1993-07-25 by Rik Faith (faith@cs.unc.edu)
31 .\" Modified 2004-10-31 by aeb
33 .TH RESOLVER 3 2021-03-22 "GNU" "Linux Programmer's Manual"
35 res_ninit, res_nclose, res_nquery, res_nsearch, res_nquerydomain, res_nmkquery, res_nsend,
36 res_init, res_query, res_search, res_querydomain, res_mkquery, res_send,
37 dn_comp, dn_expand \- resolver routines
40 .B #include <netinet/in.h>
41 .B #include <arpa/nameser.h>
42 .B #include <resolv.h>
44 .B struct __res_state;
45 .B typedef struct __res_state *res_state;
47 .BI "int res_ninit(res_state " statep );
49 .BI "void res_nclose(res_state " statep );
51 .BI "int res_nquery(res_state " statep ,
52 .BI " const char *" dname ", int " class ", int " type ,
53 .BI " unsigned char *" answer ", int " anslen );
55 .BI "int res_nsearch(res_state " statep ,
56 .BI " const char *" dname ", int " class ", int " type ,
57 .BI " unsigned char *" answer ", int " anslen );
59 .BI "int res_nquerydomain(res_state " statep ,
60 .BI " const char *" name ", const char *" domain ,
61 .BI " int " class ", int " type ", unsigned char *" answer ,
64 .BI "int res_nmkquery(res_state " statep ,
65 .BI " int " op ", const char *" dname ", int " class ,
66 .BI " int " type ", const unsigned char *" data ", int " datalen ,
67 .BI " const unsigned char *" newrr ,
68 .BI " unsigned char *" buf ", int " buflen );
70 .BI "int res_nsend(res_state " statep ,
71 .BI " const unsigned char *" msg ", int " msglen ,
72 .BI " unsigned char *" answer ", int " anslen );
74 .BI "int dn_comp(const char *" exp_dn ", unsigned char *" comp_dn ,
75 .BI " int " length ", unsigned char **" dnptrs ,
76 .BI " unsigned char **" lastdnptr );
78 .BI "int dn_expand(const unsigned char *" msg ,
79 .BI " const unsigned char *" eomorig ,
80 .BI " const unsigned char *" comp_dn ", char *" exp_dn ,
86 .B extern struct __res_state _res;
88 .B int res_init(void);
90 .BI "int res_query(const char *" dname ", int " class ", int " type ,
91 .BI " unsigned char *" answer ", int " anslen );
93 .BI "int res_search(const char *" dname ", int " class ", int " type ,
94 .BI " unsigned char *" answer ", int " anslen );
96 .BI "int res_querydomain(const char *" name ", const char *" domain ,
97 .BI " int " class ", int " type ", unsigned char *" answer ,
100 .BI "int res_mkquery(int " op ", const char *" dname ", int " class ,
101 .BI " int " type ", const unsigned char *" data ", int " datalen ,
102 .BI " const unsigned char *" newrr ,
103 .BI " unsigned char *" buf ", int " buflen );
105 .BI "int res_send(const unsigned char *" msg ", int " msglen ,
106 .BI " unsigned char *" answer ", int " anslen );
109 Link with \fI\-lresolv\fP.
112 This page is incomplete (various resolver functions provided by glibc
113 are not described) and likely out of date.
115 The functions described below make queries to and interpret
116 the responses from Internet domain name servers.
118 The API consists of a set of more modern, reentrant functions
119 and an older set of nonreentrant functions that have been superseded.
120 The traditional resolver interfaces such as
124 use some static (global) state stored in the
126 structure, rendering these functions non-thread-safe.
127 BIND 8.2 introduced a set of new interfaces
130 and so on, which take a
132 as their first argument, so you can use a per-thread resolver state.
138 functions read the configuration files (see
140 to get the default domain name and name
142 If no server is given, the local host is tried.
143 If no domain is given, that associated with the local host is used.
144 It can be overridden with the environment variable
149 is normally executed by the first call to one of the
153 requires a corresponding call to
155 to free memory allocated by
157 and subsequent calls to
164 functions query the name server for the
165 fully qualified domain name \fIname\fP of specified \fItype\fP and
167 The reply is left in the buffer \fIanswer\fP of length
168 \fIanslen\fP supplied by the caller.
174 functions make a query and waits for the response like
178 but in addition they implement the default and search
184 \fI_res\fP options below).
187 .BR res_nquerydomain ()
189 .BR res_querydomain ()
190 functions make a query using
191 .BR res_nquery ()/ res_query ()
192 on the concatenation of \fIname\fP and \fIdomain\fP.
194 The following functions are lower-level routines used by
195 .BR res_nquery ()/ res_query ().
201 functions construct a query message in \fIbuf\fP
202 of length \fIbuflen\fP for the domain name \fIdname\fP.
204 \fIop\fP is one of the following (typically
212 This option was removed in glibc 2.26,
213 .\" commit e4e794841e3140875f2aa86b90e2ada3d61e1244
214 since it has not been supported by DNS servers for a very long time.
217 Notify secondary of SOA (Start of Authority) change.
219 \fInewrr\fP is currently unused.
225 function send a preformatted query given in
226 \fImsg\fP of length \fImsglen\fP and returns the answer in \fIanswer\fP
227 which is of length \fIanslen\fP.
229 .BR res_ninit ()/ res_init ()
230 if it has not already been called.
234 function compresses the domain name \fIexp_dn\fP
235 and stores it in the buffer \fIcomp_dn\fP of length \fIlength\fP.
236 The compression uses an array of pointers \fIdnptrs\fP to previously
237 compressed names in the current message.
238 The first pointer points
239 to the beginning of the message and the list ends with NULL.
240 The limit of the array is specified by \fIlastdnptr\fP.
241 If \fIdnptr\fP is NULL, domain names are not compressed.
242 If \fIlastdnptr\fP is NULL, the list
243 of labels is not updated.
247 function expands the compressed domain name
248 \fIcomp_dn\fP to a full domain name, which is placed in the buffer
249 \fIexp_dn\fP of size \fIlength\fP.
250 The compressed name is contained
251 in a query or reply message, and \fImsg\fP points to the beginning of
254 The resolver routines use configuration and state information
257 structure (either passed as the
259 argument, or in the global variable
261 in the case of the older nonreentrant functions).
262 The only field of this structure that is normally manipulated by the
266 This field can contain the bitwise "OR"
267 of the following options:
277 Print debugging messages.
278 This option is available only if glibc was built with debugging enabled,
279 .\" See resolv/README.
280 .\" Support for RES_DEBUG was made conditional in glibc 2.2.
281 which is not the default.
283 .BR RES_AAONLY " (unimplemented; deprecated in glibc 2.25)"
284 Accept authoritative answers only.
287 it finds an authoritative answer or returns an error.
288 This option was present but unimplemented in glibc until version 2.24;
289 since glibc 2.25, it is deprecated, and its usage produces a warning.
292 Use TCP connections for queries rather than UDP datagrams.
294 .BR RES_PRIMARY " (unimplemented; deprecated in glibc 2.25)"
295 Query primary domain name server only.
296 This option was present but unimplemented in glibc until version 2.24;
297 since glibc 2.25, it is deprecated, and its usage produces a warning.
300 Ignore truncation errors.
301 Don't retry with TCP.
304 Set the recursion desired bit in queries.
305 Recursion is carried out
306 by the domain name server, not by
308 [Enabled by default].
313 will append the default domain name to
314 single component names\(emthat is, those that do not contain a dot.
315 [Enabled by default].
320 to keep the TCP connection open between queries.
325 will search for hostnames in the current
326 domain and in parent domains.
327 This option is used by
328 .BR gethostbyname (3).
329 [Enabled by default].
332 Accept a response from a wrong server.
333 This can be used to detect potential security hazards,
334 but you need to compile glibc with debugging enabled and use
336 option (for debug purpose only).
339 Accept a response which contains a wrong query.
340 This can be used to detect potential security hazards,
341 but you need to compile glibc with debugging enabled and use
343 option (for debug purpose only).
348 environment variable.
351 Try an AAAA query before an A query inside the
352 .BR gethostbyname (3)
353 function, and map IPv4 responses in IPv6 "tunneled form" if no AAAA records
354 are found but an A record set exists.
355 Since glibc 2.25, this option is deprecated,
356 and its usage produces a warning;
357 applications should use
360 .BR gethostbyname (3).
363 Causes round-robin selection of name servers from among those listed.
364 This has the effect of spreading the query load among all listed servers,
365 rather than having all clients try the first listed server first every
368 .BR RES_NOCHECKNAME " (unimplemented; deprecated in glibc 2.25)"
369 Disable the modern BIND checking of incoming hostnames and mail names
370 for invalid characters such as underscore (_), non-ASCII,
371 or control characters.
372 This option was present in glibc until version 2.24;
373 since glibc 2.25, it is deprecated, and its usage produces a warning.
375 .BR RES_KEEPTSIG " (unimplemented; deprecated in glibc 2.25)"
376 Do not strip TSIG records.
377 This option was present but unimplemented in glibc until version 2.24;
378 since glibc 2.25, it is deprecated, and its usage produces a warning.
380 .BR RES_BLAST " (unimplemented; deprecated in glibc 2.25)"
381 Send each query simultaneously and recursively to all servers.
382 This option was present but unimplemented in glibc until version 2.24;
383 since glibc 2.25, it is deprecated, and its usage produces a warning.
385 .BR RES_USEBSTRING " (glibc 2.3.4 to 2.24)"
386 Make reverse IPv6 lookups using the bit-label format described in RFC 2673;
387 if this option is not set (which is the default), then nibble format is used.
388 This option was removed in glibc 2.25,
389 since it relied on a backward-incompatible
390 DNS extension that was never deployed on the Internet.
392 .BR RES_NOIP6DOTINT " (glibc 2.24 and earlier)"
395 zone in IPv6 reverse lookup instead of
397 which is deprecated since glibc 2.3.4.
398 This option is present in glibc up to and including version 2.24,
399 where it is enabled by default.
400 In glibc 2.25, this option was removed.
402 .BR RES_USE_EDNS0 " (since glibc 2.6)"
403 Enables support for the DNS extensions (EDNS0) described in RFC 2671.
405 .BR RES_SNGLKUP " (since glibc 2.10)"
406 By default, glibc performs IPv4 and IPv6 lookups in parallel since
408 Some appliance DNS servers cannot handle these queries properly
409 and make the requests time out.
410 This option disables the behavior and makes glibc
411 perform the IPv6 and IPv4 requests sequentially
412 (at the cost of some slowdown of the resolving process).
417 option is enabled, opens a new socket for the each request.
420 Use DNSSEC with OK bit in OPT record.
425 Do not look up unqualified name as a top-level domain (TLD).
428 Default option which implies:
433 .BR RES_NOIP6DOTINT .
440 functions return 0 on success, or \-1 if an error
448 .BR res_nquerydomain (),
449 .BR res_querydomain (),
455 functions return the length
456 of the response, or \-1 if an error occurs.
462 functions return the length
463 of the compressed name, or \-1 if an error occurs.
465 In the case of an error return from
470 .BR res_nquerydomain (),
472 .BR res_querydomain (),
476 .BR gethostbyname (3))
477 can be consulted to determine the cause of the error.
481 resolver configuration file
484 resolver configuration file
486 For an explanation of the terms used in this section, see
494 Interface Attribute Value
500 .BR res_nquerydomain (),
502 T} Thread safety MT-Safe locale
507 T} Thread safety MT-Safe
515 .BR gethostbyname (3),
521 The GNU C library source file