Blame resolv/README

Packit 6c4009
The resolver in the GNU C Library
Packit 6c4009
*********************************
Packit 6c4009
Packit 6c4009
Starting with version 2.2, the resolver in the GNU C Library comes
Packit 6c4009
from BIND 8.  Only a subset of the src/lib/resolv part of libbind is
Packit 6c4009
included here; basically the parts that are needed to provide the
Packit 6c4009
functionality present in the resolver from BIND 4.9.7 that was
Packit 6c4009
included in the previous release of the GNU C Library, augmented by
Packit 6c4009
the parts needed to provide thread-safety.  This means that support
Packit 6c4009
for things as dynamic DNS updates and TSIG keys isn't included.  If
Packit 6c4009
you need those facilities, please take a look at the full BIND
Packit 6c4009
distribution.
Packit 6c4009
Packit 6c4009
Packit 6c4009
Differences
Packit 6c4009
===========
Packit 6c4009
Packit 6c4009
The resolver in the GNU C Library still differs from what's in BIND
Packit 6c4009
8.2.3-T5B:
Packit 6c4009
Packit 6c4009
* The RES_DEBUG option (`options debug' in /etc/resolv.conf) has been
Packit 6c4009
  disabled.
Packit 6c4009
Packit 6c4009
* The resolver in glibc allows underscores in domain names.
Packit 6c4009
Packit 6c4009
* The <resolv.h> header in glibc includes <netinet/in.h> and
Packit 6c4009
  <arpa/nameser.h> to make it self-contained.
Packit 6c4009
Packit 6c4009
* The `res_close' function in glibc only tries to close open files
Packit 6c4009
  referenced through `_res' if the RES_INIT bit is set in
Packit 6c4009
  `_res.options'.  This fixes a potential security bug with programs
Packit 6c4009
  that bogusly call `res_close' without initialising the resolver
Packit 6c4009
  state first.  Note that the thread-safe `res_nclose' still doesn't
Packit 6c4009
  check the RES_INIT bit.  By the way, you're not really supposed to
Packit 6c4009
  call `res_close/res_nclose' directly.
Packit 6c4009
Packit 6c4009
* The resolver in glibc can connect to a nameserver over IPv6.  Just
Packit 6c4009
  specify the IPv6 address in /etc/resolv.conf.  You cannot change the
Packit 6c4009
  address of an IPv6 nameserver dynamically in your program though.
Packit 6c4009
Packit 6c4009
Packit 6c4009
Using the resolver in multi-threaded code
Packit 6c4009
=========================================
Packit 6c4009
Packit 6c4009
The traditional resolver interfaces `res_query', `res_search',
Packit 6c4009
`res_mkquery', `res_send' and `res_init', used a static (global)
Packit 6c4009
resolver state stored in the `_res' structure.  Therefore, these
Packit 6c4009
interfaces are not thread-safe.  Therefore, BIND 8.2 introduced a set
Packit 6c4009
of "new" interfaces `res_nquery', `res_nsearch', `res_nmkquery',
Packit 6c4009
`res_nsend' and `res_ninit' that take a `res_state' as their first
Packit 6c4009
argument, so you can use a per-thread resolver state.  In glibc, when
Packit 6c4009
you link with -lpthread, such a per-thread resolver state is already
Packit 6c4009
present.  It can be accessed using `_res', which has been redefined as
Packit 6c4009
a macro, in a similar way to what has been done for the `errno' and
Packit 6c4009
`h_errno' variables.  This per-thread resolver state is also used for
Packit 6c4009
the `gethostby*' family of functions, which means that for example
Packit 6c4009
`gethostbyname_r' is now fully thread-safe and re-entrant.  The
Packit 6c4009
traditional resolver interfaces however, continue to use a single
Packit 6c4009
resolver state and are therefore still thread-unsafe.  The resolver
Packit 6c4009
state is the same resolver state that is used for the initial ("main")
Packit 6c4009
thread.
Packit 6c4009
Packit 6c4009
This has the following consequences for existing binaries and source
Packit 6c4009
code:
Packit 6c4009
Packit 6c4009
* Single-threaded programs will continue to work.  There should be no
Packit 6c4009
  user-visible changes when you recompile them.
Packit 6c4009
Packit 6c4009
* Multi-threaded programs that use the traditional resolver interfaces
Packit 6c4009
  in the "main" thread should continue to work, except that they no
Packit 6c4009
  longer see any changes in the global resolver state caused by calls
Packit 6c4009
  to, for example, `gethostbyname' in other threads.  Again there
Packit 6c4009
  should be no user-visible changes when you recompile these programs.
Packit 6c4009
Packit 6c4009
* Multi-threaded programs that use the traditional resolver interfaces
Packit 6c4009
  in more than one thread should be just as buggy as before (there are
Packit 6c4009
  no problems if you use proper locking of course).  If you recompile
Packit 6c4009
  these programs, manipulating the _res structure in threads other
Packit 6c4009
  than the "main" thread will seem to have no effect though.
Packit 6c4009
Packit 6c4009
* In Multi-threaded that manipulate the _res structure, calls to
Packit 6c4009
  functions like `gethostbyname' in threads other than the "main"
Packit 6c4009
  thread won't be influenced by the those changes anymore.
Packit 6c4009
Packit 6c4009
We recommend to use the new thread-safe interfaces in new code, since
Packit 6c4009
the traditional interfaces have been deprecated by the BIND folks.
Packit 6c4009
For compatibility with other (older) systems you might want to
Packit 6c4009
continue to use those interfaces though.
Packit 6c4009
Packit 6c4009
Packit 6c4009
Using the resolver in C++ code
Packit 6c4009
==============================
Packit 6c4009
Packit 6c4009
There resolver contains some hooks which will allow the user to
Packit 6c4009
install some callback functions that make it possible to filter DNS
Packit 6c4009
requests and responses.  Although we do not encourage you to make use
Packit 6c4009
of this facility at all, C++ developers should realise that it isn't
Packit 6c4009
safe to throw exceptions from such callback functions.
Packit 6c4009
Packit 6c4009
Packit 6c4009
Source code
Packit 6c4009
===========
Packit 6c4009
Packit 6c4009
The following files come from the BIND distribution (currently version
Packit 6c4009
8.2.3-T5B):
Packit 6c4009
Packit 6c4009
src/include/
Packit 6c4009
  arpa/nameser.h
Packit 6c4009
  arpa/nameser_compat.h
Packit 6c4009
  resolv.h
Packit 6c4009
Packit 6c4009
src/lib/resolv/
Packit 6c4009
  herror.c
Packit 6c4009
  res_comp.c
Packit 6c4009
  res_data.c
Packit 6c4009
  res_debug.c
Packit 6c4009
  res_init.c
Packit 6c4009
  res_mkquery.c
Packit 6c4009
  res_query.c
Packit 6c4009
  res_send.c
Packit 6c4009
Packit 6c4009
src/lib/nameser/
Packit 6c4009
  ns_name.c
Packit 6c4009
  ns_netint.c
Packit 6c4009
  ns_parse.c
Packit 6c4009
  ns_print.c
Packit 6c4009
  ns_samedomain.c
Packit 6c4009
  ns_ttl.c
Packit 6c4009
Packit 6c4009
src/lib/inet/
Packit 6c4009
  inet_addr.c
Packit 6c4009
  inet_net_ntop.c
Packit 6c4009
  inet_net_pton.c
Packit 6c4009
  inet_neta.c
Packit 6c4009
  inet_ntop.c
Packit 6c4009
  inet_pton.c
Packit 6c4009
  nsap_addr.c
Packit 6c4009
Packit 6c4009
src/lib/isc/
Packit 6c4009
  base64.c
Packit 6c4009
Packit 6c4009
Some of these files have been optimised a bit, and adaptations have
Packit 6c4009
been made to make them fit in with the rest of glibc.
Packit 6c4009
Packit 6c4009
res_libc.c is home-brewn, although parts of it are taken from res_data.c.
Packit 6c4009
Packit 6c4009
res_hconf.c and res_hconf.h were contributed by David Mosberger, and
Packit 6c4009
do not come from BIND.
Packit 6c4009
Packit 6c4009
The files gethnamaddr.c, mapv4v6addr.h and mapv4v6hostent.h are
Packit 6c4009
leftovers from BIND 4.9.7.