Index: adns/Makefile.in
diff -u adns/Makefile.in:1.26 adns/Makefile.in:1.27
--- adns/Makefile.in:1.26	Sun Sep 17 15:10:57 2000
+++ adns/Makefile.in	Tue Jul  1 22:59:38 2003
@@ -23,7 +23,7 @@
 
 # Remember to change ADNS_VERSION_STRING in client/client.h too, and
 # possibly library soname (MAJOR and MINOR in settings.make.in).
-DISTVERSION=	1.0
+DISTVERSION=	1.1
 
 srcdir=		@srcdir@
 VPATH=		@srcdir@
Index: adns/README
diff -u adns/README:1.13 adns/README:1.15
--- adns/README:1.13	Sun Sep 17 15:09:22 2000
+++ adns/README	Sun Jun 29 20:06:27 2003
@@ -1,12 +1,12 @@
 
                                    GNU adns
-                                       
+
    Advanced, easy to use, asynchronous-capable DNS client library and
    utilities.
-   
+
    adns is a resolver library for C (and C++) programs, and a collection
    of useful DNS resolver utilities.
-   
+
 C library
 
    In contrast with the standard interfaces, gethostbyname et al and
@@ -38,7 +38,7 @@
        TCP in case of long replies or queries, or to other nameservers if
        several are available. It has sensible handling of bad responses
        etc.
-       
+
 DNS utility programs
 
    adns also comes with a number of utility programs for use from the
@@ -54,37 +54,49 @@
        general-purpose DNS helper program for scripting languages which
        can invoke and communicate with subprocesses. See the [1]adnshost
        usage message for a summary of its capabilities.
-       
+
+Forthcoming:
+
+   I hope that future versions may also have the following features:
+     * The library should be useable by threads in a multithreaded
+       program in a natural way. It should multiplex many threads'
+       queries through a single query socket.
+     * IPv6 support.
+     * Some kind of awareness of DNSSEC.
+     * Possibly some very limited caching behaviour.
+     * There was, at one point, a draft native Perl interface from Tony
+       Finch.
+
 Documentation
 
    I'm afraid there is no manual yet. However, competent C programmers
    should be able to use the library based on the [2]commented adns.h
    header file, and the usage messages for the programs should be
    sufficient.
-   
+
 Feedback
 
    I'd be pleased if you would let me know if you're using my library in
    your project, and what you think of it.
-   
+
    If you are subscribed to adns-discuss please send feedback, including
    bug reports, there; otherwise send mail to
    adns-bugreports@chiark.greenend.org.uk. If you'd prefer that your
    message wasn't forwarded to the adns-bugreports list, send it to
    adns-maint@chiark.greenend.org.uk.
-   
+
 Mailinglists
 
    I have set up mailinglists adns-announce and adns-discuss. The
    announcements list is moderated and will contain only announcements of
    important bugs, new versions, etc. The bug reports address mentioned
    above is also a mailing list; feel free to subscribe to it.
-   
+
    There are [3]archives and subscription web pages, or you can subscribe
    by sending mail containing the word `subscribe' to
    adns-announce-REQUEST@chiark.greenend.org.uk or
    adns-discuss-REQUEST@chiark.greenend.org.uk.
-   
+
 Download
 
    Available for download from [4]chiark.greenend.org.uk are:
@@ -92,52 +104,60 @@
      * [6]adns.h API header file with comments, and [7]usage message for
        adnshost (currently there is no manual, sorry).
      * All versions released so far are also available via [8]anonymous
-       FTP and [9]HTTP,
-     * A mirror of my CVS repository is available via rsync from
+       FTP and [9]HTTP.
+
+   You can also access the project CVS repositories:
+     * A mirror of the source code repository is available via rsync from
        rsync.chiark.greenend.org.uk::ftp/users/ian/cvs-pub/adns (use FTP
        first to find your way around), or via [10]cvsweb.
-       
-   adns is also available from the [11]GNU Project FTP servers and their
-   [12]mirrors.
-   
+     * This web page is maintained in [11]Savannah, where you can browse
+       the [12]webpage CVS.
+
+   adns is also available from the [13]GNU Project FTP servers and their
+   [14]mirrors.
+
 Technical note
 
-   adns requires a real nameserver like [13]BIND or [14]Dents running on
+   adns requires a real nameserver like [15]BIND or [16]Dents running on
    the same system or a nearby one, which must be willing to provide
    `recursive service'. I.e., adns is a `stub resolver'. All properly
    configured UN*X and GNU systems will already have such nameserver(s);
    they are usually listed in /etc/resolv.conf.
-   
+
+References and related projects
+
+   There is a [17]port to MS Visual Studio 6 C++ by Jarle Aase.
+
 Copyright and licensing
 
-   adns is Copyright 1997-2000 Ian Jackson, Copyright 1999-2000 Tony
+   adns is Copyright 1997-2001 Ian Jackson, Copyright 1999-2000 Tony
    Finch, and Copyright (C) 1991 Massachusetts Institute of Technology.
-   
+
    adns is free software; you can redistribute it and/or modify it under
    the terms of the GNU General Public License as published by the Free
    Software Foundation; either version 2 of the License, or (at your
    option) any later version.
-   
+
    This program and documentation is distributed in the hope that it will
    be useful, but without any warranty; without even the implied warranty
    of merchantability or fitness for a particular purpose. See the
-   [15]GNU General Public License for more details.
-   
+   [18]GNU General Public License for more details.
+
    You should have received a copy of the GNU General Public License
    along with adns, or one should be available above; if not, write to
-   the [16]Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+   the [19]Free Software Foundation, 59 Temple Place - Suite 330, Boston,
    MA 02111-1307, USA, or email adns-maint@chiark.greenend.org.uk.
      _________________________________________________________________
-   
-   [17]Ian Jackson / [18]adns-maint@chiark.greenend.org.uk; more [19]free
+
+   [20]Ian Jackson / [21]adns-maint@chiark.greenend.org.uk; more [22]free
    software by me.
-   
-   [20]GNU home page; [21]chiark home page; [22]site or mirror home page
-   
-   This web page is Copyright (C)1996-2000 Ian Jackson. See the
-   [23]Copyright/acknowledgements.
-   
-   Use any browser - [24]Campaign for a non-browser-specific WWW
+
+   [23]GNU home page; [24]chiark home page; [25]site or mirror home page
+
+   This web page is Copyright (C)1996-2001 Ian Jackson. See the
+   [26]Copyright/acknowledgements.
+
+   Use any browser - [27]Campaign for a non-browser-specific WWW
 
 References
 
@@ -151,17 +171,20 @@
    8. ftp://ftp.chiark.greenend.org.uk/users/ian/adns/
    9. http://www.chiark.greenend.org.uk/~ian/adns/ftp/
   10. http://www.chiark.greenend.org.uk/ucgi/~ijackson/cvsweb/adns/
-  11. http://www.gnu.org/
-  12. http://www.gnu.org/order/ftp.html
-  13. http://www.isc.org/view.cgi?/products/BIND/index.phtml
-  14. http://www.dents.org/
-  15. http://www.chiark.greenend.org.uk/~ian/COPYING.txt
-  16. http://www.fsf.org/
-  17. http://www.chiark.greenend.org.uk/
-  18. mailto:adns-maint@chiark.greenend.org.uk
-  19. http://www.chiark.greenend.org.uk/~ian/software/
-  20. http://www.gnu.org/
-  21. http://www.chiark.greenend.org.uk/
-  22. file://localhost/
-  23. http://www.chiark.greenend.org.uk/~ian/sw-www-copy.html
-  24. http://www.anybrowser.org/campaign/
+  11. http://savannah.gnu.org/
+  12. http://savannah.gnu.org/cgi-bin/viewcvs/software/adns/?cvsroot=www.gnu.org
+  13. http://www.gnu.org/
+  14. http://www.gnu.org/order/ftp.html
+  15. http://www.isc.org/view.cgi?/products/BIND/index.phtml
+  16. http://www.dents.org/
+  17. http://adns.jgaa.com/
+  18. http://www.chiark.greenend.org.uk/~ian/COPYING.txt
+  19. http://www.fsf.org/
+  20. http://www.chiark.greenend.org.uk/
+  21. mailto:adns-maint@chiark.greenend.org.uk
+  22. http://www.chiark.greenend.org.uk/~ian/software/
+  23. http://www.gnu.org/
+  24. http://www.chiark.greenend.org.uk/
+  25. file://localhost/
+  26. http://www.chiark.greenend.org.uk/~ian/sw-www-copy.html
+  27. http://www.anybrowser.org/campaign/
Index: adns/README.html
diff -u adns/README.html:1.5 adns/README.html:1.8
--- adns/README.html:1.5	Sun Sep 17 15:09:22 2000
+++ adns/README.html	Sun Jun 29 20:06:00 2003
@@ -1,7 +1,6 @@
-<html>
-<head>
-<title>adns - advanced, alternative, asynchronous resolver</title>
+<html><head><title>adns - advanced, alternative, asynchronous resolver</title>
 <link rev="made" href="mailto:adns-maint@chiark.greenend.org.uk">
+<meta name="keywords" content="adns">
 </head>
 <body>
 <h1>GNU adns</h1>
@@ -9,14 +8,14 @@
 <strong>Advanced, easy to use, asynchronous-capable DNS client
 library and utilities.</strong>
 
-<!-- Note: this file is maintained in Ian Jackson's private CVS.  -->
+<!--      Note: this file must contain portable HTML !            -->
 <!--                                                              -->
 <!--  It is served on the GNU site and also from my own system,   -->
 <!--  under the URL http://www.chiark.greenend.org.uk/adns/       -->
 <!--  Please ensure that all links continine to be correct        -->
 <!--  both for www.gnu.org and chiark.                            -->
 <!--                                                              -->
-<!--  $Id: README.html,v 1.5 2000/09/17 14:09:22 ian Exp $        -->   
+<!--  $Id: README.html,v 1.8 2003/06/29 19:06:00 ian Exp $    -->   
 
 <p>
 
@@ -92,6 +91,26 @@
 
 </ul>
 
+<h2>Forthcoming:</h2>
+
+I hope that future versions may also have the following features:
+
+<ul>
+
+<li>The library should be useable by threads in a multithreaded
+program in a natural way.  It should multiplex many threads' queries
+through a single query socket.
+
+<li>IPv6 support.
+
+<li>Some kind of awareness of DNSSEC.
+
+<li>Possibly some very limited caching behaviour.
+
+<li>There was, at one point, a draft native Perl interface from Tony Finch.
+
+</ul>
+
 <h2>Documentation</h2>
 
 I'm afraid there is no manual yet.  However, competent C programmers
@@ -144,11 +163,19 @@
     message for adnshost</A> (currently there is no manual, sorry).
 <li>All versions released so far are also available via
     <A href="ftp://ftp.chiark.greenend.org.uk/users/ian/adns/">anonymous
-    FTP</A> and <A href="http://www.chiark.greenend.org.uk/~ian/adns/ftp/">HTTP</A>,
-<li>A mirror of my CVS repository is available via rsync from
+    FTP</A> and <A href="http://www.chiark.greenend.org.uk/~ian/adns/ftp/">HTTP</A>.
+</ul>
+
+You can also access the project CVS repositories:
+<ul>
+<li>A mirror of the source code repository is available via rsync from
     <code>rsync.chiark.greenend.org.uk::ftp/users/ian/cvs-pub/adns</code>
     (use FTP first to find your way around), or via
     <A href="http://www.chiark.greenend.org.uk/ucgi/~ijackson/cvsweb/adns/">cvsweb</A>.
+<li>This web page is maintained in
+    <A href="http://savannah.gnu.org/">Savannah</A>,
+    where you can browse the
+    <A href="http://savannah.gnu.org/cgi-bin/viewcvs/software/adns/?cvsroot=www.gnu.org">webpage CVS</A>.
 </ul>
 
 adns is also available from the
@@ -166,9 +193,14 @@
 configured UN*X and GNU systems will already have such nameserver(s);
 they are usually listed in /etc/resolv.conf.
 
+<h2>References and related projects</h2>
+
+There is a <a href="http://adns.jgaa.com/">port to MS Visual Studio 6
+C++</a> by Jarle Aase.
+
 <h2>Copyright and licensing</h2>
 
-<kbd>adns</kbd> is Copyright 1997-2000 Ian Jackson, Copyright
+<kbd>adns</kbd> is Copyright 1997-2001 Ian Jackson, Copyright
 1999-2000 Tony Finch, and Copyright (C) 1991 Massachusetts Institute
 of Technology.
 
@@ -211,7 +243,7 @@
 <A href="/">site or mirror home page</A>
 <p>
 
-This web page is Copyright (C)1996-2000 Ian Jackson.  See the
+This web page is Copyright (C)1996-2001 Ian Jackson.  See the
 <A href="http://www.chiark.greenend.org.uk/~ian/sw-www-copy.html">Copyright/acknowledgements</A>.
 <p>
 
Index: adns/TODO
diff -u adns/TODO:1.11 adns/TODO:1.14
--- adns/TODO:1.11	Sun Sep 17 01:24:24 2000
+++ adns/TODO	Sun Jun 15 17:54:29 2003
@@ -1,4 +1,8 @@
+BUGS:
+Arnout Engelen <arnouten@sci.kun.nl> reports servfail is thought conclusive
+
 WISHLIST:
+* Support for as-yet-unrecognised query types.
 * Make timeouts configurable.
 * `fake' reverse queries (give nnn.nnn.nnn.nnn either always or on error)
 * `fake' forward queries (allow nnn.nnn.nnn.nnn -> A)
@@ -9,3 +13,4 @@
 * Threadsafe version/mode.
 * Caching in the library.
 * SRV RRs.
+* Make port configurable in config file.
Index: adns/acconfig.h
diff -u adns/acconfig.h:1.8 adns/acconfig.h:1.9
--- adns/acconfig.h:1.8	Sun Sep 17 01:24:24 2000
+++ adns/acconfig.h	Tue Dec 18 00:03:20 2001
@@ -114,7 +114,3 @@
 #ifdef HAVEUSE_RPCTYPES_H
 #include <rpc/types.h>
 #endif
