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 2017-09-15 "GNU" "Linux Programmer's Manual"
35 res_ninit, 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 "int res_nquery(res_state " statep ,
50 .BI " const char *" dname ", int " class ", int " type ,
51 .BI " unsigned char *" answer ", int " anslen );
53 .BI "int res_nsearch(res_state " statep ,
54 .BI " const char *" dname ", int " class ", int " type ,
55 .BI " unsigned char *" answer ", int " anslen );
57 .BI "int res_nquerydomain(res_state " statep ,
58 .BI " const char *" name ", const char *" domain ,
59 .BI " int " class ", int " type ", unsigned char *" answer ,
62 .BI "int res_nmkquery(res_state " statep ,
63 .BI " int " op ", const char *" dname ", int " class ,
64 .BI " int " type ", const unsigned char *" data ", int " datalen ,
65 .BI " const unsigned char *" newrr ,
66 .BI " unsigned char *" buf ", int " buflen );
68 .BI "int res_nsend(res_state " statep ,
69 .BI " const unsigned char *" msg ", int " msglen ,
70 .BI " unsigned char *" answer ", int " anslen );
72 .BI "int dn_comp(const char *" exp_dn ", unsigned char *" comp_dn ,
73 .BI " int " length ", unsigned char **" dnptrs ,
74 .BI " unsigned char **" lastdnptr );
76 .BI "int dn_expand(const unsigned char *" msg ,
77 .BI " const unsigned char *" eomorig ,
78 .BI " const unsigned char *" comp_dn ", char *" exp_dn ,
84 .B extern struct __res_state _res;
86 .B int res_init(void);
88 .BI "int res_query(const char *" dname ", int " class ", int " type ,
89 .BI " unsigned char *" answer ", int " anslen );
91 .BI "int res_search(const char *" dname ", int " class ", int " type ,
92 .BI " unsigned char *" answer ", int " anslen );
94 .BI "int res_querydomain(const char *" name ", const char *" domain ,
95 .BI " int " class ", int " type ", unsigned char *" answer ,
98 .BI "int res_mkquery(int " op ", const char *" dname ", int " class ,
99 .BI " int " type ", const unsigned char *" data ", int " datalen ,
100 .BI " const unsigned char *" newrr ,
101 .BI " unsigned char *" buf ", int " buflen );
103 .BI "int res_send(const unsigned char *" msg ", int " msglen ,
104 .BI " unsigned char *" answer ", int " anslen );
107 Link with \fI\-lresolv\fP.
110 This page is incomplete (various resolver functions provided by glibc
111 are not described) and likely out of date.
113 The functions described below make queries to and interpret
114 the responses from Internet domain name servers.
116 The API consists of a set of more modern, reentrant functions
117 and an older set of nonreentrant functions that have been superseded.
118 The traditional resolver interfaces such as
122 use some static (global) state stored in the
124 structure, rendering these functions non-thread-safe.
125 BIND 8.2 introduced a set of new interfaces
128 and so on, which take a
130 as their first argument, so you can use a per-thread resolver state.
136 functions read the configuration files (see
138 to get the default domain name and name
140 If no server is given, the local host is tried.
141 If no domain is given, that associated with the local host is used.
142 It can be overridden with the environment variable
147 is normally executed by the first call to one of the
154 functions query the name server for the
155 fully qualified domain name \fIname\fP of specified \fItype\fP and
157 The reply is left in the buffer \fIanswer\fP of length
158 \fIanslen\fP supplied by the caller.
164 functions make a query and waits for the response like
168 but in addition they implement the default and search
174 \fI_res\fP options below).
177 .BR res_nquerydomain ()
179 .BR res_querydomain ()
180 functions make a query using
181 .BR res_nquery ()/ res_query ()
182 on the concatenation of \fIname\fP and \fIdomain\fP.
184 The following functions are lower-level routines used by
185 .BR res_query ()/ res_query ().
191 functions construct a query message in \fIbuf\fP
192 of length \fIbuflen\fP for the domain name \fIdname\fP.
194 \fIop\fP is one of the following (typically
202 This option was removed in glibc 2.26,
203 .\" commit e4e794841e3140875f2aa86b90e2ada3d61e1244
204 since it has not been supported by DNS servers for a very long time.
207 Notify secondary of SOA (Start of Authority) change.
209 \fInewrr\fP is currently unused.
215 function send a preformatted query given in
216 \fImsg\fP of length \fImsglen\fP and returns the answer in \fIanswer\fP
217 which is of length \fIanslen\fP.
219 .BR res_ninit ()/ res_init ()
220 if it has not already been called.
224 function compresses the domain name \fIexp_dn\fP
225 and stores it in the buffer \fIcomp_dn\fP of length \fIlength\fP.
226 The compression uses an array of pointers \fIdnptrs\fP to previously
227 compressed names in the current message.
228 The first pointer points
229 to the beginning of the message and the list ends with NULL.
230 The limit of the array is specified by \fIlastdnptr\fP.
231 If \fIdnptr\fP is NULL, domain names are not compressed.
232 If \fIlastdnptr\fP is NULL, the list
233 of labels is not updated.
237 function expands the compressed domain name
238 \fIcomp_dn\fP to a full domain name, which is placed in the buffer
239 \fIexp_dn\fP of size \fIlength\fP.
240 The compressed name is contained
241 in a query or reply message, and \fImsg\fP points to the beginning of
244 The resolver routines use configuration and state information
247 structure (either passed as the
249 argument, or in the global variable
251 in the case of the older nonreentrant functions).
252 The only field of this structure that is normally manipulated by the
256 This field can contain the bitwise "OR"
257 of the following options:
267 Print debugging messages.
268 This option is available only if glibc was built with debugging enabled,
269 .\" See resolv/README.
270 .\" Support for RES_DEBUG was made conditional in glibc 2.2.
271 which is not the default.
273 .BR RES_AAONLY " (unimplemented; deprecated in glibc 2.25)"
274 Accept authoritative answers only.
277 it finds an authoritative answer or returns an error.
278 This option was present but unimplemented in glibc until version 2.24;
279 since glibc 2.25, it is deprecated, and its usage produces a warning.
282 Use TCP connections for queries rather than UDP datagrams.
284 .BR RES_PRIMARY " (unimplemented; deprecated in glibc 2.25)"
285 Query primary domain name server only.
286 This option was present but unimplemented in glibc until version 2.24;
287 since glibc 2.25, it is deprecated, and its usage produces a warning.
290 Ignore truncation errors.
291 Don't retry with TCP.
294 Set the recursion desired bit in queries.
295 Recursion is carried out
296 by the domain name server, not by
298 [Enabled by default].
303 will append the default domain name to
304 single component names\(emthat is, those that do not contain a dot.
305 [Enabled by default].
310 to keep the TCP connection open between queries.
315 will search for hostnames in the current
316 domain and in parent domains.
317 This option is used by
318 .BR gethostbyname (3).
319 [Enabled by default].
322 Accept a response from a wrong server.
323 This can be used to detect potential security hazards,
324 but you need to compile glibc with debugging enabled and use
326 option (for debug purpose only).
329 Accept a response which contains a wrong query.
330 This can be used to detect potential security hazards,
331 but you need to compile glibc with debugging enabled and use
333 option (for debug purpose only).
338 environment variable.
341 Try an AAAA query before an A query inside the
342 .BR gethostbyname (3)
343 function, and map IPv4 responses in IPv6 "tunneled form" if no AAAA records
344 are found but an A record set exists.
345 Since glibc 2.25, this option is deprecated,
346 and its usage produces a warning;
347 applications should use
350 .BR gethostbyname (3).
353 Causes round-robin selection of name servers from among those listed.
354 This has the effect of spreading the query load among all listed servers,
355 rather than having all clients try the first listed server first every
358 .BR RES_NOCHECKNAME " (unimplemented; deprecated in glibc 2.25)"
359 Disable the modern BIND checking of incoming hostnames and mail names
360 for invalid characters such as underscore (_), non-ASCII,
361 or control characters.
362 This option was present in glibc until version 2.24;
363 since glibc 2.25, it is deprecated, and its usage produces a warning.
365 .BR RES_KEEPTSIG " (unimplemented; deprecated in glibc 2.25)"
366 Do not strip TSIG records.
367 This option was present but unimplemented in glibc until version 2.24;
368 since glibc 2.25, it is deprecated, and its usage produces a warning.
370 .B RES_BLAST " (unimplemented; deprecated in glibc 2.25)"
371 Send each query simultaneously and recursively to all servers.
372 This option was present but unimplemented in glibc until version 2.24;
373 since glibc 2.25, it is deprecated, and its usage produces a warning.
375 .BR RES_USEBSTRING " (glibc 2.3.4 to 2.24)"
376 Make reverse IPv6 lookups using the bit-label format described in RFC 2673;
377 if this option is not set (which is the default), then nibble format is used.
378 This option was removed in glibc 2.25,
379 since it relied on a backward-incompatible
380 DNS extension that was never deployed on the Internet.
382 .BR RES_NOIP6DOTINT " (glibc 2.24 and earlier)"
385 zone in IPv6 reverse lookup instead of
387 which is deprecated since glibc 2.3.4.
388 This option is present in glibc up to and including version 2.24,
389 where it is enabled by default.
390 In glibc 2.25, this option was removed.
392 .BR RES_USE_EDNS0 " (since glibc 2.6)"
393 Enables support for the DNS extensions (EDNS0) described in RFC 2671.
395 .BR RES_SNGLKUP " (since glibc 2.10)"
396 By default, glibc performs IPv4 and IPv6 lookups in parallel since
398 Some appliance DNS servers cannot handle these queries properly
399 and make the requests time out.
400 This option disables the behavior and makes glibc
401 perform the IPv6 and IPv4 requests sequentially
402 (at the cost of some slowdown of the resolving process).
407 option is enabled, opens a new socket for the each request.
410 Use DNSSEC with OK bit in OPT record.
415 Do not look up unqualified name as a top-level domain (TLD).
418 Default option which implies:
423 .BR RES_NOIP6DOTINT .
430 functions return 0 on success, or \-1 if an error
438 .BR res_nquerydomain (),
439 .BR res_querydomain (),
445 functions return the length
446 of the response, or \-1 if an error occurs.
452 functions return the length
453 of the compressed name, or \-1 if an error occurs.
457 resolver configuration file
460 resolver configuration file
462 For an explanation of the terms used in this section, see
468 Interface Attribute Value
474 .BR res_nquerydomain (),
476 T} Thread safety MT-Safe locale
482 T} Thread safety MT-Safe
488 .BR gethostbyname (3),
494 The GNU C library source file