monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-devel] MinGW patch


From: Jon Bright
Subject: [Monotone-devel] MinGW patch
Date: Mon, 29 Mar 2004 23:49:11 +0200
User-agent: Mozilla Thunderbird 0.5 (Windows/20040207)

Hi,

I've finally got around to sorting out the MinGW patch. Attached are in fact two patches (both against a pull of monotone from about 4 hours ago) - the first, monotone-win32.patch contains the changes to the monotone source itself. The second switches the adns version as distributed with monotone for a Win32 port of adns. As far as I can tell, this should still compile and work just fine on Linux/Unix, but I've not had a chance to test this yet. I similarly haven't attempted to configure or build the patched monotone on Linux/Unix, but everything I've done should work fine there.

Limitations:
   i) Passwords will be echoed as they're entered, haven't looked in
      to windows equivalents for the termios juggling yet.
  ii) rcs_file.cc needed a replacement mmap writing, it's totally
      untested (but may work :-)
 iii) rcs_import.cc needed a replacement for strptime.  It's been
      replaced with a simple sscanf which is similarly untested
  iv) smtp_tasks.cc is no longer re-entrant, since there's no
      localtime_r on Windows.  I suspect this won't really be a problem,
      but I've been known to be wrong.
   v) the hacked-together mkstemp-replacement in lua/liolib.c is
      probably a security/re-entrancy nightmare
  vi) The testsuite mostly fails.  This is mostly due to path errors as
      far as I can tell.  Will look into this more.  I'm pretty sure
      that this will (at least mostly) work fine once either Boost has
      been persuaded that "C:" does belong in a pathname on windows, or
      the testsuite has been persuaded not to give drive-letter-prefixed
      paths to Boost (with a strong preference on the former solution,
      obviously).  A newer version of Boost may help, I'll check that.
 vii) I'm no autoconf/automake guru, so those parts can probably be done
      better, but the way the patch does them works
viii) Some of the #ifdefing ends up looking mighty ugly.  Adjust to
      taste.

Steps to build and use this:

1. Download the MinGW exe, the MSYS exe, the gettext exe and the libiconv exe from http://www.mingw.org/download.shtml 2. Install MinGW, then MSYS. After install, MSYS will ask if you have a MinGW install. Tell it yes, give it the path of your MinGW install.
3. Install gettext and libiconv.
4. Get popt-1.7.tar.gz from ftp://ftp.rpm.org/pub/rpm/dist/rpm-4.1.x/ and copy it to c:\msys\1.0\home\<username>
5. Start msys
6. tar zxvf popt-1.7.tar.gz
7. Using your favourite text editor, edit popt-1.7/intl/localename.c
8. Search for LANG_SORBIAN, delete the line on which it appears. Not doing so results in a compile error.
9. In MSYS again, cd into the popt-1.7 directory
10. ./configure --prefix=/mingw && make && make install
11. Get boost 1.31.0 from www.boost.org.
12. In MSYS, untar it
13. Open a windows command window (cmd.exe), then:
14. set PATH=%PATH%;c:\mingw\bin (or wherever your mingw is)
15. cd c:\msys\1.0\home\<username>\boost_1_31_0\tools\build\jam_src
16. build.bat mingw
17. Back in MSYS:
18. cd ~/boost_1_31_0
19. tools/build/jam_src/bin.ntx86/bjam.exe -sTOOLS=mingw "-sBUILD=release <threading>single <optimization>speed <runtime-link>static" 20. find . -name libboost*.lib -a -type f |awk -F / -- '{a=$NF;gsub("-mgw-s-1_31.lib",".a",a);system("cp " $0 " /mingw/lib/" a);}'
    (this copies the boost libraries, renaming them appropriately, to
    the MinGW lib dir)
21. cp -a boost /mingw/include
22. Get the monotone source (with patch), unpack it inside your home directory in MSYS
23. ./configure
24. make
25. make check also works, but 26 of 29 tests fail
26. In a Windows shell: c:\msys\1.0\home\<user>\monotone-0.11\monotone --db=\dir\monotone.db db init Specifying the path here is important - if you don't, it takes something like c:\dir\monotone.db - at which point, boost chokes on the "c:". See limitation vi above. 27. Copy the keys to keys.txt, as specified in self-hosting info on the monotone site 28. c:\msys\1.0\home\<user>\monotone-0.11\monotone --db=\dir\monotone.db read <keys.txt 29. c:\msys\1.0\home\<user>\monotone-0.11\monotone --db=\dir\monotone.db fetch http://www.off.net/monotone/depot.cgi/monotone 30. c:\msys\1.0\home\<user>\monotone-0.11\monotone --db=\dir\monotone.db --branch=net.venge.monotone heads 31. c:\msys\1.0\home\<user>\monotone-0.11\monotone --db=\dir\monotone.db ls certs manifest dcc23 32. c:\msys\1.0\home\<user>\monotone-0.11\monotone --db=\dir\monotone.db checkout dcc23 . 33. c:\msys\1.0\home\<user>\monotone-0.11\monotone --db=\dir\monotone.db fetch 34. c:\msys\1.0\home\<user>\monotone-0.11\monotone --db=\dir\monotone.db update

(this last one doesn't work until you give it a --branch)

--
Jon Bright
Silicon Circus Ltd.
http://www.siliconcircus.com

diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/Makefile.am monotone-win32/Makefile.am
--- monotone-pulled/Makefile.am Mon Mar 29 17:52:18 2004
+++ monotone-win32/Makefile.am  Mon Mar 29 20:43:49 2004
@@ -109,7 +109,8 @@
 ADNS_SOURCES = \
        adns/adns.h adns/check.c adns/config.h adns/dlist.h adns/event.c \
        adns/general.c adns/internal.h adns/parse.c adns/poll.c adns/query.c \
-       adns/reply.c adns/setup.c adns/transmit.c adns/tvarith.h adns/types.c 
+       adns/reply.c adns/setup.c adns/transmit.c adns/tvarith.h adns/types.c \
+       adns/adns_unix_calls.c
 
 IDNA_SOURCES = \
        idna/gunibreak.h idna/gunidecomp.h idna/idna.h idna/nfkc.c      \
@@ -151,15 +152,19 @@
 
 if STATIC_BOOST
 address@hidden@/libboost_filesystem.a @BOOST_LIBDIR@/libboost_date_time.a 
@BOOST_LIBDIR@/libboost_regex.a
-monotone_LDADD = lib3rdparty.a $(BOOSTLIBS) 
@BOOST_LIBDIR@/libboost_prg_exec_monitor.a
-unit_tests_LDADD = lib3rdparty.a $(BOOSTLIBS) 
@BOOST_LIBDIR@/libboost_unit_test_framework.a
+monotone_LDADD = lib3rdparty.a $(BOOSTLIBS) 
@BOOST_LIBDIR@/libboost_prg_exec_monitor.a @win32_libs@
+unit_tests_LDADD = lib3rdparty.a $(BOOSTLIBS) 
@BOOST_LIBDIR@/libboost_unit_test_framework.a @win32_libs@
 depot_cgi_LDADD = lib3rdparty.a $(BOOSTLIBS)
 else
-monotone_LDADD = lib3rdparty.a -lboost_prg_exec_monitor
-unit_tests_LDADD = lib3rdparty.a -lboost_unit_test_framework
+monotone_LDADD = lib3rdparty.a -lboost_prg_exec_monitor @win32_libs@
+unit_tests_LDADD = lib3rdparty.a -lboost_unit_test_framework @win32_libs@
 depot_cgi_LDADD = lib3rdparty.a
 endif
 
+# adns_win32 would be inside BUNDLED_ADNS up above, but if I do that, building 
+# adns/lib3rdparty_a-check.o fails, since it doesn't seem to use those flags...
+lib3rdparty_a_CPPFLAGS = @netxx_win32@ @adns_win32@
+
 monotone_LDFLAGS = 
 monotone_CPPFLAGS = 
 
@@ -241,7 +246,7 @@
 
 txt2c: txt2c.cc Makefile
        $(CXX) -Wall -o $@ $<
-       chmod 0755 $@
+       chmod 0755 address@hidden(EXEEXT)
 
 %.h: %.sql txt2c Makefile
        ./txt2c $< $(*F) >$@
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/app_state.cc monotone-win32/app_state.cc
--- monotone-pulled/app_state.cc        Mon Mar 29 17:52:20 2004
+++ monotone-win32/app_state.cc Mon Mar 29 19:18:27 2004
@@ -1,4 +1,3 @@
-#include <termios.h>
 #include <iostream>
 
 #include "app_state.hh"
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/configure.ac monotone-win32/configure.ac
--- monotone-pulled/configure.ac        Mon Mar 29 17:52:20 2004
+++ monotone-win32/configure.ac Mon Mar 29 18:38:39 2004
@@ -163,6 +163,32 @@
    fi
 fi
 
+AC_CACHE_CHECK([if this is Windows],
+       ac_win32, [
+       AC_TRY_RUN([
+#ifdef WIN32
+#include <windows.h>
+int main(void)
+{
+  return 0;
+}
+#else
+__wont_compile_
+#endif
+],
+               ac_win32=yes,
+               ac_win32=no,
+               ac_win32=no)
+       ])
+if test "$ac_win32" = "yes"; then
+  AC_SUBST(adns_win32, -DADNS_JGAA_WIN32=1)
+  AC_SUBST(netxx_win32, -DNETXX_NO_INET6=1)
+  AC_SUBST(win32_libs, "-lws2_32 -lintl -liconv.dll -liphlpapi")
+else
+  AC_SUBST(adns_win32, "")
+  AC_SUBST(netxx_win32, "")
+  AC_SUBST(win32_libs, "")
+fi
 
 # simple library checks 
 AC_CHECK_LIB([dl], [dlsym])
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/file_io.cc monotone-win32/file_io.cc
--- monotone-pulled/file_io.cc  Mon Mar 29 17:52:20 2004
+++ monotone-win32/file_io.cc   Mon Mar 29 19:24:40 2004
@@ -27,7 +27,9 @@
 
 #include <stdlib.h>
 #include <unistd.h>
+#ifndef WIN32
 #include <pwd.h>
+#endif
 #include <sys/types.h>
 
 void 
@@ -46,6 +48,12 @@
 string 
 get_homedir()
 {
+#ifdef WIN32
+  char * homedrive = getenv("HOMEDRIVE");
+  char * homepath = getenv("HOMEPATH");
+  N((homedrive!=NULL && homepath!=NULL), F("could not find home directory"));
+  return string(homedrive)+string(homepath);
+#else
   char * home = getenv("HOME");
   if (home != NULL)
     return string(home);
@@ -53,6 +61,7 @@
   struct passwd * pw = getpwuid(getuid());  
   N(pw != NULL, F("could not find home directory for uid %d") % getuid());
   return string(pw->pw_dir);
+#endif
 }
 
 
@@ -94,10 +103,14 @@
        }
       else if (i->size() > 1 && i->at(0) == '~')
        {         
+#ifdef WIN32
+               res /= mkpath(get_homedir());
+#else
          struct passwd * pw;
          pw = getpwnam(i->substr(1).c_str());
          N(pw != NULL, F("could not find home directory user %s") % 
i->substr(1));
          res /= mkpath(string(pw->pw_dir));
+#endif
          ++i;
        }
       while (i != tmp.end())
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/keys.cc monotone-win32/keys.cc
--- monotone-pulled/keys.cc     Mon Mar 29 17:52:20 2004
+++ monotone-win32/keys.cc      Mon Mar 29 19:38:47 2004
@@ -2,7 +2,9 @@
 #include <string>
 #include <map>
 