-
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif
Index: adns/changelog
diff -u adns/changelog:1.139 adns/changelog:1.152
--- adns/changelog:1.139	Sun Sep 17 15:16:22 2000
+++ adns/changelog	Tue Jul  1 22:55:37 2003
@@ -1,3 +1,27 @@
+adns (1.1); urgency=medium
+
+  Major bugfixes:
+  * Do not spin if connect() fails immediately (!)
+  * Stop searching on a CNAME (even if it's broken).
+  * When search list runs out, _qf_owner sets owner to query domain.
+  * Fix bogus multiple updates to p in transmit.c (!)
+
+  Portability improvements:
+  * Fix up spurious #undef's in hredirect.h.
+  * Don't use <sys/select.h> any more, it was a mistake made in pre-1.0
+    (and there doesn't seem to be much explanation why).
+  * Understand and sort of check OpenBSD `lookup' resolv.conf directive.
+  * #include <stdlib.h> in internal.h (for abort etc).
+  * Always #include <sys/types.h> before <sys/socket.h> (for FreeBSD 4.6).
+
+  Cosmetic and documentation improvements:
+  * Added wishlist entry re configurable port no.
+  * Problem with SERVFAIL in TODO.
+  * README.html: mentioned Jarle Aase's Windows port, and other fixes.
+  * Some better source code formatting/wrapping.
+
+ -- Ian Jackson <ian@davenant.greenend.org.uk>  Tue,  1 Jul 2003 22:55:29 +0100
+
 adns (1.0); urgency=medium
 
   Bugfixes:
Index: adns/configure
diff -u adns/configure:1.13 adns/configure:1.14
--- adns/configure:1.13	Thu Sep 14 02:23:39 2000
+++ adns/configure	Tue Dec 18 00:03:20 2001
@@ -1668,46 +1668,6 @@
  fi
 
 
-for ac_hdr in sys/select.h
-do
-ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
-echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1676: checking for $ac_hdr" >&5
-if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  cat > conftest.$ac_ext <<EOF
-#line 1681 "configure"
-#include "confdefs.h"
-#include <$ac_hdr>
-EOF
-ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1686: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
-if test -z "$ac_err"; then
-  rm -rf conftest*
-  eval "ac_cv_header_$ac_safe=yes"
-else
-  echo "$ac_err" >&5
-  echo "configure: failed program was:" >&5
-  cat conftest.$ac_ext >&5
-  rm -rf conftest*
-  eval "ac_cv_header_$ac_safe=no"
-fi
-rm -f conftest*
-fi
-if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
-  echo "$ac_t""yes" 1>&6
-    ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
-  cat >> confdefs.h <<EOF
-#define $ac_tr_hdr 1
-EOF
- 
-else
-  echo "$ac_t""no" 1>&6
-fi
-done
-
 
 
 
Index: adns/configure.in
diff -u adns/configure.in:1.17 adns/configure.in:1.18
--- adns/configure.in:1.17	Sun Sep 17 01:24:24 2000
+++ adns/configure.in	Tue Dec 18 00:03:20 2001
@@ -113,7 +113,6 @@
  AC_MSG_RESULT(no))
 
 ADNS_C_GCCATTRIB
-AC_CHECK_HEADERS(sys/select.h)
 
 AC_SUBST(WARNS)
 
Index: adns/client/client.h
diff -u adns/client/client.h:1.1 adns/client/client.h:1.2
--- adns/client/client.h:1.1	Sun Sep 17 15:09:10 2000
+++ adns/client/client.h	Tue Jul  1 22:55:37 2003
@@ -28,7 +28,7 @@
 #ifndef CLIENT_H_INCLUDED
 #define CLIENT_H_INCLUDED
 
-#define ADNS_VERSION_STRING "1.0"
+#define ADNS_VERSION_STRING "1.1"
 
 #define COPYRIGHT_MESSAGE \
  "Copyright (C) 1997-2000 Ian Jackson <ian@davenant.greenend.org.uk>\n" \
Index: adns/regress/case-connfail.out
diff -u /dev/null adns/regress/case-connfail.out:1.1
--- /dev/null	Tue Jul  1 23:33:52 2003
+++ adns/regress/case-connfail.out	Sun Jun 22 14:49:20 2003
@@ -0,0 +1,9 @@
+adns debug: using nameserver 172.18.45.36
+adns debug: using nameserver 172.18.45.6
+davenant.greenend.org.uk flags 2 type 1adns warning: TCP connection failed: connect: Socket operation on non-socket (NS=172.18.45.36)
+adns warning: TCP connection failed: connect: Socket operation on non-socket (NS=172.18.45.6)
+ A(-) submitted
+adns warning: TCP connection failed: connect: Socket operation on non-socket (NS=172.18.45.36)
+adns warning: TCP connection failed: connect: Socket operation on non-socket (NS=172.18.45.6)
+davenant.greenend.org.uk flags 2 type A(-): All nameservers failed; nrrs=0; cname=$; owner=$; ttl=604800
+rc=0
Index: adns/regress/case-connfail.sys
diff -u /dev/null adns/regress/case-connfail.sys:1.1
--- /dev/null	Tue Jul  1 23:33:52 2003
+++ adns/regress/case-connfail.sys	Sun Jun 22 14:49:20 2003
@@ -0,0 +1,78 @@
+./adnstest 2ndserver
+:1 2/davenant.greenend.org.uk
+ start 1056289303.784817
+ socket type=SOCK_DGRAM
+ socket=6
+ +0.000031
+ fcntl fd=6 cmd=F_GETFL
+ fcntl=~O_NONBLOCK&...
+ +0.000010
+ fcntl fd=6 cmd=F_SETFL O_NONBLOCK|...
+ fcntl=OK
+ +0.000007
+ socket type=SOCK_STREAM
+ socket=7
+ +0.000059
+ fcntl fd=7 cmd=F_GETFL
+ fcntl=~O_NONBLOCK&...
+ +0.000007
+ fcntl fd=7 cmd=F_SETFL O_NONBLOCK|...
+ fcntl=OK
+ +0.000006
+ connect fd=7 addr=172.18.45.36:53
+ connect=ENOTSOCK
+ +0.000013
+ close fd=7
+ close=OK
+ +0.000031
+ socket type=SOCK_STREAM
+ socket=7
+ +0.000035
+ fcntl fd=7 cmd=F_GETFL
+ fcntl=~O_NONBLOCK&...
+ +0.000006
+ fcntl fd=7 cmd=F_SETFL O_NONBLOCK|...
+ fcntl=OK
+ +0.000007
+ connect fd=7 addr=172.18.45.6:53
+ connect=ENOTSOCK
+ +0.000008
+ close fd=7
+ close=OK
+ +0.000013
+ select max=7 rfds=[6] wfds=[] efds=[] to=0.000000
+ select=0 rfds=[] wfds=[] efds=[]
+ +0.000036
+ socket type=SOCK_STREAM
+ socket=7
+ +0.000036
+ fcntl fd=7 cmd=F_GETFL
+ fcntl=~O_NONBLOCK&...
+ +0.000007
+ fcntl fd=7 cmd=F_SETFL O_NONBLOCK|...
+ fcntl=OK
+ +0.000006
+ connect fd=7 addr=172.18.45.36:53
+ connect=ENOTSOCK
+ +0.000008
+ close fd=7
+ close=OK
+ +0.000013
+ socket type=SOCK_STREAM
+ socket=7
+ +0.000036
+ fcntl fd=7 cmd=F_GETFL
+ fcntl=~O_NONBLOCK&...
+ +0.000007
+ fcntl fd=7 cmd=F_SETFL O_NONBLOCK|...
+ fcntl=OK
+ +0.000006
+ connect fd=7 addr=172.18.45.6:53
+ connect=ENOTSOCK
+ +0.000008
+ close fd=7
+ close=OK
+ +0.000012
+ close fd=6
+ close=OK
+ +0.000023
Index: adns/regress/case-ndots-as.out
diff -u adns/regress/case-ndots-as.out:1.1 adns/regress/case-ndots-as.out:1.2
--- adns/regress/case-ndots-as.out:1.1	Wed Jul 14 23:45:04 1999
+++ adns/regress/case-ndots-as.out	Sun Jun 22 14:01:04 2003
@@ -7,10 +7,10 @@
 test.iwj.relativity flags 5 type 1 A(-) submitted
 news.davenant.greenend.org.uk flags 5 type A(-): OK; nrrs=1; cname=davenant.relativity.greenend.org.uk; owner=news.davenant.greenend.org.uk; ttl=86400
  172.18.45.6
-newsx.davenant flags 5 type A(-): No such domain; nrrs=0; cname=$; owner=newsx.davenant.greenend.org.uk; ttl=86400
+newsx.davenant flags 5 type A(-): No such domain; nrrs=0; cname=$; owner=newsx.davenant; ttl=86400
 news.davenant flags 5 type A(-): OK; nrrs=1; cname=davenant.relativity.greenend.org.uk; owner=news.davenant.greenend.org.uk; ttl=86400
  172.18.45.6
 trunc.test.iwj.relativity flags 5 type A(-): No such data; nrrs=0; cname=$; owner=trunc.test.iwj.relativity.greenend.org.uk; ttl=60
-trunx.test.iwj.relativity flags 5 type A(-): No such domain; nrrs=0; cname=$; owner=trunx.test.iwj.relativity.greenend.org.uk; ttl=60
+trunx.test.iwj.relativity flags 5 type A(-): No such domain; nrrs=0; cname=$; owner=trunx.test.iwj.relativity; ttl=60
 test.iwj.relativity flags 5 type A(-): No such data; nrrs=0; cname=$; owner=test.iwj.relativity.greenend.org.uk; ttl=60
 rc=0
Index: adns/regress/case-ndots.out
diff -u adns/regress/case-ndots.out:1.1 adns/regress/case-ndots.out:1.2
--- adns/regress/case-ndots.out:1.1	Sat Apr 17 17:23:13 1999
+++ adns/regress/case-ndots.out	Sun Jun 22 14:01:04 2003
@@ -11,6 +11,6 @@
 news.davenant.greenend.org.uk flags 5 type A(-): OK; nrrs=1; cname=davenant.relativity.greenend.org.uk; owner=news.davenant.greenend.org.uk; ttl=86400
  172.18.45.6
 trunc.test.iwj.relativity flags 5 type A(-): No such data; nrrs=0; cname=$; owner=trunc.test.iwj.relativity.greenend.org.uk; ttl=60
-trunx.test.iwj.relativity flags 5 type A(-): No such domain; nrrs=0; cname=$; owner=trunx.test.iwj.relativity.greenend.org.uk; ttl=60
+trunx.test.iwj.relativity flags 5 type A(-): No such domain; nrrs=0; cname=$; owner=trunx.test.iwj.relativity; ttl=60
 test.iwj.relativity flags 5 type A(-): No such data; nrrs=0; cname=$; owner=test.iwj.relativity.greenend.org.uk; ttl=60
 rc=0
Index: adns/regress/hcommon.c
diff -u adns/regress/hcommon.c:1.2 adns/regress/hcommon.c:1.3
--- adns/regress/hcommon.c:1.2	Sat Sep 16 23:34:16 2000
+++ adns/regress/hcommon.c	Sun Jun 22 14:49:20 2003
@@ -29,6 +29,7 @@
   { "ECONNRESET",                ECONNRESET                   },
   { "ECONNREFUSED",              ECONNREFUSED                 },
   { "EPIPE",                     EPIPE                        },
+  { "ENOTSOCK",                  ENOTSOCK                     },
   {  0,                          0                            }
 };
 static vbuf vbw;
Index: adns/regress/hredirect.h
diff -u adns/regress/hredirect.h:1.1 adns/regress/hredirect.h:1.2
--- adns/regress/hredirect.h:1.1	Sat Sep 16 23:12:31 2000
+++ adns/regress/hredirect.h	Sun Jun 22 14:58:15 2003
@@ -23,16 +23,16 @@
 #define read Hread
 #undef write
 #define write Hwrite
-#undef int
+#undef writev
 #define writev Hwritev
-#undef int
+#undef gettimeofday
 #define gettimeofday Hgettimeofday
-#undef void*
+#undef malloc
 #define malloc Hmalloc
-#undef void
+#undef free
 #define free Hfree
-#undef void*
+#undef realloc
 #define realloc Hrealloc
-#undef void
+#undef exit
 #define exit Hexit
 #endif
Index: adns/regress/hredirect.h.m4
diff -u adns/regress/hredirect.h.m4:1.2 adns/regress/hredirect.h.m4:1.3
--- adns/regress/hredirect.h.m4:1.2	Sun Sep 17 01:24:24 2000
+++ adns/regress/hredirect.h.m4	Sun Jun 22 14:58:15 2003
@@ -33,7 +33,7 @@
 hm_create_nothing
 m4_define(`hm_syscall', `#undef $1
 #define $1 H$1')
-m4_define(`hm_specsyscall',`#undef $1
+m4_define(`hm_specsyscall',`#undef $2
 #define $2 H$2')
 m4_include(`hsyscalls.i4')
 
Index: adns/regress/hsyscalls.h
diff -u adns/regress/hsyscalls.h:1.1 adns/regress/hsyscalls.h:1.2
--- adns/regress/hsyscalls.h:1.1	Sat Sep 16 23:12:31 2000
+++ adns/regress/hsyscalls.h	Sun Nov 24 17:23:01 2002
@@ -1,5 +1,6 @@
 #ifndef HSYSCALLS_H_INCLUDED
 #define HSYSCALLS_H_INCLUDED
+#include <sys/types.h>
 #include <sys/time.h>
 #include <sys/socket.h>
 #include <sys/uio.h>
Index: adns/regress/hsyscalls.h.m4
diff -u adns/regress/hsyscalls.h.m4:1.2 adns/regress/hsyscalls.h.m4:1.3
--- adns/regress/hsyscalls.h.m4:1.2	Sun Sep 17 01:24:24 2000
+++ adns/regress/hsyscalls.h.m4	Sun Nov 24 17:23:01 2002
@@ -28,6 +28,7 @@
 #ifndef HSYSCALLS_H_INCLUDED
 #define HSYSCALLS_H_INCLUDED
 
+#include <sys/types.h>
 #include <sys/time.h>
 #include <sys/socket.h>
 #include <sys/uio.h>
Index: adns/src/adns.h
diff -u adns/src/adns.h:1.83 adns/src/adns.h:1.85
--- adns/src/adns.h:1.83	Sun Sep 17 02:56:18 2000
+++ adns/src/adns.h	Sun Jun 22 15:34:37 2003
@@ -51,7 +51,7 @@
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
  *
- *  $Id: adns.h,v 1.83 2000/09/17 01:56:18 ian Exp $
+ *  $Id: adns.h,v 1.85 2003/06/22 14:34:37 ian Exp $
  */
 
 #ifndef ADNS_H_INCLUDED
@@ -59,9 +59,9 @@
 
 #include <stdio.h>
 
+#include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <sys/types.h>
 #include <sys/time.h>
 #include <unistd.h>
 
@@ -75,63 +75,63 @@
 typedef struct adns__query *adns_query;
 
 typedef enum {
-  adns_if_noenv=        0x0001, /* do not look at environment */
-  adns_if_noerrprint=   0x0002, /* never print output to stderr (_debug overrides) */
-  adns_if_noserverwarn= 0x0004, /* do not warn to stderr about duff nameservers etc */
-  adns_if_debug=        0x0008, /* enable all output to stderr plus debug msgs */
-  adns_if_logpid=       0x0080, /* include pid in diagnostic output */
-  adns_if_noautosys=    0x0010, /* do not make syscalls at every opportunity */
-  adns_if_eintr=        0x0020, /* allow _wait and _synchronous to return EINTR */
-  adns_if_nosigpipe=    0x0040, /* applic has SIGPIPE set to SIG_IGN, do not protect */
-  adns_if_checkc_entex= 0x0100, /* do consistency checks on entry/exit to adns funcs */
-  adns_if_checkc_freq=  0x0300  /* do consistency checks very frequently (slow!) */
+ adns_if_noenv=       0x0001,/* do not look at environment */
+ adns_if_noerrprint=  0x0002,/* never print to stderr (_debug overrides) */
+ adns_if_noserverwarn=0x0004,/* do not warn to stderr about duff servers etc */
+ adns_if_debug=       0x0008,/* enable all output to stderr plus debug msgs */
+ adns_if_logpid=      0x0080,/* include pid in diagnostic output */
+ adns_if_noautosys=   0x0010,/* do not make syscalls at every opportunity */
+ adns_if_eintr=       0x0020,/* allow _wait and _synchronous to return EINTR */
+ adns_if_nosigpipe=   0x0040,/* applic has SIGPIPE ignored, do not protect */
+ adns_if_checkc_entex=0x0100,/* consistency checks on entry/exit to adns fns */
+ adns_if_checkc_freq= 0x0300 /* consistency checks very frequently (slow!) */
 } adns_initflags;
 
 typedef enum {
-  adns_qf_search=          0x00000001, /* use the searchlist */
-  adns_qf_usevc=           0x00000002, /* use a virtual circuit (TCP connection) */
-  adns_qf_owner=           0x00000004, /* fill in the owner field in the answer */
-  adns_qf_quoteok_query=   0x00000010, /* allow special chars in query domain */
-  adns_qf_quoteok_cname=   0x00000000, /* allow ... in CNAME we go via - now default */
-  adns_qf_quoteok_anshost= 0x00000040, /* allow ... in things supposed to be hostnames */
-  adns_qf_quotefail_cname= 0x00000080, /* refuse if quote-req chars in CNAME we go via */
-  adns_qf_cname_loose=     0x00000100, /* allow refs to CNAMEs - without, get _s_cname */
-  adns_qf_cname_forbid=    0x00000200, /* don't follow CNAMEs, instead give _s_cname */
-  adns__qf_internalmask=   0x0ff00000
+ adns_qf_search=         0x00000001,/* use the searchlist */
+ adns_qf_usevc=          0x00000002,/* use a virtual circuit (TCP conn) */
+ adns_qf_owner=          0x00000004,/* fill in the owner field in the answer */
+ adns_qf_quoteok_query=  0x00000010,/* allow special chars in query domain */
+ adns_qf_quoteok_cname=  0x00000000,/*  ... in CNAME we go via (now default) */
+ adns_qf_quoteok_anshost=0x00000040,/*  ... in things supposedly hostnames */
+ adns_qf_quotefail_cname=0x00000080,/* refuse if quote-req chars in CNAME we go via */
+ adns_qf_cname_loose=    0x00000100,/* allow refs to CNAMEs - without, get _s_cname */
+ adns_qf_cname_forbid=   0x00000200,/* don't follow CNAMEs, instead give _s_cname */
+ adns__qf_internalmask=  0x0ff00000
 } adns_queryflags;
 
 typedef enum {
-  adns__rrt_typemask=  0x0ffff,
-  adns__qtf_deref=     0x10000, /* dereference domains and perhaps produce extra data */
-  adns__qtf_mail822=   0x20000, /* make mailboxes be in RFC822 rcpt field format */
-  
-  adns_r_none=               0,
-  
-  adns_r_a=                  1,
-  
-  adns_r_ns_raw=             2,
-  adns_r_ns=                    adns_r_ns_raw|adns__qtf_deref,
-  
-  adns_r_cname=              5,
-  
-  adns_r_soa_raw=            6,
-  adns_r_soa=                   adns_r_soa_raw|adns__qtf_mail822, 
-  
-  adns_r_ptr_raw=           12,
-  adns_r_ptr=                   adns_r_ptr_raw|adns__qtf_deref,
-  
-  adns_r_hinfo=             13,  
-  
-  adns_r_mx_raw=            15,
-  adns_r_mx=                    adns_r_mx_raw|adns__qtf_deref,
-  
-  adns_r_txt=               16,
-  
-  adns_r_rp_raw=            17,
-  adns_r_rp=                    adns_r_rp_raw|adns__qtf_mail822,
-
-  adns_r_addr=                  adns_r_a|adns__qtf_deref
-  
+ adns__rrt_typemask=0x0ffff,
+ adns__qtf_deref=   0x10000, /* dereference domains; perhaps get extra data */
+ adns__qtf_mail822= 0x20000, /* return mailboxes in RFC822 rcpt field fmt   */
+ 		     
+ adns_r_none=             0,
+ 		     
+ adns_r_a=                1,
+ 		     
+ adns_r_ns_raw=           2,
+ adns_r_ns=                  adns_r_ns_raw|adns__qtf_deref,
+ 		     
+ adns_r_cname=            5,
+ 		     
+ adns_r_soa_raw=          6,
+ adns_r_soa=                 adns_r_soa_raw|adns__qtf_mail822, 
+ 		     
+ adns_r_ptr_raw=         12,
+ adns_r_ptr=                 adns_r_ptr_raw|adns__qtf_deref,
+ 		     
+ adns_r_hinfo=           13,  
+ 		     
+ adns_r_mx_raw=          15,
+ adns_r_mx=                  adns_r_mx_raw|adns__qtf_deref,
+ 		     
+ adns_r_txt=             16,
+ 		     
+ adns_r_rp_raw=          17,
+ adns_r_rp=                  adns_r_rp_raw|adns__qtf_mail822,
+		     
+ adns_r_addr=                adns_r_a|adns__qtf_deref
+ 
 } adns_rrtype;
 
 /*
@@ -203,55 +203,55 @@
  */
 
 typedef enum {
-  adns_s_ok,
+ adns_s_ok,
 
-  /* locally induced errors */
-  adns_s_nomemory,
-  adns_s_unknownrrtype,
-  adns_s_systemfail,
-
-  adns_s_max_localfail= 29,
-  
-  /* remotely induced errors, detected locally */
-  adns_s_timeout,
-  adns_s_allservfail,
-  adns_s_norecurse,
-  adns_s_invalidresponse,
-  adns_s_unknownformat,
-
-  adns_s_max_remotefail= 59,
-  
-  /* remotely induced errors, reported by remote server to us */
-  adns_s_rcodeservfail,
-  adns_s_rcodeformaterror,
-  adns_s_rcodenotimplemented,
-  adns_s_rcoderefused,
-  adns_s_rcodeunknown,
-
-  adns_s_max_tempfail= 99,
-
-  /* remote configuration errors */
-  adns_s_inconsistent, /* PTR gives domain whose A does not exist and match */
-  adns_s_prohibitedcname, /* CNAME found where eg A expected (not if _qf_loosecname) */
-  adns_s_answerdomaininvalid,
-  adns_s_answerdomaintoolong,
-  adns_s_invaliddata,
-  
-  adns_s_max_misconfig= 199,
-
-  /* permanent problems with the query */
-  adns_s_querydomainwrong,
-  adns_s_querydomaininvalid,
-  adns_s_querydomaintoolong,
-  
-  adns_s_max_misquery= 299,
-
-  /* permanent errors */
-  adns_s_nxdomain,
-  adns_s_nodata,
+ /* locally induced errors */
+ adns_s_nomemory,
+ adns_s_unknownrrtype,
+ adns_s_systemfail,
+
+ adns_s_max_localfail= 29,
+ 
+ /* remotely induced errors, detected locally */
+ adns_s_timeout,
+ adns_s_allservfail,
+ adns_s_norecurse,
+ adns_s_invalidresponse,
+ adns_s_unknownformat,
+
+ adns_s_max_remotefail= 59,
+ 
+ /* remotely induced errors, reported by remote server to us */
+ adns_s_rcodeservfail,
+ adns_s_rcodeformaterror,
+ adns_s_rcodenotimplemented,
+ adns_s_rcoderefused,
+ adns_s_rcodeunknown,
+
+ adns_s_max_tempfail= 99,
+
+ /* remote configuration errors */
+ adns_s_inconsistent, /* PTR gives domain whose A does not exist and match */
+ adns_s_prohibitedcname, /* CNAME, but eg A expected (not if _qf_loosecname) */
+ adns_s_answerdomaininvalid,
+ adns_s_answerdomaintoolong,
+ adns_s_invaliddata,
+ 
+ adns_s_max_misconfig= 199,
+
+ /* permanent problems with the query */
+ adns_s_querydomainwrong,
+ adns_s_querydomaininvalid,
+ adns_s_querydomaintoolong,
+ 
+ adns_s_max_misquery= 299,
+
+ /* permanent errors */
+ adns_s_nxdomain,
+ adns_s_nodata,
 
-  adns_s_max_permfail= 499
-  
+ adns_s_max_permfail= 499
+ 
 } adns_status;
 
 typedef struct {
@@ -279,10 +279,11 @@
 } adns_rr_inthostaddr;
 
 typedef struct {
-  /* Used both for mx_raw, in which case i is the preference and str the domain,
-   * and for txt, in which case each entry has i for the `text' length,
-   * and str for the data (which will have had an extra nul appended
-   * so that if it was plain text it is now a null-terminated string).
+  /* Used both for mx_raw, in which case i is the preference and str
+   * the domain, and for txt, in which case each entry has i for the
+   * `text' length, and str for the data (which will have had an extra
+   * nul appended so that if it was plain text it is now a
+   * null-terminated string).
    */
   int i;
   char *str;
@@ -300,23 +301,23 @@
 typedef struct {
   adns_status status;
   char *cname; /* always NULL if query was for CNAME records */
-  char *owner; /* only set if requested in query flags, and may be 0 on error anyway */
+  char *owner; /* only set if req'd in query flags; maybe 0 on error anyway */
   adns_rrtype type; /* guaranteed to be same as in query */
-  time_t expires; /* expiry time, defined only if _s_ok, nxdomain or nodata. NOT TTL! */
+  time_t expires;/*abs time.  def only if _s_ok, nxdomain or nodata. NOT TTL!*/
   int nrrs, rrsz; /* nrrs is 0 if an error occurs */
   union {
     void *untyped;
     unsigned char *bytes;
-    char *(*str);                     /* ns_raw, cname, ptr, ptr_raw */
-    adns_rr_intstr *(*manyistr);      /* txt (list of strings ends with i=-1, str=0) */
-    adns_rr_addr *addr;               /* addr */
-    struct in_addr *inaddr;           /* a */
-    adns_rr_hostaddr *hostaddr;       /* ns */
-    adns_rr_intstrpair *intstrpair;   /* hinfo */
-    adns_rr_strpair *strpair;         /* rp, rp_raw */
-    adns_rr_inthostaddr *inthostaddr; /* mx */
-    adns_rr_intstr *intstr;           /* mx_raw */
-    adns_rr_soa *soa;                 /* soa, soa_raw */
+    char *(*str);                    /* ns_raw, cname, ptr, ptr_raw */
+    adns_rr_intstr *(*manyistr);     /* txt (list strs ends with i=-1, str=0)*/
+    adns_rr_addr *addr;              /* addr */
+    struct in_addr *inaddr;          /* a */
+    adns_rr_hostaddr *hostaddr;      /* ns */
+    adns_rr_intstrpair *intstrpair;  /* hinfo */
+    adns_rr_strpair *strpair;        /* rp, rp_raw */
+    adns_rr_inthostaddr *inthostaddr;/* mx */
+    adns_rr_intstr *intstr;          /* mx_raw */
+    adns_rr_soa *soa;                /* soa, soa_raw */
   } rrs;
 } adns_answer;
 
@@ -711,7 +712,8 @@
  * entrypoints will not be defined in libadns.  Sorry !
  */
 
-int adns_beforepoll(adns_state ads, struct pollfd *fds, int *nfds_io, int *timeout_io,
+int adns_beforepoll(adns_state ads, struct pollfd *fds,
+		    int *nfds_io, int *timeout_io,
 		    const struct timeval *now);
 /* Finds out which fd's adns is interested in, and when it would like
  * to be able to time things out.  This is in a form suitable for use
Index: adns/src/check.c
diff -u adns/src/check.c:1.8 adns/src/check.c:1.9
--- adns/src/check.c:1.8	Sun Sep 17 01:24:24 2000
+++ adns/src/check.c	Sun Jun 22 14:01:11 2003
@@ -31,24 +31,26 @@
   adns__consistency(ads,qu,cc_user);
 }
 
-#define DLIST_CHECK(list, nodevar, part, body)					\
-  if ((list).head) {								\
-    assert(! (list).head->part back);						\
-    for ((nodevar)= (list).head; (nodevar); (nodevar)= (nodevar)->part next) {	\
-      assert((nodevar)->part next						\
-	     ? (nodevar) == (nodevar)->part next->part back			\
-	     : (nodevar) == (list).tail);					\
-      body									\
-    }										\
+#define DLIST_CHECK(list, nodevar, part, body)			\
+  if ((list).head) {						\
+    assert(! (list).head->part back);				\
+    for ((nodevar)= (list).head;				\
+	 (nodevar);						\
+	 (nodevar)= (nodevar)->part next) {			\
+      assert((nodevar)->part next				\
+	     ? (nodevar) == (nodevar)->part next->part back	\
+	     : (nodevar) == (list).tail);			\
+      body							\
+    }								\
   }
 
-#define DLIST_ASSERTON(node, nodevar, list, part)				\
-  do {										\
-    for ((nodevar)= (list).head;						\
-	 (nodevar) != (node);							\
-	 (nodevar)= (nodevar)->part next) {					\
-      assert((nodevar));							\
-    }										\
+#define DLIST_ASSERTON(node, nodevar, list, part)	\
+  do {							\
+    for ((nodevar)= (list).head;			\
+	 (nodevar) != (node);				\
+	 (nodevar)= (nodevar)->part next) {		\
+      assert((nodevar));				\
+    }							\
   } while(0)
 
 static void checkc_query_alloc(adns_state ads, adns_query qu) {
Index: adns/src/config.h.in
diff -u adns/src/config.h.in:1.6 adns/src/config.h.in:1.7
--- adns/src/config.h.in:1.6	Thu Sep 14 02:23:39 2000
+++ adns/src/config.h.in	Tue Dec 18 00:03:20 2001
@@ -21,9 +21,6 @@
 /* Define if you have the poll function.  */
 #undef HAVE_POLL
 
-/* Define if you have the <sys/select.h> header file.  */
-#undef HAVE_SYS_SELECT_H
-
 /* Define if you have the nsl library (-lnsl).  */
 #undef HAVE_LIBNSL
 
@@ -98,8 +95,4 @@
 
 #ifdef HAVEUSE_RPCTYPES_H
 #include <rpc/types.h>
-#endif
-
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
 #endif
Index: adns/src/dlist.h
diff -u adns/src/dlist.h:1.2 adns/src/dlist.h:1.3
--- adns/src/dlist.h:1.2	Sun May  7 23:37:18 2000
+++ adns/src/dlist.h	Sun Jun 22 14:01:11 2003
@@ -31,20 +31,21 @@
 #define LIST_INIT(list) ((list).head= (list).tail= 0)
 #define LINK_INIT(link) ((link).next= (link).back= 0)
 
-#define LIST_UNLINK_PART(list,node,part) \
-  do { \
+#define LIST_UNLINK_PART(list,node,part)				    \
+  do {									    \
     if ((node)->part back) (node)->part back->part next= (node)->part next; \
       else                                  (list).head= (node)->part next; \
     if ((node)->part next) (node)->part next->part back= (node)->part back; \
       else                                  (list).tail= (node)->part back; \
   } while(0)
 
-#define LIST_LINK_TAIL_PART(list,node,part) \
-  do { \
-    (node)->part next= 0; \
-    (node)->part back= (list).tail; \
-    if ((list).tail) (list).tail->part next= (node); else (list).head= (node); \
-    (list).tail= (node); \
+#define LIST_LINK_TAIL_PART(list,node,part)		\
+  do {							\
+    (node)->part next= 0;				\
+    (node)->part back= (list).tail;			\
+    if ((list).tail) (list).tail->part next= (node);	\
+    else (list).head= (node);				\
+    (list).tail= (node);				\
   } while(0)
 
 #define LIST_UNLINK(list,node) LIST_UNLINK_PART(list,node,)
Index: adns/src/event.c
diff -u adns/src/event.c:1.56 adns/src/event.c:1.58
--- adns/src/event.c:1.56	Sun Sep 17 01:24:24 2000
+++ adns/src/event.c	Sun Jun 22 14:49:20 2003
@@ -83,6 +83,21 @@
   }
 }
 
+static void tcp_broken_events(adns_state ads) {
+  adns_query qu, nqu;
+  
+  assert(ads->tcpstate == server_broken);
+  for (qu= ads->tcpw.head; qu; qu= nqu) {
+    nqu= qu->next;
+    assert(qu->state == query_tcpw);
+    if (qu->retries > ads->nservers) {
+      LIST_UNLINK(ads->tcpw,qu);
+      adns__query_fail(qu,adns_s_allservfail);
+    }
+  }
+  ads->tcpstate= server_disconnected;
+}
+
 void adns__tcp_tryconnect(adns_state ads, struct timeval now) {
   int r, fd, tries;
   struct sockaddr_in addr;
@@ -105,7 +120,10 @@
     assert(!ads->tcprecv_skip);
 
     proto= getprotobyname("tcp");
-    if (!proto) { adns__diag(ads,-1,0,"unable to find protocol no. for TCP !"); return; }
+    if (!proto) {
+      adns__diag(ads,-1,0,"unable to find protocol no. for TCP !");
+      return;
+    }
     fd= socket(AF_INET,SOCK_STREAM,proto->p_proto);
     if (fd<0) {
       adns__diag(ads,-1,0,"cannot create TCP socket: %s",strerror(errno));
@@ -113,7 +131,8 @@
     }
     r= adns__setnonblock(ads,fd);
     if (r) {
-      adns__diag(ads,-1,0,"cannot make TCP socket nonblocking: %s",strerror(r));
+      adns__diag(ads,-1,0,"cannot make TCP socket nonblocking:"
+		 " %s",strerror(r));
       close(fd);
       return;
     }
@@ -131,7 +150,7 @@
       return;
     }
     adns__tcp_broken(ads,"connect",strerror(errno));
-    ads->tcpstate= server_disconnected;
+    tcp_broken_events(ads);
   }
 }
 
@@ -218,21 +237,11 @@
 static void tcp_events(adns_state ads, int act,
 		       struct timeval **tv_io, struct timeval *tvbuf,
 		       struct timeval now) {
-  adns_query qu, nqu;
-  
   for (;;) {
     switch (ads->tcpstate) {
     case server_broken:
       if (!act) { inter_immed(tv_io,tvbuf); return; }
-      for (qu= ads->tcpw.head; qu; qu= nqu) {
-	nqu= qu->next;
-	assert(qu->state == query_tcpw);
-	if (qu->retries > ads->nservers) {
-	  LIST_UNLINK(ads->tcpw,qu);
-	  adns__query_fail(qu,adns_s_allservfail);
-	}
-      }
-      ads->tcpstate= server_disconnected;
+      tcp_broken_events(ads);
     case server_disconnected: /* fall through */
       if (!ads->tcpw.head) return;
       if (!act) { inter_immed(tv_io,tvbuf); return; }
@@ -317,7 +326,8 @@
     pollfds_buf[1].events= POLLOUT;
     break;
   case server_ok:
-    pollfds_buf[1].events= ads->tcpsend.used ? POLLIN|POLLOUT|POLLPRI : POLLIN|POLLPRI;
+    pollfds_buf[1].events=
+      ads->tcpsend.used ? POLLIN|POLLOUT|POLLPRI : POLLIN|POLLPRI;
     break;
   default:
     abort();
@@ -358,7 +368,8 @@
 	want= 2;
       }
       ads->tcprecv.used -= ads->tcprecv_skip;
-      memmove(ads->tcprecv.buf,ads->tcprecv.buf+ads->tcprecv_skip,ads->tcprecv.used);
+      memmove(ads->tcprecv.buf, ads->tcprecv.buf+ads->tcprecv_skip,
+	      ads->tcprecv.used);
       ads->tcprecv_skip= 0;
       if (!adns__vbuf_ensure(&ads->tcprecv,want)) { r= ENOMEM; goto xit; }
       assert(ads->tcprecv.used <= ads->tcprecv.avail);
@@ -405,8 +416,8 @@
 	continue;
       }
       if (ntohs(udpaddr.sin_port) != DNS_PORT) {
-	adns__diag(ads,-1,0,"datagram received from wrong port %u (expected %u)",
-		   ntohs(udpaddr.sin_port),DNS_PORT);
+	adns__diag(ads,-1,0,"datagram received from wrong port"
+		   " %u (expected %u)", ntohs(udpaddr.sin_port),DNS_PORT);
 	continue;
       }
       for (serv= 0;
@@ -484,7 +495,8 @@
   return r;
 }
   
-int adns_processexceptional(adns_state ads, int fd, const struct timeval *now) {
+int adns_processexceptional(adns_state ads, int fd,
+			    const struct timeval *now) {
   adns__consistency(ads,0,cc_entex);
   switch (ads->tcpstate) {
   case server_disconnected:
@@ -505,7 +517,8 @@
 static void fd_event(adns_state ads, int fd,
 		     int revent, int pollflag,
 		     int maxfd, const fd_set *fds,
-		     int (*func)(adns_state, int fd, const struct timeval *now),
+		     int (*func)(adns_state, int fd,
+				 const struct timeval *now),
 		     struct timeval now, int *r_r) {
   int r;
   
@@ -516,7 +529,8 @@
     if (r_r) {
       *r_r= r;
     } else {
-      adns__diag(ads,-1,0,"process fd failed after select: %s",strerror(errno));
+      adns__diag(ads,-1,0,"process fd failed after select:"
+		 " %s",strerror(errno));
       adns_globalsystemfailure(ads);
     }
   }
@@ -533,9 +547,12 @@
     fd= pollfds[i].fd;
     if (fd >= maxfd) maxfd= fd+1;
     revents= pollfds[i].revents;
-    fd_event(ads,fd, revents,POLLIN, maxfd,readfds, adns_processreadable,now,r_r);
-    fd_event(ads,fd, revents,POLLOUT, maxfd,writefds, adns_processwriteable,now,r_r);
-    fd_event(ads,fd, revents,POLLPRI, maxfd,exceptfds, adns_processexceptional,now,r_r);
+#define EV(pollfl,fds,how)  \
+    fd_event(ads,fd, revents,pollfl, maxfd,fds, adns_process##how,now,r_r)
+    EV( POLLIN,  readfds,   readable    );
+    EV( POLLOUT, writefds,  writeable   );
+    EV( POLLPRI, exceptfds, exceptional );
+#undef EV
   }
 }
 
Index: adns/src/general.c
diff -u adns/src/general.c:1.28 adns/src/general.c:1.29
--- adns/src/general.c:1.28	Sun Sep 17 01:24:24 2000
+++ adns/src/general.c	Sun Jun 22 14:01:11 2003
@@ -44,7 +44,8 @@
   vbuf vb;
   
   if (!ads->diagfile ||
-      (!(ads->iflags & adns_if_debug) && (!prevent || (ads->iflags & prevent))))
+      (!(ads->iflags & adns_if_debug)
+       && (!prevent || (ads->iflags & prevent))))
     return;
 
   if (ads->iflags & adns_if_logpid) {
@@ -79,7 +80,8 @@
   fputs(aft,ads->diagfile);
 }
 
-void adns__debug(adns_state ads, int serv, adns_query qu, const char *fmt, ...) {
+void adns__debug(adns_state ads, int serv, adns_query qu,
+		 const char *fmt, ...) {
   va_list al;
 
   va_start(al,fmt);
@@ -87,15 +89,18 @@
   va_end(al);
 }
 
-void adns__warn(adns_state ads, int serv, adns_query qu, const char *fmt, ...) {
+void adns__warn(adns_state ads, int serv, adns_query qu,
+		const char *fmt, ...) {
   va_list al;
 
   va_start(al,fmt);
-  adns__vdiag(ads," warning",adns_if_noerrprint|adns_if_noserverwarn,serv,qu,fmt,al);
+  adns__vdiag(ads," warning",
+	      adns_if_noerrprint|adns_if_noserverwarn, serv,qu,fmt,al);
   va_end(al);
 }
 
-void adns__diag(adns_state ads, int serv, adns_query qu, const char *fmt, ...) {
+void adns__diag(adns_state ads, int serv, adns_query qu,
+		const char *fmt, ...) {
   va_list al;
 
   va_start(al,fmt);
@@ -156,10 +161,12 @@
 /* Additional diagnostic functions */
 
 const char *adns__diag_domain(adns_state ads, int serv, adns_query qu,
-			      vbuf *vb, const byte *dgram, int dglen, int cbyte) {
+			      vbuf *vb, const byte *dgram,
+			      int dglen, int cbyte) {
   adns_status st;
 
-  st= adns__parse_domain(ads,serv,qu,vb, pdf_quoteok, dgram,dglen,&cbyte,dglen);
+  st= adns__parse_domain(ads,serv,qu,vb, pdf_quoteok,
+			 dgram,dglen,&cbyte,dglen);
   if (st == adns_s_nomemory) {
     return "<cannot report domain... out of memory>";
   }
@@ -218,36 +225,36 @@
   const char *abbrev;
   const char *string;
 } sinfos[]= {
-  SINFO(  ok,                  "OK"                                            ),
-
-  SINFO(  nomemory,            "Out of memory"                                 ),
-  SINFO(  unknownrrtype,       "Query not implemented in DNS library"          ),
-  SINFO(  systemfail,          "General resolver or system failure"            ),
-
-  SINFO(  timeout,             "DNS query timed out"                           ),
-  SINFO(  allservfail,         "All nameservers failed"                        ),
-  SINFO(  norecurse,           "Recursion denied by nameserver"                ),
-  SINFO(  invalidresponse,     "Nameserver sent bad response"                  ),
-  SINFO(  unknownformat,       "Nameserver used unknown format"                ),
-
-  SINFO(  rcodeservfail,       "Nameserver reports failure"                    ),
-  SINFO(  rcodeformaterror,    "Query not understood by nameserver"            ),
-  SINFO(  rcodenotimplemented, "Query not implemented by nameserver"           ),
-  SINFO(  rcoderefused,        "Query refused by nameserver"                   ),
-  SINFO(  rcodeunknown,        "Nameserver sent unknown response code"         ),
-  
-  SINFO(  inconsistent,        "Inconsistent resource records in DNS"          ),
-  SINFO(  prohibitedcname,     "DNS alias found where canonical name wanted"   ),
-  SINFO(  answerdomaininvalid, "Found syntactically invalid domain name"       ),
-  SINFO(  answerdomaintoolong, "Found overly-long domain name"                 ),
-  SINFO(  invaliddata,         "Found invalid DNS data"                        ),
-
-  SINFO(  querydomainwrong,    "Domain invalid for particular DNS query type"  ),
-  SINFO(  querydomaininvalid,  "Domain name is syntactically invalid"          ),
-  SINFO(  querydomaintoolong,  "Domain name or component is too long"          ),
-
-  SINFO(  nxdomain,            "No such domain"                                ),
-  SINFO(  nodata,              "No such data"                                  )
+  SINFO( ok,                  "OK"                                           ),
+									      
+  SINFO( nomemory,            "Out of memory"                                ),
+  SINFO( unknownrrtype,       "Query not implemented in DNS library"         ),
+  SINFO( systemfail,          "General resolver or system failure"           ),
+									      
+  SINFO( timeout,             "DNS query timed out"                          ),
+  SINFO( allservfail,         "All nameservers failed"                       ),
+  SINFO( norecurse,           "Recursion denied by nameserver"               ),
+  SINFO( invalidresponse,     "Nameserver sent bad response"                 ),
+  SINFO( unknownformat,       "Nameserver used unknown format"               ),
+									      
+  SINFO( rcodeservfail,       "Nameserver reports failure"                   ),
+  SINFO( rcodeformaterror,    "Query not understood by nameserver"           ),
+  SINFO( rcodenotimplemented, "Query not implemented by nameserver"          ),
+  SINFO( rcoderefused,        "Query refused by nameserver"                  ),
+  SINFO( rcodeunknown,        "Nameserver sent unknown response code"        ),
+  									      
+  SINFO( inconsistent,        "Inconsistent resource records in DNS"         ),
+  SINFO( prohibitedcname,     "DNS alias found where canonical name wanted"  ),
+  SINFO( answerdomaininvalid, "Found syntactically invalid domain name"      ),
+  SINFO( answerdomaintoolong, "Found overly-long domain name"                ),
+  SINFO( invaliddata,         "Found invalid DNS data"                       ),
+									      
+  SINFO( querydomainwrong,    "Domain invalid for particular DNS query type" ),
+  SINFO( querydomaininvalid,  "Domain name is syntactically invalid"         ),
+  SINFO( querydomaintoolong,  "Domain name or component is too long"         ),
+									      
+  SINFO( nxdomain,            "No such domain"                               ),
+  SINFO( nodata,              "No such data"                                 )
 };
 
 static int si_compar(const void *key, const void *elem) {
@@ -258,7 +265,8 @@
 }
 
 static const struct sinfo *findsinfo(adns_status st) {
-  return bsearch(&st,sinfos,sizeof(sinfos)/sizeof(*sinfos),sizeof(*sinfos),si_compar);
+  return bsearch(&st,sinfos, sizeof(sinfos)/sizeof(*sinfos),
+		 sizeof(*sinfos), si_compar);
 }
 
 const char *adns_strerror(adns_status st) {
@@ -307,7 +315,8 @@
 const char *adns_errtypeabbrev(adns_status st) {
   const struct stinfo *sti;
 
-  sti= bsearch(&st,stinfos,sizeof(stinfos)/sizeof(*stinfos),sizeof(*stinfos),sti_compar);
+  sti= bsearch(&st,stinfos, sizeof(stinfos)/sizeof(*stinfos),
+	       sizeof(*stinfos), sti_compar);
   return sti->abbrev;
 }
 
Index: adns/src/internal.h
diff -u adns/src/internal.h:1.62 adns/src/internal.h:1.64
--- adns/src/internal.h:1.62	Sun Sep 17 01:24:24 2000
+++ adns/src/internal.h	Sun Jun 22 14:58:15 2003
@@ -39,6 +39,7 @@
 #include <signal.h>
 #include <errno.h>
 #include <string.h>
+#include <stdlib.h>
 
 #include <sys/time.h>
 
@@ -129,7 +130,8 @@
    * and will not be null-terminated by convstring.
    */
 
-  adns_status (*parse)(const parseinfo *pai, int cbyte, int max, void *store_r);
+  adns_status (*parse)(const parseinfo *pai, int cbyte,
+		       int max, void *store_r);
   /* Parse one RR, in dgram of length dglen, starting at cbyte and
    * extending until at most max.
    *
@@ -141,7 +143,7 @@
    * nsstart is the offset of the authority section.
    */
 
-  int (*diff_needswap)(adns_state ads, const void *datap_a, const void *datap_b);
+  int (*diff_needswap)(adns_state ads,const void *datap_a,const void *datap_b);
   /* Returns !0 if RR a should be strictly after RR b in the sort order,
    * 0 otherwise.  Must not fail.
    */
@@ -327,7 +329,7 @@
 		const char *fmt, ...) PRINTFFORMAT(4,5);
 
 int adns__vbuf_ensure(vbuf *vb, int want);
-int adns__vbuf_appendstr(vbuf *vb, const char *data); /* does not include nul */
+int adns__vbuf_appendstr(vbuf *vb, const char *data); /* doesn't include nul */
 int adns__vbuf_append(vbuf *vb, const byte *data, int len);
 /* 1=>success, 0=>realloc failed */
 void adns__vbuf_appendq(vbuf *vb, const byte *data, int len);
@@ -335,7 +337,8 @@
 void adns__vbuf_free(vbuf *vb);
 
 const char *adns__diag_domain(adns_state ads, int serv, adns_query qu,
-			      vbuf *vb, const byte *dgram, int dglen, int cbyte);
+			      vbuf *vb,
+			      const byte *dgram, int dglen, int cbyte);
 /* Unpicks a domain in a datagram and returns a string suitable for
  * printing it as.  Never fails - if an error occurs, it will
  * return some kind of string describing the error.
@@ -374,7 +377,8 @@
  */
 
 adns_status adns__mkquery_frdgram(adns_state ads, vbuf *vb, int *id_r,
-				  const byte *qd_dgram, int qd_dglen, int qd_begin,
+				  const byte *qd_dgram, int qd_dglen,
+				  int qd_begin,
 				  adns_rrtype type, adns_queryflags flags);
 /* Same as adns__mkquery, but takes the owner domain from an existing datagram.
  * That domain must be correct and untruncated.
@@ -389,8 +393,8 @@
 void adns__query_send(adns_query qu, struct timeval now);
 /* Query must be in state tosend/NONE; it will be moved to a new state,
  * and no further processing can be done on it for now.
- * (Resulting state is one of udp/timew, tcpwait/timew (if server not connected),
- *  tcpsent/timew, child/childw or done/output.)
+ * (Resulting state is one of udp/timew, tcpwait/timew (if server not
+ * connected), tcpsent/timew, child/childw or done/output.)
  * __query_send may decide to use either UDP or TCP depending whether
  * _qf_usevc is set (or has become set) and whether the query is too
  * large.
@@ -399,7 +403,8 @@
 /* From query.c: */
 
 adns_status adns__internal_submit(adns_state ads, adns_query *query_r,
-				  const typeinfo *typei, vbuf *qumsg_vb, int id,
+				  const typeinfo *typei, vbuf *qumsg_vb,
+				  int id,
 				  adns_queryflags flags, struct timeval now,
 				  const qcontext *ctx);
 /* Submits a query (for internal use, called during external submits).
@@ -460,7 +465,8 @@
  *  answer->cname and answer->owner are _preserved.
  */
 
-void adns__transfer_interim(adns_query from, adns_query to, void *block, size_t sz);
+void adns__transfer_interim(adns_query from, adns_query to,
+			    void *block, size_t sz);
 /* Transfers an interim allocation from one query to another, so that
  * the `to' query will have room for the data when we get to makefinal
  * and so that the free will happen when the `to' query is freed
@@ -537,7 +543,8 @@
  * serv may be -1, qu may be null - they are for error reporting.
  */
 
-adns_status adns__findlabel_next(findlabel_state *fls, int *lablen_r, int *labstart_r);
+adns_status adns__findlabel_next(findlabel_state *fls,
+				 int *lablen_r, int *labstart_r);
 /* Then, call this one repeatedly.
  *
  * It will return adns_s_ok if all is well, and tell you the length
@@ -568,7 +575,8 @@
 
 adns_status adns__parse_domain(adns_state ads, int serv, adns_query qu,
 			       vbuf *vb, parsedomain_flags flags,
-			       const byte *dgram, int dglen, int *cbyte_io, int max);
+			       const byte *dgram, int dglen, int *cbyte_io,
+			       int max);
 /* vb must already have been initialised; it will be reset if necessary.
  * If there is truncation, vb->used will be set to 0; otherwise
  * (if there is no error) vb will be null-terminated.
@@ -578,7 +586,8 @@
  */
 
 adns_status adns__parse_domain_more(findlabel_state *fls, adns_state ads,
-				    adns_query qu, vbuf *vb, parsedomain_flags flags,
+				    adns_query qu, vbuf *vb,
+				    parsedomain_flags flags,
 				    const byte *dgram);
 /* Like adns__parse_domain, but you pass it a pre-initialised findlabel_state,
  * for continuing an existing domain or some such of some kind.  Also, unlike
@@ -617,10 +626,11 @@
 
 adns_status adns__findrr_anychk(adns_query qu, int serv,
 				const byte *dgram, int dglen, int *cbyte_io,
-				int *type_r, int *class_r, unsigned long *ttl_r,
+				int *type_r, int *class_r,
+				unsigned long *ttl_r,
 				int *rdlen_r, int *rdstart_r,
-				const byte *eo_dgram, int eo_dglen, int eo_cbyte,
-				int *eo_matched_r);
+				const byte *eo_dgram, int eo_dglen,
+				int eo_cbyte, int *eo_matched_r);
 /* Like adns__findrr_checked, except that the datagram and
  * owner to compare with can be specified explicitly.
  *
@@ -635,7 +645,8 @@
  * untruncated.
  */
 
-void adns__update_expires(adns_query qu, unsigned long ttl, struct timeval now);
+void adns__update_expires(adns_query qu, unsigned long ttl,
+			  struct timeval now);
 /* Updates the `expires' field in the query, so that it doesn't exceed
  * now + ttl.
  */
@@ -682,12 +693,16 @@
 
 /* Useful static inline functions: */
 
-static inline int ctype_whitespace(int c) { return c==' ' || c=='\n' || c=='\t'; }
+static inline int ctype_whitespace(int c) {
+  return c==' ' || c=='\n' || c=='\t';
+}
 static inline int ctype_digit(int c) { return c>='0' && c<='9'; }
 static inline int ctype_alpha(int c) {
   return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
 }
-static inline int ctype_822special(int c) { return strchr("()<>@,;:\\\".[]",c) != 0; }
+static inline int ctype_822special(int c) {
+  return strchr("()<>@,;:\\\".[]",c) != 0;
+}
 static inline int ctype_domainunquoted(int c) {
   return ctype_alpha(c) || ctype_digit(c) || (strchr("-_/+",c) != 0);
 }
@@ -696,18 +711,18 @@
 
 /* Useful macros */
 
-#define MEM_ROUND(sz) \
-  (( ((sz)+sizeof(union maxalign)-1) / sizeof(union maxalign) ) \
+#define MEM_ROUND(sz)						\
+  (( ((sz)+sizeof(union maxalign)-1) / sizeof(union maxalign) )	\
    * sizeof(union maxalign) )
 
 #define GETIL_B(cb) (((dgram)[(cb)++]) & 0x0ff)
 #define GET_B(cb,tv) ((tv)= GETIL_B((cb)))
-#define GET_W(cb,tv) ((tv)=0, (tv)|=(GETIL_B((cb))<<8), (tv)|=GETIL_B(cb), (tv))
-#define GET_L(cb,tv) ( (tv)=0, \
-		       (tv)|=(GETIL_B((cb))<<24), \
-		       (tv)|=(GETIL_B((cb))<<16), \
-		       (tv)|=(GETIL_B((cb))<<8), \
-		       (tv)|=GETIL_B(cb), \
+#define GET_W(cb,tv) ((tv)=0,(tv)|=(GETIL_B((cb))<<8), (tv)|=GETIL_B(cb), (tv))
+#define GET_L(cb,tv) ( (tv)=0,				\
+		       (tv)|=(GETIL_B((cb))<<24),	\
+		       (tv)|=(GETIL_B((cb))<<16),	\
+		       (tv)|=(GETIL_B((cb))<<8),	\
+		       (tv)|=GETIL_B(cb),		\
 		       (tv) )
 
 #endif
Index: adns/src/parse.c
diff -u adns/src/parse.c:1.21 adns/src/parse.c:1.22
--- adns/src/parse.c:1.21	Sun Sep 17 01:24:24 2000
+++ adns/src/parse.c	Sun Jun 22 14:01:11 2003
@@ -43,7 +43,8 @@
 	break;
       }
     }
-    if (!adns__vbuf_append(vb,buf,i) || !adns__vbuf_append(vb,qbuf,strlen(qbuf)))
+    if (!adns__vbuf_append(vb,buf,i) ||
+	!adns__vbuf_append(vb,qbuf,strlen(qbuf)))
       return 0;
     if (i<len) i++;
     buf+= i;
@@ -106,22 +107,26 @@
   return adns_s_ok;
 
  x_badresponse: 
-  adns__diag(fls->ads,fls->serv,fls->qu,"label in domain runs beyond end of domain");
+  adns__diag(fls->ads,fls->serv,fls->qu,
+	     "label in domain runs beyond end of domain");
   return adns_s_invalidresponse;
 }
 
 adns_status adns__parse_domain(adns_state ads, int serv, adns_query qu,
 			       vbuf *vb, adns_queryflags flags,
-			       const byte *dgram, int dglen, int *cbyte_io, int max) {
+			       const byte *dgram, int dglen, int *cbyte_io,
+			       int max) {
   findlabel_state fls;
   
-  adns__findlabel_start(&fls,ads, serv,qu, dgram,dglen,max, *cbyte_io,cbyte_io);
+  adns__findlabel_start(&fls,ads, serv,qu, dgram,dglen,max,
+			*cbyte_io,cbyte_io);
   vb->used= 0;
   return adns__parse_domain_more(&fls,ads,qu, vb,flags,dgram);
 }
 
 adns_status adns__parse_domain_more(findlabel_state *fls, adns_state ads,
-				    adns_query qu, vbuf *vb, parsedomain_flags flags,
+				    adns_query qu, vbuf *vb,
+				    parsedomain_flags flags,
 				    const byte *dgram) {
   int lablen, labstart, i, ch, first;
   adns_status st;
@@ -142,7 +147,8 @@
 	return adns_s_nomemory;
     } else {
       ch= dgram[labstart];
-      if (!ctype_alpha(ch) && !ctype_digit(ch)) return adns_s_answerdomaininvalid;
+      if (!ctype_alpha(ch) && !ctype_digit(ch))
+	return adns_s_answerdomaininvalid;
       for (i= labstart+1; i<labstart+lablen; i++) {
 	ch= dgram[i];
 	if (ch != '-' && !ctype_alpha(ch) && !ctype_digit(ch))
@@ -158,10 +164,11 @@
 	
 adns_status adns__findrr_anychk(adns_query qu, int serv,
 				const byte *dgram, int dglen, int *cbyte_io,
-				int *type_r, int *class_r, unsigned long *ttl_r,
+				int *type_r, int *class_r,
+				unsigned long *ttl_r,
 				int *rdlen_r, int *rdstart_r,
-				const byte *eo_dgram, int eo_dglen, int eo_cbyte,
-				int *eo_matched_r) {
+				const byte *eo_dgram, int eo_dglen,
+				int eo_cbyte, int *eo_matched_r) {
   findlabel_state fls, eo_fls;
   int cbyte;
   
@@ -175,7 +182,8 @@
 
   adns__findlabel_start(&fls,qu->ads, serv,qu, dgram,dglen,dglen,cbyte,&cbyte);
   if (eo_dgram) {
-    adns__findlabel_start(&eo_fls,qu->ads, -1,0, eo_dgram,eo_dglen,eo_dglen,eo_cbyte,0);
+    adns__findlabel_start(&eo_fls,qu->ads, -1,0,
+			  eo_dgram,eo_dglen,eo_dglen,eo_cbyte,0);
     mismatch= 0;
   } else {
     mismatch= 1;
Index: adns/src/poll.c
diff -u adns/src/poll.c:1.9 adns/src/poll.c:1.10
--- adns/src/poll.c:1.9	Sun Sep 17 01:24:24 2000
+++ adns/src/poll.c	Sun Jun 22 14:01:11 2003
@@ -32,8 +32,8 @@
 
 #ifdef HAVE_POLL
 
-int adns_beforepoll(adns_state ads, struct pollfd *fds, int *nfds_io, int *timeout_io,
-		    const struct timeval *now) {
+int adns_beforepoll(adns_state ads, struct pollfd *fds, int *nfds_io,
+		    int *timeout_io, const struct timeval *now) {
   struct timeval tv_nowbuf, tv_tobuf, *tv_to;
   int space, found, timeout_ms, r;
   struct pollfd fds_tmp[MAX_POLLFDS];
Index: adns/src/query.c
diff -u adns/src/query.c:1.62 adns/src/query.c:1.64
--- adns/src/query.c:1.62	Sun Sep 17 01:24:24 2000
+++ adns/src/query.c	Sun Jun 22 14:01:11 2003
@@ -43,7 +43,8 @@
   adns_query qu;
   
   qu= malloc(sizeof(*qu));  if (!qu) return 0;
-  qu->answer= malloc(sizeof(*qu->answer));  if (!qu->answer) { free(qu); return 0; }
+  qu->answer= malloc(sizeof(*qu->answer));
+  if (!qu->answer) { free(qu); return 0; }
   
   qu->ads= ads;
   qu->state= query_tosend;
@@ -108,7 +109,8 @@
 }
 
 adns_status adns__internal_submit(adns_state ads, adns_query *query_r,
-				  const typeinfo *typei, vbuf *qumsg_vb, int id,
+				  const typeinfo *typei, vbuf *qumsg_vb,
+				  int id,
 				  adns_queryflags flags, struct timeval now,
 				  const qcontext *ctx) {
   adns_query qu;
@@ -157,8 +159,8 @@
   } else {
     if (qu->search_pos >= ads->nsearchlist) {
       if (qu->search_doneabs) {
+	qu->search_vb.used= qu->search_origlen;
 	stat= adns_s_nxdomain; goto x_fail;
-	return;
       } else {
 	nextentry= 0;
 	qu->search_doneabs= 1;
@@ -171,17 +173,19 @@
   qu->search_vb.used= qu->search_origlen;
   if (nextentry) {
     if (!adns__vbuf_append(&qu->search_vb,".",1) ||
-	!adns__vbuf_appendstr(&qu->search_vb,nextentry)) {
-      stat= adns_s_nomemory; goto x_fail;
-    }
+	!adns__vbuf_appendstr(&qu->search_vb,nextentry))
+      goto x_nomemory;
   }
 
   free(qu->query_dgram);
   qu->query_dgram= 0; qu->query_dglen= 0;
 
-  query_simple(ads,qu, qu->search_vb.buf, qu->search_vb.used, qu->typei, qu->flags, now);
+  query_simple(ads,qu, qu->search_vb.buf, qu->search_vb.used,
+	       qu->typei, qu->flags, now);
   return;
-  
+
+x_nomemory:
+  stat= adns_s_nomemory;
 x_fail:
   adns__query_fail(qu,stat);
 }
@@ -190,6 +194,8 @@
   /* Returns 1 if OK, otherwise there was no memory. */
   adns_answer *ans;
 
+  if (!(qu->flags & adns_qf_owner)) return 1;
+
   ans= qu->answer;
   assert(!ans->owner);
 
@@ -282,7 +288,8 @@
   flags &= ~adns_qf_search;
 
   if (addr->sa_family != AF_INET) return ENOSYS;
-  iaddr= (const unsigned char*) &(((const struct sockaddr_in*)addr) -> sin_addr);
+  iaddr= (const unsigned char*)
+    &(((const struct sockaddr_in*)addr) -> sin_addr);
 
   lreq= strlen(zone) + 4*4 + 1;
   if (lreq > sizeof(shortbuf)) {
@@ -307,7 +314,8 @@
 			void *context,
 			adns_query *query_r) {
   if (type != adns_r_ptr && type != adns_r_ptr_raw) return EINVAL;
-  return adns_submit_reverse_any(ads,addr,"in-addr.arpa",type,flags,context,query_r);
+  return adns_submit_reverse_any(ads,addr,"in-addr.arpa",
+				 type,flags,context,query_r);
 }
 
 int adns_synchronous(adns_state ads,
@@ -362,7 +370,8 @@
   return alloc_common(qu,MEM_ROUND(sz));
 }
 
-void adns__transfer_interim(adns_query from, adns_query to, void *block, size_t sz) {
+void adns__transfer_interim(adns_query from, adns_query to,
+			    void *block, size_t sz) {
   allocnode *an;
 
   if (!block) return;
@@ -454,7 +463,8 @@
   adns__consistency(ads,0,cc_entex);
 }
 
-void adns__update_expires(adns_query qu, unsigned long ttl, struct timeval now) {
+void adns__update_expires(adns_query qu, unsigned long ttl,
+			  struct timeval now) {
   time_t max;
 
   assert(ttl <= MAXTTLBELIEVE);
@@ -470,7 +480,8 @@
   ans= qu->answer;
 
   if (qu->interim_allocd) {
-    ans= realloc(qu->answer, MEM_ROUND(MEM_ROUND(sizeof(*ans)) + qu->interim_allocd));
+    ans= realloc(qu->answer,
+		 MEM_ROUND(MEM_ROUND(sizeof(*ans)) + qu->interim_allocd));
     if (!ans) goto x_nomem;
     qu->answer= ans;
   }
@@ -508,8 +519,7 @@
   qu->id= -1;
   ans= qu->answer;
 
-  if (qu->flags & adns_qf_owner && qu->flags & adns_qf_search &&
-      ans->status != adns_s_nomemory) {
+  if (qu->flags & adns_qf_search && ans->status != adns_s_nomemory) {
     if (!save_owner(qu, qu->search_vb.buf, qu->search_vb.used)) {
       adns__query_fail(qu,adns_s_nomemory);
       return;
@@ -523,7 +533,8 @@
     }
     adns__isort(ans->rrs.bytes, ans->nrrs, ans->rrsz,
 		qu->vb.buf,
-		(int(*)(void*, const void*, const void*))qu->typei->diff_needswap,
+		(int(*)(void*, const void*, const void*))
+		  qu->typei->diff_needswap,
 		qu->ads);
   }
 
Index: adns/src/reply.c
diff -u adns/src/reply.c:1.41 adns/src/reply.c:1.43
--- adns/src/reply.c:1.41	Sun Sep 17 01:24:24 2000
+++ adns/src/reply.c	Sun Jun 22 14:01:11 2003
@@ -47,7 +47,8 @@
   parseinfo pai;
   
   if (dglen<DNS_HDRSIZE) {
-    adns__diag(ads,serv,0,"received datagram too short for message header (%d)",dglen);
+    adns__diag(ads,serv,0,"received datagram"
+	       " too short for message header (%d)",dglen);
     return;
   }
   cbyte= 0;
@@ -74,7 +75,8 @@
     return;
   }
   if (opcode) {
-    adns__diag(ads,serv,0,"server sent us unknown opcode %d (wanted 0=QUERY)",opcode);
+    adns__diag(ads,serv,0,"server sent us unknown opcode"
+	       " %d (wanted 0=QUERY)",opcode);
     return;
   }
 
@@ -114,7 +116,8 @@
   case rcode_nxdomain:
     break;
   case rcode_formaterror:
-    adns__warn(ads,serv,qu,"server cannot understand our query (Format Error)");
+    adns__warn(ads,serv,qu,"server cannot understand our query"
+	       " (Format Error)");
     if (qu) adns__query_fail(qu,adns_s_rcodeformaterror);
     return;
   case rcode_servfail:
@@ -139,18 +142,20 @@
     if (!qdcount) {
       adns__diag(ads,serv,0,"server sent reply without quoting our question");
     } else if (qdcount>1) {
-      adns__diag(ads,serv,0,"server claimed to answer %d questions with one message",
-		 qdcount);
+      adns__diag(ads,serv,0,"server claimed to answer %d"
+		 " questions with one message", qdcount);
     } else if (ads->iflags & adns_if_debug) {
       adns__vbuf_init(&tempvb);
       adns__debug(ads,serv,0,"reply not found, id %02x, query owner %s",
-		  id, adns__diag_domain(ads,serv,0,&tempvb,dgram,dglen,DNS_HDRSIZE));
+		  id, adns__diag_domain(ads,serv,0,&tempvb,
+					dgram,dglen,DNS_HDRSIZE));
       adns__vbuf_free(&tempvb);
     }
     return;
   }
 
-  /* We're definitely going to do something with this packet and this query now. */
+  /* We're definitely going to do something with this packet and this
+   * query now. */
   
   anstart= qu->query_dglen;
   arstart= -1;
@@ -169,14 +174,15 @@
     if (rrtype == -1) goto x_truncated;
 
     if (rrclass != DNS_CLASS_IN) {
-      adns__diag(ads,serv,qu,"ignoring answer RR with wrong class %d (expected IN=%d)",
-		 rrclass,DNS_CLASS_IN);
+      adns__diag(ads,serv,qu,"ignoring answer RR with wrong class %d"
+		 " (expected IN=%d)", rrclass,DNS_CLASS_IN);
       continue;
     }
     if (!ownermatched) {
       if (ads->iflags & adns_if_debug) {
 	adns__debug(ads,serv,qu,"ignoring RR with an unexpected owner %s",
-		    adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rrstart));
+		    adns__diag_domain(ads,serv,qu, &qu->vb,
+				      dgram,dglen,rrstart));
       }
       continue;
     }
@@ -186,25 +192,31 @@
 	adns__query_fail(qu,adns_s_prohibitedcname);
 	return;
       } else if (qu->cname_dgram) { /* Ignore second and subsequent CNAME(s) */
-	adns__debug(ads,serv,qu,"allegedly canonical name %s is actually alias for %s",
-		    qu->answer->cname,
-		    adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rdstart));
+	adns__debug(ads,serv,qu,"allegedly canonical name %s"
+		    " is actually alias for %s", qu->answer->cname,
+		    adns__diag_domain(ads,serv,qu, &qu->vb,
+				      dgram,dglen,rdstart));
 	adns__query_fail(qu,adns_s_prohibitedcname);
 	return;
       } else if (wantedrrs) { /* Ignore CNAME(s) after RR(s). */
 	adns__debug(ads,serv,qu,"ignoring CNAME (to %s) coexisting with RR",
-		    adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rdstart));
+		    adns__diag_domain(ads,serv,qu, &qu->vb,
+				      dgram,dglen,rdstart));
       } else {
 	qu->cname_begin= rdstart;
 	qu->cname_dglen= dglen;
 	st= adns__parse_domain(ads,serv,qu, &qu->vb,
-			       qu->flags & adns_qf_quotefail_cname ? 0 : pdf_quoteok,
+			       qu->flags & adns_qf_quotefail_cname
+			       ? 0 : pdf_quoteok,
 			       dgram,dglen, &rdstart,rdstart+rdlength);
 	if (!qu->vb.used) goto x_truncated;
 	if (st) { adns__query_fail(qu,st); return; }
 	l= strlen(qu->vb.buf)+1;
 	qu->answer->cname= adns__alloc_preserved(qu,l);
-	if (!qu->answer->cname) { adns__query_fail(qu,adns_s_nomemory); return; }
+	if (!qu->answer->cname) {
+	  adns__query_fail(qu,adns_s_nomemory);
+	  return;
+	}
 
 	qu->cname_dgram= adns__alloc_mine(qu,dglen);
 	memcpy(qu->cname_dgram,dgram,dglen);
@@ -221,7 +233,8 @@
     } else if (rrtype == (qu->typei->type & adns__rrt_typemask)) {
       wantedrrs++;
     } else {
-      adns__debug(ads,serv,qu,"ignoring answer RR with irrelevant type %d",rrtype);
+      adns__debug(ads,serv,qu,"ignoring answer RR"
+		  " with irrelevant type %d",rrtype);
     }
   }
 
@@ -233,9 +246,11 @@
   nsstart= cbyte;
 
   if (!wantedrrs) {
-    /* Oops, NODATA or NXDOMAIN or perhaps a referral (which would be a problem) */
+    /* Oops, NODATA or NXDOMAIN or perhaps a referral
+     * (which would be a problem) */
 
-    /* RFC2308: NODATA has _either_ a SOA _or_ _no_ NS records in authority section */
+    /* RFC2308: NODATA has _either_ a SOA _or_ _no_ NS records
+     * in authority section */
     foundsoa= 0; soattl= 0; foundns= 0;
     for (rri= 0; rri<nscount; rri++) {
       rrstart= cbyte;
@@ -245,8 +260,8 @@
       if (rrtype==-1) goto x_truncated;
       if (rrclass != DNS_CLASS_IN) {
 	adns__diag(ads,serv,qu,
-		   "ignoring authority RR with wrong class %d (expected IN=%d)",
-		   rrclass,DNS_CLASS_IN);
+		   "ignoring authority RR with wrong class %d"
+		   " (expected IN=%d)", rrclass,DNS_CLASS_IN);
 	continue;
       }
       if (rrtype == adns_r_soa_raw) { foundsoa= 1; soattl= ttl; break; }
@@ -257,7 +272,7 @@
       /* We still wanted to look for the SOA so we could find the TTL. */
       adns__update_expires(qu,soattl,now);
 
-      if (qu->flags & adns_qf_search) {
+      if (qu->flags & adns_qf_search && !qu->cname_dgram) {
 	adns__search_next(ads,qu,now);
       } else {
 	adns__query_fail(qu,adns_s_nxdomain);
@@ -281,13 +296,16 @@
 
     /* Bloody hell, I thought we asked for recursion ? */
     if (!flg_ra) {
-      adns__diag(ads,serv,qu,"server is not willing to do recursive lookups for us");
+      adns__diag(ads,serv,qu,"server is not willing"
+		 " to do recursive lookups for us");
       adns__query_fail(qu,adns_s_norecurse);
     } else {
       if (!flg_rd)
-	adns__diag(ads,serv,qu,"server thinks we didn't ask for recursive lookup");
+	adns__diag(ads,serv,qu,"server thinks"
+		   " we didn't ask for recursive lookup");
       else
-	adns__debug(ads,serv,qu,"server claims to do recursion, but gave us a referral");
+	adns__debug(ads,serv,qu,"server claims to do recursion,"
+		    " but gave us a referral");
       adns__query_fail(qu,adns_s_invalidresponse);
     }
     return;
@@ -296,7 +314,10 @@
   /* Now, we have some RRs which we wanted. */
 
   qu->answer->rrs.untyped= adns__alloc_interim(qu,qu->typei->rrsz*wantedrrs);
-  if (!qu->answer->rrs.untyped) { adns__query_fail(qu,adns_s_nomemory); return; }
+  if (!qu->answer->rrs.untyped) {
+    adns__query_fail(qu,adns_s_nomemory);
+    return;
+  }
 
   typei= qu->typei;
   cbyte= anstart;
@@ -351,7 +372,7 @@
  x_restartquery:
   if (qu->cname_dgram) {
     st= adns__mkquery_frdgram(qu->ads,&qu->vb,&qu->id,
-			      qu->cname_dgram, qu->cname_dglen, qu->cname_begin,
+			      qu->cname_dgram,qu->cname_dglen,qu->cname_begin,
 			      qu->typei->type, qu->flags);
     if (st) { adns__query_fail(qu,st); return; }
     
Index: adns/src/setup.c
diff -u adns/src/setup.c:1.39 adns/src/setup.c:1.42
--- adns/src/setup.c:1.39	Sun Sep 17 01:24:24 2000
+++ adns/src/setup.c	Sun Jun 22 14:01:11 2003
@@ -32,6 +32,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 
+#include <sys/types.h>
 #include <netdb.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -103,7 +104,8 @@
   return 1;
 }
 
-static void ccf_nameserver(adns_state ads, const char *fn, int lno, const char *buf) {
+static void ccf_nameserver(adns_state ads, const char *fn,
+			   int lno, const char *buf) {
   struct in_addr ia;
   
   if (!inet_aton(buf,&ia)) {
@@ -114,7 +116,8 @@
   addserver(ads,ia);
 }
 
-static void ccf_search(adns_state ads, const char *fn, int lno, const char *buf) {
+static void ccf_search(adns_state ads, const char *fn,
+		       int lno, const char *buf) {
   const char *bufp, *word;
   char *newchars, **newptrs, **pp;
   int count, tl, l;
@@ -126,8 +129,11 @@
   tl= 0;
   while (nextword(&bufp,&word,&l)) { count++; tl += l+1; }
 
-  newptrs= malloc(sizeof(char*)*count);  if (!newptrs) { saveerr(ads,errno); return; }
-  newchars= malloc(tl);  if (!newchars) { saveerr(ads,errno); free(newptrs); return; }
+  newptrs= malloc(sizeof(char*)*count);
+  if (!newptrs) { saveerr(ads,errno); return; }
+
+  newchars= malloc(tl);
+  if (!newchars) { saveerr(ads,errno); free(newptrs); return; }
 
   bufp= buf;
   pp= newptrs;
@@ -143,7 +149,8 @@
   ads->searchlist= newptrs;
 }
 
-static void ccf_sortlist(adns_state ads, const char *fn, int lno, const char *buf) {
+static void ccf_sortlist(adns_state ads, const char *fn,
+			 int lno, const char *buf) {
   const char *word;
   char tbuf[200], *slash, *ep;
   struct in_addr base, mask;
@@ -155,7 +162,8 @@
   ads->nsortlist= 0;
   while (nextword(&buf,&word,&l)) {
     if (ads->nsortlist >= MAXSORTLIST) {
-      adns__diag(ads,-1,0,"too many sortlist entries, ignoring %.*s onwards",l,word);
+      adns__diag(ads,-1,0,"too many sortlist entries,"
+		 " ignoring %.*s onwards",l,word);
       return;
     }
 
@@ -180,8 +188,8 @@
 	  continue;
 	}
 	if (base.s_addr & ~mask.s_addr) {
-	  configparseerr(ads,fn,lno,
-			 "mask `%s' in sortlist overlaps address `%s'",slash,tbuf);
+	  configparseerr(ads,fn,lno, "mask `%s' in sortlist"
+			 " overlaps address `%s'",slash,tbuf);
 	  continue;
 	}
       } else {
@@ -201,8 +209,8 @@
       else if ((baselocal & 0x0f0000000UL) == 0x0e0000000UL)
 	mask.s_addr= htonl(0x0ff000000UL); /* class C */
       else {
-	configparseerr(ads,fn,lno,
-		       "network address `%s' in sortlist is not in classed ranges,"
+	configparseerr(ads,fn,lno, "network address `%s'"
+		       " in sortlist is not in classed ranges,"
 		       " must specify mask explicitly", tbuf);
 	continue;
       }
@@ -214,7 +222,8 @@
   }
 }
 
-static void ccf_options(adns_state ads, const char *fn, int lno, const char *buf) {
+static void ccf_options(adns_state ads, const char *fn,
+			int lno, const char *buf) {
   const char *word;
   char *ep;
   unsigned long v;
@@ -230,7 +239,8 @@
     if (l>=6 && !memcmp(word,"ndots:",6)) {
       v= strtoul(word+6,&ep,10);
       if (l==6 || ep != word+l || v > INT_MAX) {
-	configparseerr(ads,fn,lno,"option `%.*s' malformed or has bad value",l,word);
+	configparseerr(ads,fn,lno,"option `%.*s' malformed"
+		       " or has bad value",l,word);
 	continue;
       }
       ads->searchndots= v;
@@ -255,11 +265,13 @@
   }
 }
 
-static void ccf_clearnss(adns_state ads, const char *fn, int lno, const char *buf) {
+static void ccf_clearnss(adns_state ads, const char *fn,
+			 int lno, const char *buf) {
   ads->nservers= 0;
 }
 
-static void ccf_include(adns_state ads, const char *fn, int lno, const char *buf) {
+static void ccf_include(adns_state ads, const char *fn,
+			int lno, const char *buf) {
   if (!*buf) {
     configparseerr(ads,fn,lno,"`include' directive with no filename");
     return;
@@ -267,6 +279,35 @@
   readconfig(ads,buf,1);
 }
 
+static void ccf_lookup(adns_state ads, const char *fn, int lno,
+		       const char *buf) {
+  int found_bind=0;
+  const char *word;
+  int l;
+
+  if (!*buf) {
+    configparseerr(ads,fn,lno,"`lookup' directive with no databases");
+    return;
+  }
+
+  while (nextword(&buf,&word,&l)) {
+    if (l==4 && !memcmp(word,"bind",4)) {
+      found_bind=1;
+    } else if (l==4 && !memcmp(word,"file",4)) {
+      /* ignore this and hope /etc/hosts is not essential */
+    } else if (l==2 && !memcmp(word,"yp",2)) {
+      adns__diag(ads,-1,0,"%s:%d: yp lookups not supported by adns", fn,lno);
+      found_bind=-1;
+    } else {
+      adns__diag(ads,-1,0,"%s:%d: unknown `lookup' database `%.*s'",
+		 fn,lno, l,word);
+      found_bind=-1;
+    }
+  }
+  if (!found_bind)
+    adns__diag(ads,-1,0,"%s:%d: `lookup' specified, but not `bind'", fn,lno);
+}
+
 static const struct configcommandinfo {
   const char *name;
   void (*fn)(adns_state ads, const char *fn, int lno, const char *buf);
@@ -278,6 +319,7 @@
   { "options",           ccf_options     },
   { "clearnameservers",  ccf_clearnss    },
   { "include",           ccf_include     },
+  { "lookup",            ccf_lookup      }, /* OpenBSD */
   {  0                                   }
 };
 
@@ -310,7 +352,8 @@
     } else if (c == EOF) {
       if (ferror(file)) {
 	saveerr(ads,errno);
-	adns__diag(ads,-1,0,"%s:%d: read error: %s",filename,lno,strerror(errno));
+	adns__diag(ads,-1,0,"%s:%d: read error: %s",
+		   filename,lno,strerror(errno));
 	return -1;
       }
       if (!i) return -1;
@@ -378,7 +421,8 @@
     while (*q && !ctype_whitespace(*q)) q++;
     dirl= q-p;
     for (ccip=configcommandinfos;
-	 ccip->name && !(strlen(ccip->name)==dirl && !memcmp(ccip->name,p,q-p));
+	 ccip->name &&
+	   !(strlen(ccip->name)==dirl && !memcmp(ccip->name,p,q-p));
 	 ccip++);
     if (!ccip->name) {
       adns__diag(ads,-1,0,"%s:%d: unknown configuration directive `%.*s'",
@@ -395,7 +439,8 @@
 
   value= getenv(envvar);
   if (!value) adns__debug(ads,-1,0,"environment variable %s not set",envvar);
-  else adns__debug(ads,-1,0,"environment variable %s set to `%s'",envvar,value);
+  else adns__debug(ads,-1,0,"environment variable %s"
+		   " set to `%s'",envvar,value);
   return value;
 }
 
@@ -406,7 +451,8 @@
   if (!gl_ctx.file) {
     if (errno == ENOENT) {
       if (warnmissing)
-	adns__debug(ads,-1,0,"configuration file `%s' does not exist",filename);
+	adns__debug(ads,-1,0, "configuration file"
+		    " `%s' does not exist",filename);
       return;
     }
     saveerr(ads,errno);
@@ -420,7 +466,8 @@
   fclose(gl_ctx.file);
 }
 
-static void readconfigtext(adns_state ads, const char *text, const char *showname) {
+static void readconfigtext(adns_state ads, const char *text,
+			   const char *showname) {
   getline_ctx gl_ctx;
   
   gl_ctx.text= text;
@@ -459,7 +506,8 @@
   return 0;
 }
 
-static int init_begin(adns_state *ads_r, adns_initflags flags, FILE *diagfile) {
+static int init_begin(adns_state *ads_r, adns_initflags flags,
+		      FILE *diagfile) {
   adns_state ads;
   
   ads= malloc(sizeof(*ads)); if (!ads) return errno;
Index: adns/src/transmit.c
diff -u adns/src/transmit.c:1.22 adns/src/transmit.c:1.24
--- adns/src/transmit.c:1.22	Sun Sep 17 01:24:24 2000
+++ adns/src/transmit.c	Sun Jun 22 14:58:15 2003
@@ -39,7 +39,8 @@
 #define MKQUERY_ADDW(w) (MKQUERY_ADDB(((w)>>8)&0x0ff), MKQUERY_ADDB((w)&0x0ff))
 #define MKQUERY_STOP(vb) ((vb)->used= rqp-(vb)->buf)
 
-static adns_status mkquery_header(adns_state ads, vbuf *vb, int *id_r, int qdlen) {
+static adns_status mkquery_header(adns_state ads, vbuf *vb,
+				  int *id_r, int qdlen) {
   int id;
   byte *rqp;
   
@@ -95,7 +96,9 @@
 	if (!(flags & adns_qf_quoteok_query)) return adns_s_querydomaininvalid;
 	if (ctype_digit(p[0])) {
 	  if (ctype_digit(p[1]) && ctype_digit(p[2])) {
-	    c= (*p++ - '0')*100 + (*p++ - '0')*10 + (*p++ - '0');
+	    c= (*p++ - '0')*100;
+	    c += (*p++ - '0')*10;
+	    c += (*p++ - '0');
 	    if (c >= 256) return adns_s_querydomaininvalid;
 	  } else {
 	    return adns_s_querydomaininvalid;
@@ -131,7 +134,8 @@
 }
 
 adns_status adns__mkquery_frdgram(adns_state ads, vbuf *vb, int *id_r,
-				  const byte *qd_dgram, int qd_dglen, int qd_begin,
+				  const byte *qd_dgram, int qd_dglen,
+				  int qd_begin,
 				  adns_rrtype type, adns_queryflags flags) {
   byte *rqp;
   findlabel_state fls;
@@ -174,7 +178,8 @@
   length[1]= (qu->query_dglen&0x0ff);
 
   ads= qu->ads;
-  if (!adns__vbuf_ensure(&ads->tcpsend,ads->tcpsend.used+qu->query_dglen+2)) return;
+  if (!adns__vbuf_ensure(&ads->tcpsend,ads->tcpsend.used+qu->query_dglen+2))
+    return;
 
   qu->retries++;
 
@@ -208,7 +213,8 @@
     wr-= 2;
   }
   if (wr<qu->query_dglen) {
-    r= adns__vbuf_append(&ads->tcpsend,qu->query_dgram+wr,qu->query_dglen-wr); assert(r);
+    r= adns__vbuf_append(&ads->tcpsend,qu->query_dgram+wr,qu->query_dglen-wr);
+    assert(r);
   }
 }
 
@@ -247,8 +253,13 @@
   
   r= sendto(ads->udpsocket,qu->query_dgram,qu->query_dglen,0,
 	    (const struct sockaddr*)&servaddr,sizeof(servaddr));
-  if (r<0 && errno == EMSGSIZE) { qu->retries= 0; query_usetcp(qu,now); return; }
-  if (r<0 && errno != EAGAIN) adns__warn(ads,serv,0,"sendto failed: %s",strerror(errno));
+  if (r<0 && errno == EMSGSIZE) {
+    qu->retries= 0;
+    query_usetcp(qu,now);
+    return;
+  }
+  if (r<0 && errno != EAGAIN)
+    adns__warn(ads,serv,0,"sendto failed: %s",strerror(errno));
   
   qu->timeout= now;
   timevaladd(&qu->timeout,UDPRETRYMS);
Index: adns/src/types.c
diff -u adns/src/types.c:1.38 adns/src/types.c:1.39
--- adns/src/types.c:1.38	Sun Sep 17 02:52:39 2000
+++ adns/src/types.c	Sun Jun 22 14:01:11 2003
@@ -34,8 +34,10 @@
 
 #include "internal.h"
 
-#define R_NOMEM           return adns_s_nomemory
-#define CSP_ADDSTR(s)     do { if (!adns__vbuf_appendstr(vb,(s))) R_NOMEM; } while (0)
+#define R_NOMEM       return adns_s_nomemory
+#define CSP_ADDSTR(s) do {			\
+    if (!adns__vbuf_appendstr(vb,(s))) R_NOMEM;	\
+  } while (0)
 
 /*
  * order of sections:
@@ -172,7 +174,8 @@
  * _txt   (pa,cs)
  */
 
-static adns_status pa_txt(const parseinfo *pai, int cbyte, int max, void *datap) {
+static adns_status pa_txt(const parseinfo *pai, int cbyte,
+			  int max, void *datap) {
   adns_rr_intstr **rrp= datap, *table, *te;
   const byte *dgram= pai->dgram;
   int ti, tc, l, startbyte;
@@ -235,7 +238,8 @@
  * _inaddr   (pa,dip,di)
  */
 
-static adns_status pa_inaddr(const parseinfo *pai, int cbyte, int max, void *datap) {
+static adns_status pa_inaddr(const parseinfo *pai, int cbyte,
+			     int max, void *datap) {
   struct in_addr *storeto= datap;
   
   if (max-cbyte != 4) return adns_s_invaliddata;
@@ -248,7 +252,8 @@
   int i;
   
   for (i=0, slp=ads->sortlist;
-       i<ads->nsortlist && !((ad.s_addr & slp->mask.s_addr) == slp->base.s_addr);
+       i<ads->nsortlist &&
+	 !((ad.s_addr & slp->mask.s_addr) == slp->base.s_addr);
        i++, slp++);
   return i;
 }
@@ -263,7 +268,8 @@
   return bi<ai;
 }
 
-static int di_inaddr(adns_state ads, const void *datap_a, const void *datap_b) {
+static int di_inaddr(adns_state ads,
+		     const void *datap_a, const void *datap_b) {
   const struct in_addr *ap= datap_a, *bp= datap_b;
 
   return dip_inaddr(ads,*ap,*bp);
@@ -282,7 +288,8 @@
  * _addr   (pa,di,csp,cs)
  */
 
-static adns_status pa_addr(const parseinfo *pai, int cbyte, int max, void *datap) {
+static adns_status pa_addr(const parseinfo *pai, int cbyte,
+			   int max, void *datap) {
   adns_rr_addr *storeto= datap;
   const byte *dgram= pai->dgram;
 
@@ -367,7 +374,8 @@
   return csp_domain(vb,*domainp);
 }
 
-static adns_status pa_dom_raw(const parseinfo *pai, int cbyte, int max, void *datap) {
+static adns_status pa_dom_raw(const parseinfo *pai, int cbyte,
+			      int max, void *datap) {
   char **rrp= datap;
   adns_status st;
 
@@ -382,7 +390,8 @@
  * _host_raw   (pa)
  */
 
-static adns_status pa_host_raw(const parseinfo *pai, int cbyte, int max, void *datap) {
+static adns_status pa_host_raw(const parseinfo *pai, int cbyte,
+			       int max, void *datap) {
   char **rrp= datap;
   adns_status st;
 
@@ -406,7 +415,8 @@
   adns_status st;
   
   for (rri=0, naddrs=-1; rri<count; rri++) {
-    st= adns__findrr_anychk(pai->qu, pai->serv, pai->dgram, pai->dglen, cbyte_io,
+    st= adns__findrr_anychk(pai->qu, pai->serv, pai->dgram,
+			    pai->dglen, cbyte_io,
 			    &type, &class, &ttl, &rdlen, &rdstart,
 			    pai->dgram, pai->dglen, dmstart, &ownermatched);
     if (st) return st;
@@ -416,7 +426,8 @@
     if (naddrs == -1) {
       naddrs= 0;
     }
-    if (!adns__vbuf_ensure(&pai->qu->vb, (naddrs+1)*sizeof(adns_rr_addr))) R_NOMEM;
+    if (!adns__vbuf_ensure(&pai->qu->vb, (naddrs+1)*sizeof(adns_rr_addr)))
+      R_NOMEM;
     adns__update_expires(pai->qu,ttl,pai->now);
     st= pa_addr(pai, rdstart,rdstart+rdlen,
 		pai->qu->vb.buf + naddrs*sizeof(adns_rr_addr));
@@ -446,7 +457,8 @@
   rrp->astatus= st;
   rrp->naddrs= (st>0 && st<=adns_s_max_tempfail) ? -1 : cans->nrrs;
   rrp->addrs= cans->rrs.addr;
-  adns__transfer_interim(child, parent, rrp->addrs, rrp->naddrs*sizeof(adns_rr_addr));
+  adns__transfer_interim(child, parent, rrp->addrs,
+			 rrp->naddrs*sizeof(adns_rr_addr));
 
   if (parent->children.head) {
     LIST_LINK_TAIL(ads->childw,parent);
@@ -506,7 +518,8 @@
   return adns_s_ok;
 }
 
-static adns_status pa_hostaddr(const parseinfo *pai, int cbyte, int max, void *datap) {
+static adns_status pa_hostaddr(const parseinfo *pai, int cbyte,
+			       int max, void *datap) {
   adns_rr_hostaddr *rrp= datap;
   adns_status st;
 
@@ -517,7 +530,8 @@
   return adns_s_ok;
 }
 
-static int dip_hostaddr(adns_state ads, const adns_rr_hostaddr *ap, const adns_rr_hostaddr *bp) {
+static int dip_hostaddr(adns_state ads,
+			const adns_rr_hostaddr *ap, const adns_rr_hostaddr *bp) {
   if (ap->astatus != bp->astatus) return ap->astatus;
   if (ap->astatus) return 0;
 
@@ -528,7 +542,8 @@
 		    bp->addrs[0].addr.inet.sin_addr);
 }
 
-static int di_hostaddr(adns_state ads, const void *datap_a, const void *datap_b) {
+static int di_hostaddr(adns_state ads,
+		       const void *datap_a, const void *datap_b) {
   const adns_rr_hostaddr *ap= datap_a, *bp= datap_b;
 
   return dip_hostaddr(ads, ap,bp);
@@ -592,7 +607,8 @@
  * _mx_raw   (pa,di)
  */
 
-static adns_status pa_mx_raw(const parseinfo *pai, int cbyte, int max, void *datap) {
+static adns_status pa_mx_raw(const parseinfo *pai, int cbyte,
+			     int max, void *datap) {
   const byte *dgram= pai->dgram;
   adns_rr_intstr *rrp= datap;
   adns_status st;
@@ -621,7 +637,8 @@
  * _mx   (pa,di)
  */
 
-static adns_status pa_mx(const parseinfo *pai, int cbyte, int max, void *datap) {
+static adns_status pa_mx(const parseinfo *pai, int cbyte,
+			 int max, void *datap) {
   const byte *dgram= pai->dgram;
   adns_rr_inthostaddr *rrp= datap;
   adns_status st;
@@ -713,7 +730,8 @@
   adns__query_fail(parent,adns_s_inconsistent);
 }
 
-static adns_status pa_ptr(const parseinfo *pai, int dmstart, int max, void *datap) {
+static adns_status pa_ptr(const parseinfo *pai, int dmstart,
+			  int max, void *datap) {
   static const char *(expectdomain[])= { DNS_INADDR_ARPA };
   
   char **rrp= datap;
@@ -741,15 +759,18 @@
     for (i=0; i<4; i++) {
       st= adns__findlabel_next(&fls,&lablen,&labstart); assert(!st);
       if (lablen<=0 || lablen>3) return adns_s_querydomainwrong;
-      memcpy(labbuf, pai->qu->query_dgram + labstart, lablen);  labbuf[lablen]= 0;
-      ipv[3-i]= strtoul(labbuf,&ep,10);  if (*ep) return adns_s_querydomainwrong;
+      memcpy(labbuf, pai->qu->query_dgram + labstart, lablen);
+      labbuf[lablen]= 0;
+      ipv[3-i]= strtoul(labbuf,&ep,10);
+      if (*ep) return adns_s_querydomainwrong;
       if (lablen>1 && pai->qu->query_dgram[labstart]=='0')
 	return adns_s_querydomainwrong;
     }
     for (i=0; i<sizeof(expectdomain)/sizeof(*expectdomain); i++) {
       st= adns__findlabel_next(&fls,&lablen,&labstart); assert(!st);
       l= strlen(expectdomain[i]);
-      if (lablen != l || memcmp(pai->qu->query_dgram + labstart, expectdomain[i], l))
+      if (lablen != l ||
+	  memcmp(pai->qu->query_dgram + labstart, expectdomain[i], l))
 	return adns_s_querydomainwrong;
     }
     st= adns__findlabel_next(&fls,&lablen,0); assert(!st);
@@ -806,7 +827,8 @@
  * _hinfo   (pa)
  */
 
-static adns_status pa_hinfo(const parseinfo *pai, int cbyte, int max, void *datap) {
+static adns_status pa_hinfo(const parseinfo *pai, int cbyte,
+			    int max, void *datap) {
   adns_rr_intstrpair *rrp= datap;
   adns_status st;
   int i;
@@ -825,8 +847,8 @@
  * _mailbox   (pap,cs)
  */
 
-static adns_status pap_mailbox822(const parseinfo *pai, int *cbyte_io, int max,
-				  char **mb_r) {
+static adns_status pap_mailbox822(const parseinfo *pai,
+				  int *cbyte_io, int max, char **mb_r) {
   int lablen, labstart, i, needquote, c, r, neednorm;
   const unsigned char *p;
   char *str;
@@ -898,7 +920,8 @@
  * _rp   (pa,cs)
  */
 
-static adns_status pa_rp(const parseinfo *pai, int cbyte, int max, void *datap) {
+static adns_status pa_rp(const parseinfo *pai, int cbyte,
+			 int max, void *datap) {
   adns_rr_strpair *rrp= datap;
   adns_status st;
 
@@ -927,7 +950,8 @@
  * _soa   (pa,mf,cs)
  */
 
-static adns_status pa_soa(const parseinfo *pai, int cbyte, int max, void *datap) {
+static adns_status pa_soa(const parseinfo *pai, int cbyte,
+			  int max, void *datap) {
   adns_rr_soa *rrp= datap;
   const byte *dgram= pai->dgram;
   adns_status st;
@@ -992,31 +1016,31 @@
 #define FLAT_MEMB(memb) TYPESZ_M(memb), mf_flat, cs_##memb
 
 #define DEEP_TYPE(code,rrt,fmt,memb,parser,comparer,printer) \
- { adns_r_##code, rrt, fmt, TYPESZ_M(memb), mf_##memb, printer, parser, comparer }
+ { adns_r_##code, rrt,fmt,TYPESZ_M(memb), mf_##memb, printer,parser,comparer }
 #define FLAT_TYPE(code,rrt,fmt,memb,parser,comparer,printer) \
- { adns_r_##code, rrt, fmt, TYPESZ_M(memb), mf_flat, printer, parser, comparer }
+ { adns_r_##code, rrt,fmt,TYPESZ_M(memb), mf_flat,   printer,parser,comparer }
 
 static const typeinfo typeinfos[] = {
 /* Must be in ascending order of rrtype ! */
-/* mem-mgmt code  rrt     fmt     member      parser      comparer    printer       */
-  		    		     		 	     		 	       
-FLAT_TYPE(a,      "A",     0,     inaddr,     pa_inaddr,  di_inaddr,  cs_inaddr     ),
-DEEP_TYPE(ns_raw, "NS",   "raw",  str,        pa_host_raw,0,          cs_domain     ),
-DEEP_TYPE(cname,  "CNAME", 0,     str,        pa_dom_raw, 0,          cs_domain     ),
-DEEP_TYPE(soa_raw,"SOA",  "raw",  soa,        pa_soa,     0,          cs_soa        ),
-DEEP_TYPE(ptr_raw,"PTR",  "raw",  str,        pa_host_raw,0,          cs_domain     ),
-DEEP_TYPE(hinfo,  "HINFO", 0,     intstrpair, pa_hinfo,   0,          cs_hinfo      ),
-DEEP_TYPE(mx_raw, "MX",   "raw",  intstr,     pa_mx_raw,  di_mx_raw,  cs_inthost    ),
-DEEP_TYPE(txt,    "TXT",   0,     manyistr,   pa_txt,     0,          cs_txt        ),
-DEEP_TYPE(rp_raw, "RP",   "raw",  strpair,    pa_rp,      0,          cs_rp         ),
- 		     	                                     		   	       
-FLAT_TYPE(addr,   "A",  "addr",   addr,       pa_addr,    di_addr,    cs_addr       ),
-DEEP_TYPE(ns,     "NS", "+addr",  hostaddr,   pa_hostaddr,di_hostaddr,cs_hostaddr   ),
-DEEP_TYPE(ptr,    "PTR","checked",str,        pa_ptr,     0,          cs_domain     ),
-DEEP_TYPE(mx,     "MX", "+addr",  inthostaddr,pa_mx,      di_mx,      cs_inthostaddr),
- 		     	                                     		      
-DEEP_TYPE(soa,    "SOA","822",    soa,        pa_soa,     0,          cs_soa        ),
-DEEP_TYPE(rp,     "RP", "822",    strpair,    pa_rp,      0,          cs_rp         ),
+/* mem-mgmt code  rrt     fmt   member   parser      comparer  printer */
+
+FLAT_TYPE(a,      "A",     0,   inaddr,  pa_inaddr,  di_inaddr,cs_inaddr     ),
+DEEP_TYPE(ns_raw, "NS",   "raw",str,     pa_host_raw,0,        cs_domain     ),
+DEEP_TYPE(cname,  "CNAME", 0,   str,     pa_dom_raw, 0,        cs_domain     ),
+DEEP_TYPE(soa_raw,"SOA",  "raw",soa,     pa_soa,     0,        cs_soa        ),
+DEEP_TYPE(ptr_raw,"PTR",  "raw",str,     pa_host_raw,0,        cs_domain     ),
+DEEP_TYPE(hinfo,  "HINFO", 0, intstrpair,pa_hinfo,   0,        cs_hinfo      ),
+DEEP_TYPE(mx_raw, "MX",   "raw",intstr,  pa_mx_raw,  di_mx_raw,cs_inthost    ),
+DEEP_TYPE(txt,    "TXT",   0,   manyistr,pa_txt,     0,        cs_txt        ),
+DEEP_TYPE(rp_raw, "RP",   "raw",strpair, pa_rp,      0,        cs_rp         ),
+
+FLAT_TYPE(addr,   "A",  "addr", addr,    pa_addr,    di_addr,  cs_addr       ),
+DEEP_TYPE(ns,     "NS", "+addr",hostaddr,pa_hostaddr,di_hostaddr,cs_hostaddr ),
+DEEP_TYPE(ptr,    "PTR","checked",str,   pa_ptr,     0,        cs_domain     ),
+DEEP_TYPE(mx,     "MX", "+addr",inthostaddr,pa_mx,   di_mx,    cs_inthostaddr),
+ 		     	                                   		      
+DEEP_TYPE(soa,    "SOA","822",  soa,     pa_soa,     0,        cs_soa        ),
+DEEP_TYPE(rp,     "RP", "822",  strpair, pa_rp,      0,        cs_rp         ),
 };
 
 const typeinfo *adns__findtype(adns_rrtype type) {
