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