+#ifndef WIN32
 #include <termios.h>
+#endif
 #include <unistd.h>
 #include <string.h>
 
@@ -84,16 +86,20 @@
       cout << "enter passphrase for key ID [" << keyid() <<  "] : ";
       cout.flush();
       
+#ifndef WIN32      
       int cin_fd = 0;
       struct termios t, t_saved;
       tcgetattr(cin_fd, &t);
       t_saved = t;
       t.c_lflag &= ~ECHO;
       tcsetattr(cin_fd, TCSANOW, &t);
+#endif
 
       try 
        {
+#ifndef WIN32
          tcsetattr(cin_fd, TCSANOW, &t);
+#endif
          cin.getline(buf, bufsz, '\n');
          phrase.Assign(reinterpret_cast<byte const *>(buf), strlen(buf));
 
@@ -106,13 +112,17 @@
       catch (...)
        {
          memset(buf, 0, bufsz);
+#ifndef WIN32
          tcsetattr(cin_fd, TCSANOW, &t_saved);
+#endif
          cout << endl;
          throw;
        }
       cout << endl;
       memset(buf, 0, bufsz);
+#ifndef WIN32
       tcsetattr(cin_fd, TCSANOW, &t_saved);
+#endif
     }
 }  
 
Binary files monotone-pulled/lib3rdparty.a and monotone-win32/lib3rdparty.a 
differ
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/lua/liolib.c monotone-win32/lua/liolib.c
--- monotone-pulled/lua/liolib.c        Mon Mar 29 17:52:20 2004
+++ monotone-win32/lua/liolib.c Mon Mar 29 20:20:27 2004
@@ -215,17 +215,36 @@
   return (*pf == NULL) ? pushresult(L, 0, NULL) : 1;
 }
 
