1 The resolver in the GNU C Library
2 *********************************
4 Starting with version 2.2, the resolver in the GNU C Library comes
5 from BIND 8. Only a subset of the src/lib/resolv part of libbind is
6 included here; basically the parts that are needed to provide the
7 functionality present in the resolver from BIND 4.9.7 that was
8 included in the previous release of the GNU C Library, augmented by
9 the parts needed to provide thread-safety. This means that support
10 for things as dynamic DNS updates and TSIG keys isn't included. If
11 you need those facilities, please take a look at the full BIND
18 The resolver in the GNU C Library still differs from what's in BIND
21 * The resolver in glibc strictly adheres to the recommendations in RFC
22 1535. BIND 8.2.3-T5B seems to relax those rules a bit (see the code
23 that's wrapped in `#ifndef RFC1535').
25 * The RES_DEBUG option (`options debug' in /etc/resolv.conf) has been
28 * The resolver in glibc allows underscores in domain names.
30 * The <resolv.h> header in glibc includes <netinet/in.h> and
31 <arpa/nameser.h> to make it self-contained.
33 * The `res_close' function in glibc only tries to close open files
34 referenced through `_res' if the RES_INIT bit is set in
35 `_res.options'. This fixes a potential security bug with programs
36 that bogusly call `res_close' without initialising the resolver
37 state first. Note that the thread-safe `res_nclose' still doesn't
38 check the RES_INIT bit. By the way, you're not really supposed to
39 call `res_close/res_nclose' directly.
41 * The resolver in glibc can connect to a nameserver over IPv6. Just
42 specify the IPv6 address in /etc/resolv.conf. You cannot change the
43 address of an IPv6 nameserver dynamically in your program though.
46 Using the resolver in multi-threaded code
47 =========================================
49 The traditional resolver interfaces `res_query', `res_search',
50 `res_mkquery', `res_send' and `res_init', used a static (global)
51 resolver state stored in the `_res' structure. Therefore, these
52 interfaces are not thread-safe. Therefore, BIND 8.2 introduced a set
53 of "new" interfaces `res_nquery', `res_nsearch', `res_nmkquery',
54 `res_nsend' and `res_ninit' that take a `res_state' as their first
55 argument, so you can use a per-thread resolver state. In glibc, when
56 you link with -lpthread, such a per-thread resolver state is already
57 present. It can be accessed using `_res', which has been redefined as
58 a macro, in a similar way to what has been done for the `errno' and
59 `h_errno' variables. This per-thread resolver state is also used for
60 the `gethostby*' family of functions, which means that for example
61 `gethostbyname_r' is now fully thread-safe and re-entrant. The
62 traditional resolver interfaces however, continue to use a single
63 resolver state and are therefore still thread-unsafe. The resolver
64 state is the same resolver state that is used for the initial ("main")
67 This has the following consequences for existing binaries and source
70 * Single-threaded programs will continue to work. There should be no
71 user-visible changes when you recompile them.
73 * Multi-threaded programs that use the traditional resolver interfaces
74 in the "main" thread should continue to work, except that they no
75 longer see any changes in the global resolver state caused by calls
76 to, for example, `gethostbyname' in other threads. Again there
77 should be no user-visible changes when you recompile these programs.
79 * Multi-threaded programs that use the traditional resolver interfaces
80 in more than one thread should be just as buggy as before (there are
81 no problems if you use proper locking of course). If you recompile
82 these programs, manipulating the _res structure in threads other
83 than the "main" thread will seem to have no effect though.
85 * In Multi-threaded that manipulate the _res structure, calls to
86 functions like `gethostbyname' in threads other than the "main"
87 thread won't be influenced by the those changes anymore. So if you
88 set RES_USE_INET6, a call to `gethostbyname' won't return any IPv6
89 hosts anymore. If you recompile such programs, manipulating the
90 _res structure will affect the thread in which you do so instead of
93 We recommend to use the new thread-safe interfaces in new code, since
94 the traditional interfaces have been deprecated by the BIND folks.
95 For compatibility with other (older) systems you might want to
96 continue to use those interfaces though.
99 Using the resolver in C++ code
100 ==============================
102 There resolver contains some hooks which will allow the user to
103 install some callback functions that make it possible to filter DNS
104 requests and responses. Although we do not encourage you to make use
105 of this facility at all, C++ developers should realise that it isn't
106 safe to throw exceptions from such callback functions.
112 The following files come from the BIND distribution (currently version
117 arpa/nameser_compat.h
151 Some of these files have been optimised a bit, and adaptations have
152 been made to make them fit in with the rest of glibc. The more
153 non-obvious changes are wrapped in something like `#ifdef _LIBC'.
155 res_libc.c is home-brewn, although parts of it are taken from res_data.c.
157 res_hconf.c and res_hconf.h were contributed by David Mosberger, and
158 do not come from BIND.
160 The files gethnamaddr.c, mapv4v6addr.h and mapv4v6hostent.h are
161 leftovers from BIND 4.9.7.