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