-
 // this function added for monotone
 static int io_mkstemp (lua_State *L) {
   int fd;
   FILE **pf;
   char const *filename = lua_tostring (L, -1);
   char *dup = strdup(filename);
+#ifdef WIN32
+  int sl;
+  static int mkstmpcnt = 0;
+#endif
 
   if (dup == NULL)
     return 0;
 
+#ifdef WIN32
+       sl = strlen(dup);
+       if (sl<6)
+       {
+               free(dup);
+               return 0;
+       }
+       if (strcmp(dup+sl-6,"XXXXXX"))
+       {
+               free(dup);
+               return 0;
+       }
+       sprintf(dup+sl-6,"%06d",mkstmpcnt++);
+       pf = newfile(L);
+       *pf = fopen(dup, "r+");
+#else
   fd = mkstemp(dup);
 
   if (fd == -1)
@@ -236,6 +255,7 @@
 
   pf = newfile(L);
   *pf = fdopen(fd, "r+");  
+#endif
 
   lua_pushstring(L, dup);
   free(dup);
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/network.cc monotone-win32/network.cc
--- monotone-pulled/network.cc  Mon Mar 29 17:52:22 2004
+++ monotone-win32/network.cc   Mon Mar 29 19:59:07 2004
@@ -7,11 +7,22 @@
 // protocols monotone knows how to speak, and the queueing / posting system
 // which interacts with the network via those protocols.
 
+#ifdef WIN32
+#include <winsock.h>
+#define ADNS_JGAA_WIN32 1
+#else
 #include <sys/time.h>
 #include <netdb.h>
 #include <arpa/inet.h>
+#endif
 
 #include <adns.h>
+#if defined(ADNS_JGAA_WIN32) && defined(getpid)
+#undef getpid
+#undef gettimeofday
+#undef writev
+#undef inet_aton
+#endif
 
 #include "Netxx/Netbuf.h"
 #include "Netxx/Stream.h"
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/rcs_file.cc monotone-win32/rcs_file.cc
--- monotone-pulled/rcs_file.cc Mon Mar 29 17:52:22 2004
+++ monotone-win32/rcs_file.cc  Mon Mar 29 19:50:56 2004
@@ -8,7 +8,11 @@
 #include <boost/spirit/attribute.hpp>
 #include <boost/spirit/phoenix/binders.hpp>
 
+#ifndef WIN32
 #include <sys/mman.h>
+#else
+#include <windows.h>
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -199,27 +203,76 @@
 {
   string const & filename;
   off_t length;
+#ifdef WIN32
+  HANDLE fd;
+#else
   int fd;
+#endif
   file_handle(string const & fn) : 
     filename(fn), 
     length(0),
+#ifdef WIN32
+    fd(NULL)
+#else
     fd(-1)
+#endif
     {
       struct stat st;
       if (stat(fn.c_str(), &st) == -1)
        throw oops("stat of " + filename + " failed");
       length = st.st_size;
+#ifdef WIN32
+      fd = 
CreateFile(fn.c_str(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
+      if (fd==NULL)
+#else
       fd = open(filename.c_str(), O_RDONLY);
       if (fd == -1)
+#endif
        throw oops("open of " + filename + " failed");
     }
   ~file_handle() 
     {
+#ifdef WIN32
+      if (CloseHandle(fd)==0)
+#else
       if (close(fd) == -1)
+#endif
        throw oops("close of " + filename + " failed");
     }
 };
 
+#ifdef WIN32
+struct 
+mmapped_handle
+{
+  string const & filename;
+  HANDLE fd,map;
+  off_t length;
+  void * mapping;
+  mmapped_handle(string const & fn,
+                 HANDLE f,
+                 off_t len) :
+    filename(fn),
+    fd(f),
+    length(len),
+    mapping(NULL)
+    {
+      map = CreateFileMapping(fd, NULL, PAGE_READONLY, 0, 0, NULL);
+      if (map==NULL)
+        throw oops("CreateFileMapping of " + filename + " failed");
+      mapping = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, len);
+      if (mapping==NULL)
+        throw oops("MapViewOFFile of " + filename + " failed");
+    }
+    ~mmapped_handle()
+    {
+      if (UnmapViewOfFile(mapping)==0)
+        throw oops("UnmapViewOfFile of " + filename + " failed");
+      if (CloseHandle(map)==0)
+        throw oops("CloseHandle of " + filename + " failed");
+    }
+};
+#else
 struct 
 mmapped_handle
 {
@@ -245,6 +298,7 @@
        throw oops("munmapping " + filename + " failed, after reading RCS 
file");
     }
 };
+#endif
 
 void 
 parse_rcs_file(string const & filename, rcs_file & r)
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/rcs_import.cc monotone-win32/rcs_import.cc
--- monotone-pulled/rcs_import.cc       Mon Mar 29 17:52:22 2004
+++ monotone-win32/rcs_import.cc        Mon Mar 29 19:54:16 2004
@@ -648,8 +648,15 @@
   {    
     struct tm t;
     char const * dp = delta->second->date.c_str();
+#ifdef WIN32
+    if (sscanf(dp, "%d.%d.%d.%d.%d.%d", &(t.tm_year), &(t.tm_mon), 
&(t.tm_mday), &(t.tm_hour), &(t.tm_min), &(t.tm_sec))!=6)
+           I(sscanf(dp, "%d.%d.%d.%d.%d.%d", &(t.tm_year), &(t.tm_mon), 
&(t.tm_mday), &(t.tm_hour), &(t.tm_min), &(t.tm_sec))!=6);
+    t.tm_mon--;
+    t.tm_year-=1900;
+#else
     if (strptime(dp, "%y.%m.%d.%H.%M.%S", &t) == NULL)
       I(strptime(dp, "%Y.%m.%d.%H.%M.%S", &t) != NULL);
+#endif
     time=mktime(&t);
   }
 
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/smtp_tasks.cc monotone-win32/smtp_tasks.cc
--- monotone-pulled/smtp_tasks.cc       Mon Mar 29 17:52:22 2004
+++ monotone-win32/smtp_tasks.cc        Mon Mar 29 20:02:38 2004
@@ -25,7 +25,11 @@
   struct tm local;
 
   I(time(&now) != ((time_t)-1));
+#ifdef WIN32
+  memcpy(&local,localtime(&now),sizeof(local));
+#else
   I(localtime_r (&now, &local) != NULL);
+#endif
   I(strftime(buf, sz, "%a, %d %b %Y %H:%M:%S %z", &local) != 0);
 
   string result(buf);
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/adns.h monotone-win32/adns/adns.h
--- monotone-pulled/adns/adns.h Mon Mar 29 17:52:20 2004
+++ monotone-win32/adns/adns.h  Mon Mar 29 18:54:15 2004
@@ -51,19 +51,30 @@
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
  *
- *  $Id: adns.h,v 1.1 2003/10/31 07:44:54 graydon Exp $
+ *  $Id: adns.h,v 1.83 2000/09/17 01:56:18 ian Exp $
  */
 
 #ifndef ADNS_H_INCLUDED
 #define ADNS_H_INCLUDED
 
-#include <stdio.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <sys/time.h>
-#include <unistd.h>
+#ifdef ADNS_JGAA_WIN32
+# include "adns_win32.h"
+#else
+# include <stdio.h>
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <sys/types.h>
+# include <sys/time.h>
+# include <unistd.h>
+
+# define ADNS_API
+# define ADNS_SOCKET int
+# define adns_socket_close(sck) close(sck)
+# define adns_socket_read(sck, data, len) read(sck, data, len)
+# define adns_socket_write(sck, data, len) write(sck, data, len)
+# define ADNS_CAPTURE_ERRNO {}
+# define ADNS_CLEAR_ERRNO {}
+#endif
 
 #ifdef __cplusplus
 extern "C" { /* I really dislike this - iwj. */
@@ -75,35 +86,35 @@
 typedef struct adns__query *adns_query;
 
 typedef enum {
- 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_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_initflags;
 
 typedef enum {
- 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_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_queryflags;
 
 typedef enum {
- 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__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,
                     
@@ -232,7 +243,7 @@
 
  /* 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_prohibitedcname, /* CNAME found where eg A expected (not if 
_qf_loosecname) */
  adns_s_answerdomaininvalid,
  adns_s_answerdomaintoolong,
  adns_s_invaliddata,
@@ -279,11 +290,10 @@
 } 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;
@@ -301,21 +311,21 @@
 typedef struct {
   adns_status status;
   char *cname; /* always NULL if query was for CNAME records */
-  char *owner; /* only set if req'd in query flags; maybe 0 on error anyway */
+  char *owner; /* only set if requested in query flags, and may be 0 on error 
anyway */
   adns_rrtype type; /* guaranteed to be same as in query */
-  time_t expires;/*abs time.  def only if _s_ok, nxdomain or nodata. NOT TTL!*/
+  time_t expires; /* expiry time, defined 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 strs ends with i=-1, str=0)*/
+    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_inthostaddr *inthostaddr; /* mx */
     adns_rr_intstr *intstr;          /* mx_raw */
     adns_rr_soa *soa;                /* soa, soa_raw */
   } rrs;
@@ -354,10 +364,10 @@
  *  requested.
  */
 
-int adns_init(adns_state *newstate_r, adns_initflags flags,
+ADNS_API int adns_init(adns_state *newstate_r, adns_initflags flags,
              FILE *diagfile /*0=>stderr*/);
 
-int adns_init_strcfg(adns_state *newstate_r, adns_initflags flags,
+ADNS_API int adns_init_strcfg(adns_state *newstate_r, adns_initflags flags,
                     FILE *diagfile /*0=>discard*/, const char *configtext);
 
 /* Configuration:
@@ -460,7 +470,7 @@
  *   line in resolv.conf.
  */
 
-int adns_synchronous(adns_state ads,
+ADNS_API int adns_synchronous(adns_state ads,
                     const char *owner,
                     adns_rrtype type,
                     adns_queryflags flags,
@@ -471,7 +481,7 @@
  * processing functions to actually get things to happen.
  */
 
-int adns_submit(adns_state ads,
+ADNS_API int adns_submit(adns_state ads,
                const char *owner,
                adns_rrtype type,
                adns_queryflags flags,
@@ -480,23 +490,23 @@
 
 /* The owner should be quoted in master file format. */
 
-int adns_check(adns_state ads,
+ADNS_API int adns_check(adns_state ads,
               adns_query *query_io,
               adns_answer **answer_r,
               void **context_r);
 
-int adns_wait(adns_state ads,
+ADNS_API int adns_wait(adns_state ads,
              adns_query *query_io,
              adns_answer **answer_r,
              void **context_r);
 
 /* same as adns_wait but uses poll(2) internally */
-int adns_wait_poll(adns_state ads,
+ADNS_API int adns_wait_poll(adns_state ads,
                   adns_query *query_io,
                   adns_answer **answer_r,
                   void **context_r);
 
-void adns_cancel(adns_query query);
+ADNS_API void adns_cancel(adns_query query);
 
 /* The adns_query you get back from _submit is valid (ie, can be
  * legitimately passed into adns functions) until it is returned by
@@ -510,7 +520,7 @@
  * query type.
  */
 
-int adns_submit_reverse(adns_state ads,
+ADNS_API int adns_submit_reverse(adns_state ads,
                        const struct sockaddr *addr,
                        adns_rrtype type,
                        adns_queryflags flags,
@@ -520,7 +530,7 @@
  * addr->sa_family must be AF_INET or you get ENOSYS.
  */
 
-int adns_submit_reverse_any(adns_state ads,
+ADNS_API int adns_submit_reverse_any(adns_state ads,
                            const struct sockaddr *addr,
                            const char *rzone,
                            adns_rrtype type,
@@ -533,14 +543,14 @@
  * addr->sa_family must be AF_INET or you get ENOSYS.
  */
 
-void adns_finish(adns_state ads);
+ADNS_API void adns_finish(adns_state ads);
 /* You may call this even if you have queries outstanding;
  * they will be cancelled.
  */
 
 
-void adns_forallqueries_begin(adns_state ads);
-adns_query adns_forallqueries_next(adns_state ads, void **context_r);
+ADNS_API void adns_forallqueries_begin(adns_state ads);
+ADNS_API adns_query adns_forallqueries_next(adns_state ads, void **context_r);
 /* Iterator functions, which you can use to loop over the outstanding
  * (submitted but not yet successfuly checked/waited) queries.
  *
@@ -556,7 +566,7 @@
  * context_r may be 0.  *context_r may not be set when _next returns 0.
  */
 
-void adns_checkconsistency(adns_state ads, adns_query qu);
+ADNS_API  void adns_checkconsistency(adns_state ads, adns_query qu);
 /* Checks the consistency of adns's internal data structures.
  * If any error is found, the program will abort().
  * You may pass 0 for qu; if you pass non-null then additional checks
@@ -588,16 +598,16 @@
  * blocking, or you may not have an up-to-date list of it's fds.
  */
 
-int adns_processany(adns_state ads);
+ADNS_API int adns_processany(adns_state ads);
 /* Gives adns flow-of-control for a bit.  This will never block, and
  * can be used with any threading/asynch-io model.  If some error
  * occurred which might cause an event loop to spin then the errno
  * value is returned.
  */
 
-int adns_processreadable(adns_state ads, int fd, const struct timeval *now);
-int adns_processwriteable(adns_state ads, int fd, const struct timeval *now);
-int adns_processexceptional(adns_state ads, int fd, const struct timeval *now);
+ADNS_API int adns_processreadable(adns_state ads, ADNS_SOCKET fd, const struct 
timeval *now);
+ADNS_API int adns_processwriteable(adns_state ads, ADNS_SOCKET fd, const 
struct timeval *now);
+ADNS_API int adns_processexceptional(adns_state ads, ADNS_SOCKET fd, const 
struct timeval *now);
 /* Gives adns flow-of-control so that it can process incoming data
  * from, or send outgoing data via, fd.  Very like _processany.  If it
  * returns zero then fd will no longer be readable or writeable
@@ -616,7 +626,7 @@
  * then the errno value is returned.
  */
 
-void adns_processtimeouts(adns_state ads, const struct timeval *now);
+ADNS_API void adns_processtimeouts(adns_state ads, const struct timeval *now);
 /* Gives adns flow-of-control so that it can process any timeouts
  * which might have happened.  Very like _processreadable/writeable.
  *
@@ -624,7 +634,7 @@
  * obtained from gettimeofday.
  */
 
-void adns_firsttimeout(adns_state ads,
+ADNS_API void adns_firsttimeout(adns_state ads,
                       struct timeval **tv_mod, struct timeval *tv_buf,
                       struct timeval now);
 /* Asks adns when it would first like the opportunity to time
@@ -643,7 +653,7 @@
  * is using.  It always succeeds and never blocks.
  */
 
-void adns_globalsystemfailure(adns_state ads);
+ADNS_API void adns_globalsystemfailure(adns_state ads);
 /* If serious problem(s) happen which globally affect your ability to
  * interact properly with adns, or adns's ability to function
  * properly, you or adns can call this function.
@@ -662,7 +672,7 @@
  * Entrypoints for select-loop based asynch io:
  */
 
-void adns_beforeselect(adns_state ads, int *maxfd, fd_set *readfds,
+ADNS_API void adns_beforeselect(adns_state ads, int *maxfd, fd_set *readfds,
                       fd_set *writefds, fd_set *exceptfds,
                       struct timeval **tv_mod, struct timeval *tv_buf,
                       const struct timeval *now);
@@ -678,7 +688,7 @@
  * finishes in _beforeselect.
  */
 
-void adns_afterselect(adns_state ads, int maxfd, const fd_set *readfds,
+ADNS_API void adns_afterselect(adns_state ads, int maxfd, const fd_set 
*readfds,
                      const fd_set *writefds, const fd_set *exceptfds,
                      const struct timeval *now);
 /* Gives adns flow-of-control for a bit; intended for use after
@@ -712,8 +722,7 @@
  * entrypoints will not be defined in libadns.  Sorry !
  */
 
-int adns_beforepoll(adns_state ads, struct pollfd *fds,
-                   int *nfds_io, int *timeout_io,
+ADNS_API 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
@@ -765,7 +774,7 @@
  * require more space than this.
  */
 
-void adns_afterpoll(adns_state ads, const struct pollfd *fds, int nfds,
+ADNS_API void adns_afterpoll(adns_state ads, const struct pollfd *fds, int 
nfds,
                    const struct timeval *now);
 /* Gives adns flow-of-control for a bit; intended for use after
  * poll(2).  fds and nfds should be the results from poll().  pollfd
@@ -773,7 +782,7 @@
  */
 
 
-adns_status adns_rr_info(adns_rrtype type,
+ADNS_API adns_status adns_rr_info(adns_rrtype type,
                         const char **rrtname_r, const char **fmtname_r,
                         int *len_r,
                         const void *datap, char **data_r);
@@ -833,9 +842,9 @@
  *  dns2.spong.dyn.ml.org timeout "DNS query timed out" ?
  */
 
-const char *adns_strerror(adns_status st);
-const char *adns_errabbrev(adns_status st);
-const char *adns_errtypeabbrev(adns_status st);
+ADNS_API const char *adns_strerror(adns_status st);
+ADNS_API const char *adns_errabbrev(adns_status st);
+ADNS_API const char *adns_errtypeabbrev(adns_status st);
 /* Like strerror but for adns_status values.  adns_errabbrev returns
  * the abbreviation of the error - eg, for adns_s_timeout it returns
  * "timeout".  adns_errtypeabbrev returns the abbreviation of the
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/adns_unix_calls.c 
monotone-win32/adns/adns_unix_calls.c
--- monotone-pulled/adns/adns_unix_calls.c      Thu Jan  1 00:00:00 1970
+++ monotone-win32/adns/adns_unix_calls.c       Mon Mar 29 18:54:15 2004
@@ -0,0 +1,120 @@
+
+/*
+* adns_unix_calls.c
+* - Simple implementation of requiered UNIX system calls and
+*   library functions.
+*/
+/*
+*  This file is
+*    Copyright (C) 2000, 2002 Jarle (jgaa) Aase <address@hidden>
+*
+*  It is part of adns, which is
+*    Copyright (C) 1997-2000 Ian Jackson <address@hidden>
+*    Copyright (C) 1999 Tony Finch <address@hidden>
+*  
+*  This program 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, or (at your option)
+*  any later version.
+*  
+*  This program 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
+*  GNU General Public License for more details.
+*  
+*  You should have received a copy of the GNU General Public License
+*  along with this program; if not, write to the Free Software Foundation,
+*  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+*/
+
+
+#include "adns.h"
+
+#ifdef ADNS_JGAA_WIN32
+
+int adns_writev(int FileDescriptor, const struct iovec * iov, int iovCount)
+{
+       size_t total_len = 0;
+       int bytes_written = 0;
+       int i = 0, r = 0;
+       char *buf = NULL, *p = NULL;
+       
+       for(; i < iovCount; i++)
+               total_len += iov[i].iov_len;
+       
+       p = buf = (char *)alloca(total_len);
+       
+       for(; i < iovCount; i++)
+       {
+               memcpy(p, iov[i].iov_base, iov[i].iov_len);
+               p += iov[i].iov_len;
+       }
+       
+       ADNS_CLEAR_ERRNO
+       r = send(FileDescriptor, buf, total_len, 0);
+       ADNS_CAPTURE_ERRNO;
+       return r;
+}
+
+int adns_inet_aton(const char *cp, struct in_addr *inp)
+{
+       inp->s_addr = inet_addr(cp);
+       return inp->s_addr != INADDR_ANY;
+}
+
+int adns_getpid()
+{
+       return GetCurrentProcessId();
+}
+
+int adns_gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+       static __int64 Adjustment;
+       __int64 Now = 0;
+       
+       if (!Adjustment)
+       {
+               SYSTEMTIME st = {1970,1,3,0,0,0,0};
+               SystemTimeToFileTime(&st, (LPFILETIME)&Adjustment);
+       }
+       
+       if (tz)
+       {
+               errno = EINVAL;
+               return -1;
+       }
+       
+       GetSystemTimeAsFileTime((LPFILETIME)&Now);
+       Now -= Adjustment;
+       
+       tv->tv_sec = (long)(Now / 100000000);
+       tv->tv_usec = (long)((Now / 100) - (((__int64)tv->tv_sec * 1000) * 
100));
+       return 0;
+}
+
+/* Memory allocated in the DLL must be freed in the dll, so
+   we provide memory manegement functions. */
+
+#ifdef ADNS_DLL
+
+#undef malloc
+#undef realloc
+#undef free
+
+void *adns_malloc(const size_t bytes)
+{
+       return malloc(bytes);
+}
+
+void *adns_realloc(void *ptr, const size_t bytes)
+{
+       return realloc(ptr, bytes);
+}
+
+void adns_free(void *ptr)
+{
+       free(ptr);
+}
+
+#endif /* ADNS_DLL */
+#endif
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/adns_win32.h 
monotone-win32/adns/adns_win32.h
--- monotone-pulled/adns/adns_win32.h   Thu Jan  1 00:00:00 1970
+++ monotone-win32/adns/adns_win32.h    Mon Mar 29 18:54:15 2004
@@ -0,0 +1,164 @@
+/*
+ *
+ *  This file is
+ *    Copyright (C) 2000, 2002 Jarle (jgaa) Aase <address@hidden>
+ *
+ *  It is part of adns, which is
+ *    Copyright (C) 1997-2000 Ian Jackson <address@hidden>
+ *    Copyright (C) 1999 Tony Finch <address@hidden>
+ *  
+ *  This program 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, or (at your option)
+ *  any later version.
+ *  
+ *  This program 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
+ *  GNU General Public License for more details.
+ *
+ * 
+ *  For the benefit of certain LGPL'd `omnibus' software which provides
+ *  a uniform interface to various things including adns, I make the
+ *  following additional licence.  I do this because the GPL would
+ *  otherwise force either the omnibus software to be GPL'd or for the
+ *  adns-using part to be distributed separately.
+ *  
+ *  So, you may also redistribute and/or modify adns.h (but only the
+ *  public header file adns.h and not any other part of adns) under the
+ *  terms of the GNU Library General Public License as published by the
+ *  Free Software Foundation; either version 2 of the License, or (at
+ *  your option) any later version.
+ *  
+ *  Note that adns itself is GPL'd.  Authors of adns-using applications
+ *  with GPL-incompatible licences, and people who distribute adns with
+ *  applications where the whole distribution is not GPL'd, are still
+ *  likely to be in violation of the GPL.  Anyone who wants to do this
+ *  should contact Ian Jackson.  Please note that to avoid encouraging
+ *  people to infringe the GPL as it applies the body of adns, Ian thinks
+ *  that if you take advantage of the special exception to redistribute
+ *  just adns.h under the LGPL, you should retain this paragraph in its
+ *  place in the appropriate copyright statements.
+ *
+ *
+ *  You should have received a copy of the GNU General Public License,
+ *  or the GNU Library General Public License, as appropriate, along
+ *  with this program; if not, write to the Free Software Foundation,
+ *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef ADNS_WIN32_H_INCLUDED
+#define ADNS_WIN32_H_INCLUDED
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+#if defined(ADNS_DLL)
+# ifdef ADNS_DLL_EXPORTS
+#   define ADNS_API __declspec(dllexport)
+# else
+#   define ADNS_API __declspec(dllimport)
+# endif /* ADNS_EXPORTS */
+#else
+# define ADNS_API
+#endif /* ADNS_DLL */
+
+#if defined (_MSC_VER)
+#pragma warning(disable:4003)
+#endif /* _MSC_VER */
+
+/* ---------------- START OF C HEADER -------------- */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <Winsock2.h>
+#include <windows.h>
+#include <sys/types.h>
+#include <time.h>
+#include <errno.h>
+#include <assert.h>
+#include <limits.h>
+#include <malloc.h>
+#include <signal.h>
+
+#define HAVE_WINSOCK 1
+//#define PRINTFFORMAT(si,tc)
+#define inline __inline
+
+#define ADNS_SOCKET SOCKET
+#define adns_socket_close(sck) closesocket(sck)
+#define adns_socket_read(sck, data, len) recv(sck, (char *)data, len, 0)
+#define adns_socket_write(sck, data, len) send(sck, (char *)data, len, 0)
+
+/* Win32 does not set errno on Winsock errors(!) 
+ * We have to map the winsock errors to errno manually
+ * in order to support the original UNIX error hadnlig
+ */
+#define ADNS_CAPTURE_ERRNO {errno = WSAGetLastError(); WSASetLastError(errno);}
+#define ADNS_CLEAR_ERRNO {WSASetLastError(errno = 0);}
+
+#define ENOBUFS WSAENOBUFS 
+#define EWOULDBLOCK WSAEWOULDBLOCK
+#define EINPROGRESS WSAEINPROGRESS
+#define EMSGSIZE WSAEMSGSIZE
+#define ENOPROTOOPT WSAENOPROTOOPT
+//#define NONRETURNING
+//#define NONRETURNPRINTFFORMAT(si,tc) 
+
+ /*
+  * UNIX system API for Win32
+  * The following is a quick and dirty implementation of
+  * some UNIX API calls in Win32. 
+  * They are used in the dll, but if your project have
+  * it's own implementation of these system calls, simply
+  * undefine ADNS_MAP_UNIXAPI.
+  */
+
+struct iovec 
+{
+    char  *iov_base;
+    int  iov_len; 
+};
+
+/* 
+ * Undef ADNS_MAP_UNIXAPI in the calling code to use natve calls 
+ */
+
+struct timezone 
+{
+       int tz_minuteswest;
+       int tz_dsttime;
+};
+
+ADNS_API int adns_gettimeofday(struct timeval *tv, struct timezone *tz);
+ADNS_API int adns_writev (int FileDescriptor, const struct iovec * iov, int 
iovCount);
+ADNS_API int adns_inet_aton(const char *cp, struct in_addr *inp);
+ADNS_API int adns_getpid();
+
+#ifdef ADNS_DLL
+ ADNS_API void *adns_malloc(const size_t bytes);
+ ADNS_API void *adns_realloc(void *ptr, const size_t bytes);
+ ADNS_API void adns_free(void *ptr);
+#endif
+
+#define gettimeofday(tv, tz) adns_gettimeofday(tv, tz)
+#define writev(FileDescriptor, iov, iovCount) adns_writev(FileDescriptor, iov, 
iovCount)
+#define inet_aton(ap, inp) adns_inet_aton(ap, inp)
+#define getpid() adns_getpid()
+
+#ifdef ADNS_DLL
+# define malloc(bytes) adns_malloc(bytes)
+# define realloc(ptr, bytes) adns_realloc(ptr, bytes)
+# define free(ptr) adns_free(ptr)
+#endif
+
+/* ---------------- END OF C HEADER -------------- */
+#ifdef __cplusplus 
+}
+#endif /* __cplusplus */
+
+#endif /* ADNS_WIN32_H_INCLUDED */
+
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/check.c monotone-win32/adns/check.c
--- monotone-pulled/adns/check.c        Mon Mar 29 17:52:20 2004
+++ monotone-win32/adns/check.c Mon Mar 29 18:54:15 2004
@@ -31,18 +31,41 @@
   adns__consistency(ads,qu,cc_user);
 }
 
+/* The original macro. Too gnuish for other compilers */
+#if 0
 #define DLIST_CHECK(list, nodevar, part, body)                 \
   if ((list).head) {                                           \
     assert(! (list).head->part back);                          \
-    for ((nodevar)= (list).head;                               \
-        (nodevar);                                             \
-        (nodevar)= (nodevar)->part next) {                     \
+    for ((nodevar)= (list).head; (nodevar); (nodevar)= (nodevar)->part next) { 
\
       assert((nodevar)->part next                              \
             ? (nodevar) == (nodevar)->part next->part back     \
             : (nodevar) == (list).tail);                       \
       body                                                     \
     }                                                          \
   }
+#endif /* 0 */
+
+#define DLIST_CHECK1(list, nodevar, body)                                      
\
+  if ((list).head) {                                                           
\
+    assert(! (list).head->back);                                               
\
+    for ((nodevar)= (list).head; (nodevar); (nodevar)= (nodevar)->next) {      
\
+      assert((nodevar)->next                                           \
+            ? (nodevar) == (nodevar)->next->back                       \
+            : (nodevar) == (list).tail);                                       
\
+      body                                                                     
\
+    }                                                                          
\
+  }
+
+#define DLIST_CHECK2(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 {                                                 \
@@ -56,7 +79,8 @@
 static void checkc_query_alloc(adns_state ads, adns_query qu) {
   allocnode *an;
 
-  DLIST_CHECK(qu->allocations, an, , {
+
+  DLIST_CHECK1(qu->allocations, an, {
   });
 }
 
@@ -109,7 +133,7 @@
 static void checkc_queue_udpw(adns_state ads) {
   adns_query qu;
   
-  DLIST_CHECK(ads->udpw, qu, , {
+  DLIST_CHECK1(ads->udpw, qu, {
     assert(qu->state==query_tosend);
     assert(qu->retries <= UDPMAXRETRIES);
     assert(qu->udpsent);
@@ -122,7 +146,7 @@
 static void checkc_queue_tcpw(adns_state ads) {
   adns_query qu;
   
-  DLIST_CHECK(ads->tcpw, qu, , {
+  DLIST_CHECK1(ads->tcpw, qu, {
     assert(qu->state==query_tcpw);
     assert(!qu->children.head && !qu->children.tail);
     assert(qu->retries <= ads->nservers+1);
@@ -134,10 +158,10 @@
 static void checkc_queue_childw(adns_state ads) {
   adns_query parent, child;
 
-  DLIST_CHECK(ads->childw, parent, , {
+  DLIST_CHECK1(ads->childw, parent, {
     assert(parent->state == query_childw);
     assert(parent->children.head);
-    DLIST_CHECK(parent->children, child, siblings., {
+    DLIST_CHECK2(parent->children, child, siblings, {
       assert(child->parent == parent);
       assert(child->state != query_done);
     });
@@ -149,7 +173,7 @@
 static void checkc_queue_output(adns_state ads) {
   adns_query qu;
   
-  DLIST_CHECK(ads->output, qu, , {
+  DLIST_CHECK1(ads->output, qu, {
     assert(qu->state == query_done);
     assert(!qu->children.head && !qu->children.tail);
     assert(!qu->parent);
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/config.h monotone-win32/adns/config.h
--- monotone-pulled/adns/config.h       Mon Mar 29 17:52:20 2004
+++ monotone-win32/adns/config.h        Mon Mar 29 19:14:44 2004
@@ -36,7 +36,7 @@
 #define inline
 #endif
 
-#ifdef HAVE_POLL
+#if !defined(ADNS_JGAA_WIN32) && defined(HAVE_POLL)
 #include <sys/poll.h>
 #else
 /* kludge it up */
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/dlist.h monotone-win32/adns/dlist.h
--- monotone-pulled/adns/dlist.h        Mon Mar 29 17:52:20 2004
+++ monotone-win32/adns/dlist.h Mon Mar 29 18:54:15 2004
@@ -43,8 +43,7 @@
   do {                                                 \
     (node)->part next= 0;                              \
     (node)->part back= (list).tail;                    \
-    if ((list).tail) (list).tail->part next= (node);   \
-    else (list).head= (node);                          \
+    if ((list).tail) (list).tail->part next= (node); else (list).head= (node); 
\
     (list).tail= (node);                               \
   } while(0)
 
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/event.c monotone-win32/adns/event.c
--- monotone-pulled/adns/event.c        Mon Mar 29 17:52:20 2004
+++ monotone-win32/adns/event.c Mon Mar 29 18:54:15 2004
@@ -23,20 +23,24 @@
  *  GNU General Public License for more details.
  *  
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software Foundation,
+ *  along with this program; if not, adns_socket_write to the Free Software 
Foundation,
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  */
 
 #include <errno.h>
+# include "adns_win32.h"
 #include <stdlib.h>
-#include <unistd.h>
 
-#include <sys/types.h>
-#include <sys/time.h>
-#include <netdb.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#ifdef ADNS_JGAA_WIN32
+#else
+# include <unistd.h>
+# include <sys/types.h>
+# include <sys/time.h>
+# include <netdb.h>
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+#endif
 
 #include "internal.h"
 #include "tvarith.h"
@@ -47,7 +51,7 @@
   int serv;
   
   serv= ads->tcpserver;
-  close(ads->tcpsocket);
+  adns_socket_close(ads->tcpsocket);
   ads->tcpsocket= -1;
   ads->tcprecv.used= ads->tcprecv_skip= ads->tcpsend.used= 0;
 }
@@ -83,23 +87,9 @@
   }
 }
 
-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;
+  int r, tries;
+  ADNS_SOCKET fd;
   struct sockaddr_in addr;
   struct protoent *proto;
 
@@ -120,20 +110,18 @@
     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; }
+       ADNS_CLEAR_ERRNO
     fd= socket(AF_INET,SOCK_STREAM,proto->p_proto);
+       ADNS_CAPTURE_ERRNO;
     if (fd<0) {
       adns__diag(ads,-1,0,"cannot create TCP socket: %s",strerror(errno));
       return;
     }
     r= adns__setnonblock(ads,fd);
     if (r) {
-      adns__diag(ads,-1,0,"cannot make TCP socket nonblocking:"
-                " %s",strerror(r));
-      close(fd);
+      adns__diag(ads,-1,0,"cannot make TCP socket nonblocking: 
%s",strerror(r));
+      adns_socket_close(fd);
       return;
     }
     memset(&addr,0,sizeof(addr));
@@ -150,7 +138,7 @@
       return;
     }
     adns__tcp_broken(ads,"connect",strerror(errno));
-    tcp_broken_events(ads);
+    ads->tcpstate= server_disconnected;
   }
 }
 
@@ -237,11 +225,21 @@
 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; }
-      tcp_broken_events(ads);
+      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;
     case server_disconnected: /* fall through */
       if (!ads->tcpw.head) return;
       if (!act) { inter_immed(tv_io,tvbuf); return; }
@@ -326,8 +324,7 @@
     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();
@@ -336,7 +333,7 @@
   return 2;
 }
 
-int adns_processreadable(adns_state ads, int fd, const struct timeval *now) {
+int adns_processreadable(adns_state ads, ADNS_SOCKET fd, const struct timeval 
*now) {
   int want, dgramlen, r, udpaddrlen, serv, old_skip;
   byte udpbuf[DNS_MAXUDP];
   struct sockaddr_in udpaddr;
@@ -368,15 +365,16 @@
        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);
       if (ads->tcprecv.used == ads->tcprecv.avail) continue;
-      r= read(ads->tcpsocket,
+         ADNS_CLEAR_ERRNO;
+      r= adns_socket_read(ads->tcpsocket,
              ads->tcprecv.buf+ads->tcprecv.used,
              ads->tcprecv.avail-ads->tcprecv.used);
+         ADNS_CAPTURE_ERRNO;
       if (r>0) {
        ads->tcprecv.used+= r;
       } else {
@@ -385,7 +383,7 @@
          if (errno==EINTR) continue;
          if (errno_resources(errno)) { r= errno; goto xit; }
        }
-       adns__tcp_broken(ads,"read",r?strerror(errno):"closed");
+       adns__tcp_broken(ads,"adns_socket_read",r?strerror(errno):"closed");
       }
     } while (ads->tcpstate == server_ok);
     r= 0; goto xit;
@@ -395,8 +393,10 @@
   if (fd == ads->udpsocket) {
     for (;;) {
       udpaddrlen= sizeof(udpaddr);
+         ADNS_CLEAR_ERRNO;
       r= recvfrom(ads->udpsocket,udpbuf,sizeof(udpbuf),0,
                  (struct sockaddr*)&udpaddr,&udpaddrlen);
+         ADNS_CAPTURE_ERRNO;
       if (r<0) {
        if (errno == EAGAIN || errno == EWOULDBLOCK) { r= 0; goto xit; }
        if (errno == EINTR) continue;
@@ -416,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;
@@ -438,7 +438,7 @@
   return r;
 }
 
-int adns_processwriteable(adns_state ads, int fd, const struct timeval *now) {
+int adns_processwriteable(adns_state ads, ADNS_SOCKET fd, const struct timeval 
*now) {
   int r;
   
   adns__consistency(ads,0,cc_entex);
@@ -453,31 +453,35 @@
     assert(ads->tcprecv_skip==0);
     for (;;) {
       if (!adns__vbuf_ensure(&ads->tcprecv,1)) { r= ENOMEM; goto xit; }
-      r= read(ads->tcpsocket,&ads->tcprecv.buf,1);
+         ADNS_CLEAR_ERRNO;
+      r= adns_socket_read(ads->tcpsocket,&ads->tcprecv.buf,1);
+         ADNS_CAPTURE_ERRNO;
       if (r==0 || (r<0 && (errno==EAGAIN || errno==EWOULDBLOCK))) {
        tcp_connected(ads,*now);
        r= 0; goto xit;
       }
       if (r>0) {
-       adns__tcp_broken(ads,"connect/read","sent data before first request");
+       adns__tcp_broken(ads,"connect/adns_socket_read","sent data before first 
request");
        r= 0; goto xit;
       }
       if (errno==EINTR) continue;
       if (errno_resources(errno)) { r= errno; goto xit; }
-      adns__tcp_broken(ads,"connect/read",strerror(errno));
+      adns__tcp_broken(ads,"connect/adns_socket_read",strerror(errno));
       r= 0; goto xit;
     } /* not reached */
   case server_ok:
     if (fd != ads->tcpsocket) break;
     while (ads->tcpsend.used) {
       adns__sigpipe_protect(ads);
-      r= write(ads->tcpsocket,ads->tcpsend.buf,ads->tcpsend.used);
+         ADNS_CLEAR_ERRNO;
+      r= adns_socket_write(ads->tcpsocket,ads->tcpsend.buf,ads->tcpsend.used);
+         ADNS_CAPTURE_ERRNO;
       adns__sigpipe_unprotect(ads);
       if (r<0) {
        if (errno==EINTR) continue;
        if (errno==EAGAIN || errno==EWOULDBLOCK) { r= 0; goto xit; }
        if (errno_resources(errno)) { r= errno; goto xit; }
-       adns__tcp_broken(ads,"write",strerror(errno));
+       adns__tcp_broken(ads,"adns_socket_write",strerror(errno));
        r= 0; goto xit;
       } else if (r>0) {
        ads->tcpsend.used -= r;
@@ -495,8 +499,7 @@
   return r;
 }
   
-int adns_processexceptional(adns_state ads, int fd,
-                           const struct timeval *now) {
+int adns_processexceptional(adns_state ads, ADNS_SOCKET fd, const struct 
timeval *now) {
   adns__consistency(ads,0,cc_entex);
   switch (ads->tcpstate) {
   case server_disconnected:
@@ -514,23 +517,21 @@
   return 0;
 }
 
-static void fd_event(adns_state ads, int fd,
+static void fd_event(adns_state ads, ADNS_SOCKET 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, ADNS_SOCKET fd, const struct 
timeval *now),
                     struct timeval now, int *r_r) {
   int r;
   
   if (!(revent & pollflag)) return;
-  if (fds && !(fd<maxfd && FD_ISSET(fd,fds))) return;
+  if (fds && !((int)fd<maxfd && FD_ISSET(fd,fds))) return;
   r= func(ads,fd,&now);
   if (r) {
     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);
     }
   }
@@ -541,18 +542,16 @@
                    int maxfd, const fd_set *readfds,
                    const fd_set *writefds, const fd_set *exceptfds,
                    struct timeval now, int *r_r) {
-  int i, fd, revents;
+  int i, revents;
+  ADNS_SOCKET fd;
 
   for (i=0; i<npollfds; i++) {
     fd= pollfds[i].fd;
-    if (fd >= maxfd) maxfd= fd+1;
+    if ((int)fd >= maxfd) maxfd= fd+1;
     revents= pollfds[i].revents;
-#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
+    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);
   }
 }
 
@@ -564,7 +563,8 @@
                       const struct timeval *now) {
   struct timeval tv_nowbuf;
   struct pollfd pollfds[MAX_POLLFDS];
-  int i, fd, maxfd, npollfds;
+  int i, maxfd, npollfds;
+  ADNS_SOCKET fd;
   
   adns__consistency(ads,0,cc_entex);
 
@@ -579,7 +579,7 @@
   maxfd= *maxfd_io;
   for (i=0; i<npollfds; i++) {
     fd= pollfds[i].fd;
-    if (fd >= maxfd) maxfd= fd+1;
+    if ((int)fd >= maxfd) maxfd= fd+1;
     if (pollfds[i].events & POLLIN) FD_SET(fd,readfds_io);
     if (pollfds[i].events & POLLOUT) FD_SET(fd,writefds_io);
     if (pollfds[i].events & POLLPRI) FD_SET(fd,exceptfds_io);
@@ -647,7 +647,7 @@
 
   /* We just use adns__fdevents to loop over the fd's trying them.
    * This seems more sensible than calling select, since we're most
-   * likely just to want to do a read on one or two fds anyway.
+   * likely just to want to do a adns_socket_read on one or two fds anyway.
    */
   npollfds= adns__pollfds(ads,pollfds);
   for (i=0; i<npollfds; i++) pollfds[i].revents= pollfds[i].events & ~POLLPRI;
@@ -707,7 +707,9 @@
     FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds);
     adns_beforeselect(ads,&maxfd,&readfds,&writefds,&exceptfds,&tvp,&tvbuf,0);
     assert(tvp);
+       ADNS_CLEAR_ERRNO;
     rsel= select(maxfd,&readfds,&writefds,&exceptfds,tvp);
+       ADNS_CAPTURE_ERRNO;
     if (rsel==-1) {
       if (errno == EINTR) {
        if (ads->iflags & adns_if_eintr) { r= EINTR; break; }
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/general.c monotone-win32/adns/general.c
--- monotone-pulled/adns/general.c      Mon Mar 29 17:52:20 2004
+++ monotone-win32/adns/general.c       Mon Mar 29 18:54:15 2004
@@ -27,12 +27,16 @@
  */
 
 #include <stdlib.h>
-#include <unistd.h>
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#ifdef ADNS_JGAA_WIN32
+# include "adns_win32.h"
+#else
+# include <unistd.h>
+# include <sys/types.h>
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+#endif
 
 #include "internal.h"
 
@@ -44,8 +48,7 @@
   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) {
@@ -80,8 +83,7 @@
   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);
@@ -89,18 +91,15 @@
   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);
@@ -161,12 +160,10 @@
 /* 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>";
   }
@@ -207,7 +204,7 @@
   st= typei->convstring(&vb,datap);
   if (st) goto x_freevb;
   if (!adns__vbuf_append(&vb,"",1)) { st= adns_s_nomemory; goto x_freevb; }
-  assert(strlen(vb.buf) == vb.used-1);
+  assert((int)strlen(vb.buf) == vb.used-1);
   *data_r= realloc(vb.buf,vb.used);
   if (!*data_r) *data_r= vb.buf;
   return adns_s_ok;
@@ -265,8 +262,7 @@
 }
 
 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) {
@@ -315,8 +311,7 @@
 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;
 }
 
@@ -340,8 +335,10 @@
 }
 
 /* SIGPIPE protection. */
+/* Not required under Win32 with MSVC */
 
 void adns__sigpipe_protect(adns_state ads) {
+#ifndef ADNS_JGAA_WIN32
   sigset_t toblock;
   struct sigaction sa;
   int r;
@@ -357,13 +354,16 @@
   
   r= sigprocmask(SIG_SETMASK,&toblock,&ads->stdsigmask); assert(!r);
   r= sigaction(SIGPIPE,&sa,&ads->stdsigpipe); assert(!r);
+#endif
 }
 
 void adns__sigpipe_unprotect(adns_state ads) {
+#ifndef ADNS_JGAA_WIN32
   int r;
 
   if (ads->iflags & adns_if_nosigpipe) return;
 
   r= sigaction(SIGPIPE,&ads->stdsigpipe,0); assert(!r);
   r= sigprocmask(SIG_SETMASK,&ads->stdsigmask,0); assert(!r);
+#endif
 }
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/internal.h monotone-win32/adns/internal.h
--- monotone-pulled/adns/internal.h     Mon Mar 29 17:52:20 2004
+++ monotone-win32/adns/internal.h      Mon Mar 29 18:54:15 2004
@@ -35,13 +35,17 @@
 
 #include <stdarg.h>
 #include <assert.h>
-#include <unistd.h>
+
+#ifndef ADNS_JGAA_WIN32
+# include <unistd.h>
+#endif
 #include <signal.h>
 #include <errno.h>
 #include <string.h>
-#include <stdlib.h>
 
-#include <sys/time.h>
+#ifndef ADNS_JGAA_WIN32
+#  include <sys/time.h>
+#endif
 
 #include "adns.h"
 #include "dlist.h"
@@ -130,8 +134,7 @@
    * 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.
    *
@@ -143,7 +146,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.
    */
@@ -287,7 +290,8 @@
   int configerrno;
   struct query_queue udpw, tcpw, childw, output;
   adns_query forallnext;
-  int nextid, udpsocket, tcpsocket;
+  int nextid;
+  ADNS_SOCKET udpsocket, tcpsocket;
   vbuf tcpsend, tcprecv;
   int nservers, nsortlist, nsearchlist, searchndots, tcpserver, tcprecv_skip;
   enum adns__tcpstate {
@@ -300,8 +304,10 @@
    * we are idle (ie, tcpw queue is empty), in which case it is the
    * absolute time when we will close the connection.
    */
+#ifndef ADNS_JGAA_WIN32
   struct sigaction stdsigpipe;
   sigset_t stdsigmask;
+#endif
   struct pollfd pollfds_buf[MAX_POLLFDS];
   struct server {
     struct in_addr addr;
@@ -314,7 +320,7 @@
 
 /* From setup.c: */
 
-int adns__setnonblock(adns_state ads, int fd); /* => errno value */
+int adns__setnonblock(adns_state ads, ADNS_SOCKET fd); /* => errno value */
 
 /* From general.c: */
 
@@ -329,7 +335,7 @@
                const char *fmt, ...) PRINTFFORMAT(4,5);
 
 int adns__vbuf_ensure(vbuf *vb, int want);
-int adns__vbuf_appendstr(vbuf *vb, const char *data); /* doesn't include nul */
+int adns__vbuf_appendstr(vbuf *vb, const char *data); /* does not 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);
@@ -337,8 +343,7 @@
 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.
@@ -377,8 +382,7 @@
  */
 
 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.
@@ -393,8 +397,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.
@@ -403,8 +407,7 @@
 /* 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).
@@ -465,8 +468,7 @@
  *  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
@@ -543,8 +545,7 @@
  * 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
@@ -575,8 +576,7 @@
 
 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.
@@ -586,8 +586,7 @@
  */
 
 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
@@ -626,11 +625,10 @@
 
 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.
  *
@@ -645,8 +643,7 @@
  * 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.
  */
@@ -693,16 +690,12 @@
 
 /* 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);
 }
@@ -717,7 +710,7 @@
 
 #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_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),       \
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/parse.c monotone-win32/adns/parse.c
--- monotone-pulled/adns/parse.c        Mon Mar 29 17:52:20 2004
+++ monotone-win32/adns/parse.c Mon Mar 29 18:54:15 2004
@@ -25,6 +25,10 @@
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  */
 
+#ifdef ADNS_JGAA_WIN32
+# include "adns_win32.h"
+#endif
+
 #include "internal.h"
 
 int vbuf__append_quoted1035(vbuf *vb, const byte *buf, int len) {
@@ -43,8 +47,7 @@
        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;
@@ -107,26 +110,22 @@
   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;
@@ -147,8 +146,7 @@
        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))
@@ -164,11 +162,10 @@
        
 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;
   
@@ -182,8 +179,7 @@
 
   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;
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/poll.c monotone-win32/adns/poll.c
--- monotone-pulled/adns/poll.c Mon Mar 29 17:52:20 2004
+++ monotone-win32/adns/poll.c  Mon Mar 29 18:54:15 2004
@@ -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];
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/query.c monotone-win32/adns/query.c
--- monotone-pulled/adns/query.c        Mon Mar 29 17:52:20 2004
+++ monotone-win32/adns/query.c Mon Mar 29 18:54:15 2004
@@ -27,13 +27,14 @@
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  */
 
-#include "internal.h"
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <sys/time.h>
+#ifdef ADNS_JGAA_WIN32
+# include "adns_win32.h"
+#else
+# include <stdlib.h>
+# include <unistd.h>
+# include <errno.h>
+# include <sys/time.h>
+#endif
 
 #include "internal.h"
 
@@ -43,8 +44,7 @@
   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;
@@ -109,8 +109,7 @@
 }
 
 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;
@@ -159,8 +158,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;
@@ -173,19 +172,17 @@
   qu->search_vb.used= qu->search_origlen;
   if (nextentry) {
     if (!adns__vbuf_append(&qu->search_vb,".",1) ||
-       !adns__vbuf_appendstr(&qu->search_vb,nextentry))
-      goto x_nomemory;
+       !adns__vbuf_appendstr(&qu->search_vb,nextentry)) {
+      stat= adns_s_nomemory; goto x_fail;
+    }
   }
 
   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);
 }
@@ -194,8 +191,6 @@
   /* 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);
 
@@ -288,8 +283,7 @@
   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)) {
@@ -314,8 +308,7 @@
                        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,
@@ -370,8 +363,7 @@
   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;
@@ -463,8 +455,7 @@
   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);
@@ -480,8 +471,7 @@
   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;
   }
@@ -519,7 +509,8 @@
   qu->id= -1;
   ans= qu->answer;
 
-  if (qu->flags & adns_qf_search && ans->status != adns_s_nomemory) {
+  if (qu->flags & adns_qf_owner && 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;
@@ -533,8 +524,7 @@
     }
     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);
   }
 
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/reply.c monotone-win32/adns/reply.c
--- monotone-pulled/adns/reply.c        Mon Mar 29 17:52:20 2004
+++ monotone-win32/adns/reply.c Mon Mar 29 18:54:15 2004
@@ -25,6 +25,10 @@
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  */
 
+#ifdef ADNS_JGAA_WIN32
+# include "adns_win32.h"
+#endif
+
 #include <stdlib.h>
 
 #include "internal.h"
@@ -47,8 +51,7 @@
   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;
@@ -75,8 +78,7 @@
     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;
   }
 
@@ -116,8 +118,7 @@
   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:
@@ -142,20 +143,18 @@
     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;
@@ -174,15 +173,14 @@
     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;
     }
@@ -192,31 +190,25 @@
        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);
@@ -233,8 +225,7 @@
     } 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);
     }
   }
 
@@ -246,11 +237,9 @@
   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;
@@ -260,8 +249,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; }
@@ -272,7 +261,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 && !qu->cname_dgram) {
+      if (qu->flags & adns_qf_search) {
        adns__search_next(ads,qu,now);
       } else {
        adns__query_fail(qu,adns_s_nxdomain);
@@ -296,16 +285,13 @@
 
     /* 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;
@@ -314,10 +300,7 @@
   /* 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;
@@ -372,7 +355,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; }
     
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/setup.c monotone-win32/adns/setup.c
--- monotone-pulled/adns/setup.c        Mon Mar 29 17:52:20 2004
+++ monotone-win32/adns/setup.c Mon Mar 29 18:54:15 2004
@@ -26,17 +26,20 @@
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  */
 
-#include <stdlib.h>
-#include <errno.h>
-#include <limits.h>
-#include <unistd.h>
-#include <fcntl.h>
-
-#include <sys/types.h>
-#include <netdb.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#ifdef ADNS_JGAA_WIN32
+# include "adns_win32.h"
+# include <iphlpapi.h>
+#else
+# include <stdlib.h>
+# include <errno.h>
+# include <limits.h>
+# include <unistd.h>
+# include <fcntl.h>
+# include <netdb.h>
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+#endif
 
 #include "internal.h"
 
@@ -104,8 +107,7 @@
   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)) {
@@ -116,8 +118,7 @@
   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;
@@ -129,11 +130,8 @@
   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;
@@ -149,8 +147,7 @@
   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;
@@ -162,8 +159,7 @@
   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;
     }
 
@@ -188,8 +184,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 {
@@ -209,8 +205,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;
       }
@@ -222,8 +218,7 @@
   }
 }
 
-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;
@@ -239,8 +234,7 @@
     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;
@@ -265,13 +259,11 @@
   }
 }
 
-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;
@@ -279,35 +271,6 @@
   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);
@@ -319,7 +282,6 @@
   { "options",           ccf_options     },
   { "clearnameservers",  ccf_clearnss    },
   { "include",           ccf_include     },
-  { "lookup",            ccf_lookup      }, /* OpenBSD */
   {  0                                   }
 };
 
@@ -352,8 +314,7 @@
     } 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;
@@ -421,8 +382,7 @@
     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 && !((int)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'",
@@ -439,8 +399,7 @@
 
   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;
 }
 
@@ -451,8 +410,7 @@
   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);
@@ -466,8 +424,7 @@
   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;
@@ -497,19 +454,29 @@
 }
 
 
-int adns__setnonblock(adns_state ads, int fd) {
+int adns__setnonblock(adns_state ads, ADNS_SOCKET fd) {
+#ifdef ADNS_JGAA_WIN32
+   unsigned long Val = 1;
+   return (ioctlsocket (fd, FIONBIO, &Val) == 0) ? 0 : -1;
+#else
   int r;
   
   r= fcntl(fd,F_GETFL,0); if (r<0) return errno;
   r |= O_NONBLOCK;
   r= fcntl(fd,F_SETFL,r); if (r<0) return errno;
   return 0;
+#endif
 }
 
-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;
   
+#ifdef ADNS_JGAA_WIN32  
+  WORD wVersionRequested = MAKEWORD( 2, 0 );
+  WSADATA wsaData;
+  int err;
+#endif
+    
   ads= malloc(sizeof(*ads)); if (!ads) return errno;
 
   ads->iflags= flags;
@@ -531,7 +498,25 @@
   timerclear(&ads->tcptimeout);
   ads->searchlist= 0;
 
+ #ifdef ADNS_JGAA_WIN32 
+  err= WSAStartup( wVersionRequested, &wsaData );
+  if ( err != 0 ) {
+    if (ads->diagfile && ads->iflags & adns_if_debug)
+      fprintf(ads->diagfile,"adns: WSAStartup() failed. \n");
+    return -1;}
+  if (LOBYTE( wsaData.wVersion ) != 2 ||
+    HIBYTE( wsaData.wVersion ) != 0 ) {
+    if (ads->diagfile && ads->iflags & adns_if_debug)
+      fprintf(ads->diagfile,"adns: Need Winsock 2.0 or better!\n");
+    
+    WSACleanup();
+    return -1;}
+  
+  /* The WinSock DLL is acceptable. Proceed. */
+#endif
+
   *ads_r= ads;
+
   return 0;
 }
 
@@ -548,18 +533,22 @@
   }
 
   proto= getprotobyname("udp"); if (!proto) { r= ENOPROTOOPT; goto x_free; }
+  ADNS_CLEAR_ERRNO;
   ads->udpsocket= socket(AF_INET,SOCK_DGRAM,proto->p_proto);
+  ADNS_CAPTURE_ERRNO;
   if (ads->udpsocket<0) { r= errno; goto x_free; }
 
   r= adns__setnonblock(ads,ads->udpsocket);
   if (r) { r= errno; goto x_closeudp; }
-  
   return 0;
 
  x_closeudp:
-  close(ads->udpsocket);
+  adns_socket_close(ads->udpsocket);
  x_free:
   free(ads);
+#ifdef ADNS_JGAA_WIN32
+  WSACleanup();
+#endif /* WIN32 */
   return r;
 }
 
@@ -569,12 +558,27 @@
     free(ads->searchlist);
   }
   free(ads);
+#ifdef ADNS_JGAA_WIN32
+  WSACleanup();
+#endif /* WIN32 */
+
 }
 
 int adns_init(adns_state *ads_r, adns_initflags flags, FILE *diagfile) {
   adns_state ads;
   const char *res_options, *adns_res_options;
   int r;
+#ifdef ADNS_JGAA_WIN32
+  #define SECURE_PATH_LEN (MAX_PATH - 64)
+  char PathBuf[MAX_PATH];
+  struct in_addr addr;
+  #define ADNS_PFIXED_INFO_BLEN (2048)
+  PFIXED_INFO network_info = (PFIXED_INFO)alloca(ADNS_PFIXED_INFO_BLEN);
+  ULONG network_info_blen = ADNS_PFIXED_INFO_BLEN;
+  DWORD network_info_result;
+  PIP_ADDR_STRING pip;
+  const char *network_err_str = "";
+#endif
   
   r= init_begin(&ads, flags, diagfile ? diagfile : stderr);
   if (r) return r;
@@ -584,8 +588,41 @@
   ccf_options(ads,"RES_OPTIONS",-1,res_options);
   ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options);
 
+#ifdef ADNS_JGAA_WIN32
+  GetWindowsDirectory(PathBuf, SECURE_PATH_LEN);
+  strcat(PathBuf,"\\resolv.conf");
+  readconfig(ads,PathBuf,1);
+  GetWindowsDirectory(PathBuf, SECURE_PATH_LEN);
+  strcat(PathBuf,"\\resolv-adns.conf");
+  readconfig(ads,PathBuf,0);
+  GetWindowsDirectory(PathBuf, SECURE_PATH_LEN);
+  strcat(PathBuf,"\\System32\\Drivers\\etc\\resolv.conf");
+  readconfig(ads,PathBuf,1);
+  GetWindowsDirectory(PathBuf, SECURE_PATH_LEN);
+  strcat(PathBuf,"\\System32\\Drivers\\etc\\resolv-adns.conf");
+  readconfig(ads,PathBuf,0);
+  network_info_result = GetNetworkParams(network_info, &network_info_blen);
+  if (network_info_result != ERROR_SUCCESS){
+    switch(network_info_result) {
+    case ERROR_BUFFER_OVERFLOW: network_err_str = "ERROR_BUFFER_OVERFLOW"; 
break;
+    case ERROR_INVALID_PARAMETER: network_err_str = "ERROR_INVALID_PARAMETER"; 
break;
+    case ERROR_NO_DATA: network_err_str = "ERROR_NO_DATA"; break;
+    case ERROR_NOT_SUPPORTED: network_err_str = "ERROR_NOT_SUPPORTED"; break;}
+    adns__diag(ads,-1,0,"GetNetworkParams() failed with error [%d] %s",
+      network_info_result,network_err_str);
+    }
+  else {
+    for(pip = &(network_info->DnsServerList); pip; pip = pip->Next) {
+      addr.s_addr = inet_addr(pip->IpAddress.String);
+      if ((addr.s_addr != INADDR_ANY) && (addr.s_addr != INADDR_NONE))
+        addserver(ads, addr); 
+    }
+  }
+#else
   readconfig(ads,"/etc/resolv.conf",1);
   readconfig(ads,"/etc/resolv-adns.conf",0);
+#endif
+
   readconfigenv(ads,"RES_CONF");
   readconfigenv(ads,"ADNS_RES_CONF");
 
@@ -642,12 +679,16 @@
     else if (ads->output.head) adns_cancel(ads->output.head);
     else break;
   }
-  close(ads->udpsocket);
-  if (ads->tcpsocket >= 0) close(ads->tcpsocket);
+  adns_socket_close(ads->udpsocket);
+  if (ads->tcpsocket >= 0) adns_socket_close(ads->tcpsocket);
   adns__vbuf_free(&ads->tcpsend);
   adns__vbuf_free(&ads->tcprecv);
   freesearchlist(ads);
   free(ads);
+#ifdef ADNS_JGAA_WIN32
+  WSACleanup();
+#endif /* WIN32 */
+
 }
 
 void adns_forallqueries_begin(adns_state ads) {
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/transmit.c monotone-win32/adns/transmit.c
--- monotone-pulled/adns/transmit.c     Mon Mar 29 17:52:20 2004
+++ monotone-win32/adns/transmit.c      Mon Mar 29 18:54:15 2004
@@ -28,8 +28,12 @@
 
 #include <errno.h>
 
-#include <sys/types.h>
-#include <sys/uio.h>
+#ifdef ADNS_JGAA_WIN32
+# include "adns_win32.h"
+#else
+# include <sys/types.h>
+# include <sys/uio.h>
+#endif
 
 #include "internal.h"
 #include "tvarith.h"
@@ -39,8 +43,7 @@
 #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;
   
@@ -96,9 +99,7 @@
        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;
-           c += (*p++ - '0')*10;
-           c += (*p++ - '0');
+           c= (*p++ - '0')*100 + (*p++ - '0')*10 + (*p++ - '0');
            if (c >= 256) return adns_s_querydomaininvalid;
          } else {
            return adns_s_querydomaininvalid;
@@ -134,8 +135,7 @@
 }
 
 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;
@@ -178,8 +178,7 @@
   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++;
 
@@ -213,8 +212,7 @@
     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);
   }
 }
 
@@ -251,15 +249,12 @@
   servaddr.sin_addr= ads->servers[serv].addr;
   servaddr.sin_port= htons(DNS_PORT);
   
+  ADNS_CLEAR_ERRNO;
   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));
+  ADNS_CAPTURE_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 
(%d)",strerror(errno), errno);
   
   qu->timeout= now;
   timevaladd(&qu->timeout,UDPRETRYMS);
diff -urbN -x *.o -x aclocal* -x #* -x *.Po -x Makefile -x *.orig -x *.rej -x 
*~ -x Makefile.in monotone-pulled/adns/types.c monotone-win32/adns/types.c
--- monotone-pulled/adns/types.c        Mon Mar 29 17:52:20 2004
+++ monotone-win32/adns/types.c Mon Mar 29 18:54:15 2004
@@ -25,19 +25,20 @@
  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  */
 
-#include <stdlib.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#ifdef ADNS_JGAA_WIN32
+# include "adns_win32.h"
+#else
+# include <stdlib.h>
+# include <sys/types.h>
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+#endif
 
 #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 CSP_ADDSTR(s)     do { if (!adns__vbuf_appendstr(vb,(s))) R_NOMEM; } 
while (0)
 
 /*
  * order of sections:
@@ -174,8 +175,7 @@
  * _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;
@@ -238,8 +238,7 @@
  * _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;
@@ -252,8 +251,7 @@
   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;
 }
@@ -268,8 +266,7 @@
   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);
@@ -288,8 +285,7 @@
  * _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;
 
@@ -374,8 +370,7 @@
   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;
 
@@ -390,8 +385,7 @@
  * _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;
 
@@ -415,8 +409,7 @@
   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;
@@ -426,8 +419,7 @@
     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));
@@ -457,8 +449,7 @@
   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);
@@ -518,8 +509,7 @@
   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;
 
@@ -530,8 +520,7 @@
   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;
 
@@ -542,8 +531,7 @@
                    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);
@@ -607,8 +595,7 @@
  * _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;
@@ -637,8 +624,7 @@
  * _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;
@@ -730,8 +716,7 @@
   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;
@@ -759,18 +744,15 @@
     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]= (unsigned char)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);
@@ -827,8 +809,7 @@
  * _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;
@@ -847,8 +828,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;
@@ -920,8 +901,7 @@
  * _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;
 
@@ -950,8 +930,7 @@
  * _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;
@@ -1016,28 +995,28 @@
 #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     ),
+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         ),
+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(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(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         ),

reply via email to

[Prev in Thread] Current Thread [Next in Thread]