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