Only in m:\bind: WINNTPORT
Only in m:\bind: bind-4.9.3-BETA26.tar.gz
Only in m:\bind: bind-4.9.3-BETA27.tar.gz
Only in m:\bind: bind-4.9.3-BETA29.tar.gz
Only in m:\bind: bind-4.9.3-BETA30.tar.gz
Only in m:\bind: bind-4.9.3-BETA31.tar.gz
Only in m:\bind: bind-4.9.3-BETA32.tar.gz
Only in m:\bind: buildallnt.bat
diff --context --recurs m:\bindb32/compat/include/sys/cdefs.h m:\bind/compat/include/sys/cdefs.h
*** m:\bindb32/compat/include/sys/cdefs.h	Mon Dec 25 21:59:26 1995
--- m:\bind/compat/include/sys/cdefs.h	Mon Dec 25 22:04:39 1995
***************
*** 97,121 ****
  #define	__CONCAT(x,y)	x/**/y
  #define	__STRING(x)	"x"
  
! #ifndef __GNUC__
! #define	__const				/* delete pseudo-ANSI C keywords */
! #define	__inline
! #define	__signed
! #define	__volatile
! /*
!  * In non-ANSI C environments, new programs will want ANSI-only C keywords
!  * deleted from the program and old programs will want them left alone.
!  * When using a compiler other than gcc, programs using the ANSI C keywords
!  * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
   * When using "gcc -traditional", we assume that this is the intent; if
   * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
   */
! #ifndef	NO_ANSI_KEYWORDS
  #define	const				/* delete ANSI C keywords */
  #define	inline
  #define	signed
  #define	volatile
! #endif
  #endif	/* !__GNUC__ */
  #endif	/* !(__STDC__ || __cplusplus) */
  
--- 97,123 ----
  #define	__CONCAT(x,y)	x/**/y
  #define	__STRING(x)	"x"
  
! #ifndef WINNT
! #ifndef __GNUC__
! #define	__const				/* delete pseudo-ANSI C keywords */
! #define	__inline
! #define	__signed
! #define	__volatile
! #endif
! /*
!  * In non-ANSI C environments, new programs will want ANSI-only C keywords
!  * deleted from the program and old programs will want them left alone.
!  * When using a compiler other than gcc, programs using the ANSI C keywords
!  * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
   * When using "gcc -traditional", we assume that this is the intent; if
   * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
   */
! #ifndef NO_ANSI_KEYWORDS
  #define	const				/* delete ANSI C keywords */
  #define	inline
  #define	signed
  #define	volatile
! #endif /* WINNT */
  #endif	/* !__GNUC__ */
  #endif	/* !(__STDC__ || __cplusplus) */
  
Only in m:\bind/compat/lib: MSG00001.bin
Only in m:\bind/compat/lib: WinRel
diff --context --recurs m:\bindb32/compat/lib/ftruncate.c m:\bind/compat/lib/ftruncate.c
*** m:\bindb32/compat/lib/ftruncate.c	Mon Dec 25 21:59:26 1995
--- m:\bind/compat/lib/ftruncate.c	Mon Dec 25 22:04:39 1995
***************
*** 41,56 ****
  		}
  		return (0);
  	}
! 
! 	/* maybe shorten... */
! 	if (wantsize < cursize) {
! 		struct flock fl;
! 
! 		fl.l_whence = 0;
! 		fl.l_len = 0;
! 		fl.l_start = wantsize;
! 		fl.l_type = F_WRLCK;
! 		return (fcntl(fd, F_FREESP, &fl));
  	}
  	return (0);
  }
--- 41,59 ----
  		}
  		return (0);
  	}
! 	/* maybe shorten... */
! 	if (wantsize < cursize) {
! #ifndef WINNT
! 		struct flock fl;
! 
! 		fl.l_whence = 0;
! 		fl.l_len = 0;
! 		fl.l_start = wantsize;
! 		fl.l_type = F_WRLCK;
! 		return (fcntl(fd, F_FREESP, &fl));
! #else
! 		return (lseek(fd, wantsize, 0) && SetEndOfFile((HANDLE)fd));
! #endif
  	}
  	return (0);
  }
diff --context --recurs m:\bindb32/compat/lib/gettimeofday.c m:\bind/compat/lib/gettimeofday.c
*** m:\bindb32/compat/lib/gettimeofday.c	Mon Dec 25 21:59:26 1995
--- m:\bind/compat/lib/gettimeofday.c	Mon Dec 25 22:04:41 1995
***************
*** 12,29 ****
  	struct timeval *tvp;
  	struct _TIMEZONE *tzp;
  {
! 	time_t clock, time __P((time_t *));
! 
! 	if (time(&clock) == (time_t) -1)
! 		return (-1);
! 	if (tvp) {
! 		tvp->tv_sec = clock;
! 		tvp->tv_usec = 0;
  	}
! 	if (tzp) {
! 		tzp->tz_minuteswest = 0;
  		tzp->tz_dsttime = 0;
  	}
  	return (0);
  }
  
--- 12,36 ----
  	struct timeval *tvp;
  	struct _TIMEZONE *tzp;
  {
! #ifndef WINNT
! 	time_t clock, time __P((time_t *));
! 
! 	if (time(&clock) == (time_t) -1)
! 		return (-1);
! 	if (tvp) {
! 		tvp->tv_sec = clock;
! 		tvp->tv_usec = 0;
  	}
! 	if (tzp) {
! 		tzp->tz_minuteswest = 0;
  		tzp->tz_dsttime = 0;
  	}
+ #else
+ 	struct _timeb timebuffer;
+ 	_ftime(&timebuffer);
+ 	tvp->tv_sec = (long) timebuffer.time;
+ 	tvp->tv_usec = (long) (1000 * (timebuffer.millitm));
+ #endif
  	return (0);
  }
  
Only in m:\bind/compat/lib: lib44bsd.mak
Only in m:\bind/compat/lib: lib44bsd.mdp
Only in m:\bind/compat/lib: lib44bsd.ncb
Only in m:\bind/compat/lib: lib44bsd.vcp
Only in m:\bind/compat/lib: log.c
Only in m:\bind/compat/lib: log.h
Only in m:\bind/compat/lib: makemc.bat
Only in m:\bind/compat/lib: messages.aps
Only in m:\bind/compat/lib: messages.h
Only in m:\bind/compat/lib: messages.mc
Only in m:\bind/compat/lib: messages.rc
diff --context --recurs m:\bindb32/compat/lib/mktemp.c m:\bind/compat/lib/mktemp.c
*** m:\bindb32/compat/lib/mktemp.c	Mon Dec 25 21:59:26 1995
--- m:\bind/compat/lib/mktemp.c	Mon Dec 25 22:04:45 1995
***************
*** 98,113 ****
  	char *path;
  	register int *doopen;
  {
! 	extern int errno;
! 	register char *start, *trv;
! 	struct stat sbuf;
! 	u_int pid;
  
! 	pid = getpid();
! 	for (trv = path; *trv; ++trv);		/* extra X's get set to 0's */
! 	while (*--trv == 'X') {
! 		*trv = (pid % 10) + '0';
! 		pid /= 10;
  	}
  
  	/*
--- 98,115 ----
  	char *path;
  	register int *doopen;
  {
! #ifndef WINNT
! 	extern int errno;
! #endif
! 	register char *start, *trv;
! 	struct stat sbuf;
! 	u_int pid;
  
! 	pid = getpid();
! 	for (trv = path; *trv; ++trv);		/* extra X's get set to 0's */
! 	while (*--trv == 'X') {
! 		*trv = (pid % 10) + '0';
! 		pid /= 10;
  	}
  
  	/*
***************
*** 122,128 ****
--- 124,134 ----
  			if (stat(path, &sbuf))
  				return(0);
  			if (!S_ISDIR(sbuf.st_mode)) {
+ #ifndef WINNT
  				errno = ENOTDIR;
+ #else
+ 				WSASetLastError(ENOTDIR);
+ #endif
  				return(0);
  			}
  			*trv = '/';
Only in m:\bind/compat/lib: ntmisc.c
diff --context --recurs m:\bindb32/compat/lib/strcasecmp.c m:\bind/compat/lib/strcasecmp.c
*** m:\bindb32/compat/lib/strcasecmp.c	Mon Dec 25 21:59:26 1995
--- m:\bind/compat/lib/strcasecmp.c	Mon Dec 25 22:04:47 1995
***************
*** 58,73 ****
  static char rcsid[] = "$Id: strcasecmp.c,v 8.2 1995/04/17 06:38:14 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <sys/types.h>
! #include <sys/cdefs.h>
! #if (!defined(BSD)) || (BSD < 199306)
! #include "../../conf/portability.h"
  #else
! #include <string.h>
! #endif
  
! #ifndef NEED_STRCASECMP
  int __strcasecmp_unneeded__;
  #else
  
--- 58,75 ----
  static char rcsid[] = "$Id: strcasecmp.c,v 8.2 1995/04/17 06:38:14 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/types.h>
! #include <sys/cdefs.h>
! #endif
! #if (!defined(BSD)) || (BSD < 199306)
! #include "../../conf/portability.h"
  #else
! #include <string.h>
! #endif
  
! #ifndef NEED_STRCASECMP
  int __strcasecmp_unneeded__;
  #else
  
***************
*** 113,119 ****
  
  int
  strcasecmp(s1, s2)
! 	const char  *s1, *s2;
  {
  	register const u_char *cm = charmap,
  			*us1 = (const u_char *)s1,
--- 115,121 ----
  
  int
  strcasecmp(s1, s2)
! 	const char *s1, *s2;
  {
  	register const u_char *cm = charmap,
  			*us1 = (const u_char *)s1,
diff --context --recurs m:\bindb32/compat/lib/strerror.c m:\bind/compat/lib/strerror.c
*** m:\bindb32/compat/lib/strerror.c	Mon Dec 25 21:59:26 1995
--- m:\bind/compat/lib/strerror.c	Mon Dec 25 22:04:47 1995
***************
*** 58,64 ****
  static char rcsid[] = "$Id: strerror.c,v 8.1 1994/12/15 06:23:51 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
  #if defined(BSD) && (BSD >= 199306)
  #include <string.h>
  #else
--- 58,66 ----
  static char rcsid[] = "$Id: strerror.c,v 8.1 1994/12/15 06:23:51 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #endif
  #if defined(BSD) && (BSD >= 199306)
  #include <string.h>
  #else
diff --context --recurs m:\bindb32/compat/lib/strpbrk.c m:\bind/compat/lib/strpbrk.c
*** m:\bindb32/compat/lib/strpbrk.c	Mon Dec 25 21:59:26 1995
--- m:\bind/compat/lib/strpbrk.c	Mon Dec 25 22:04:49 1995
***************
*** 58,64 ****
  static char rcsid[] = "$Id: strpbrk.c,v 8.1 1994/12/15 06:23:51 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
  #if defined(BSD) && (BSD >= 199306)
  #include <sys/cdefs.h>
  #include <string.h>
--- 58,66 ----
  static char rcsid[] = "$Id: strpbrk.c,v 8.1 1994/12/15 06:23:51 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #endif
  #if defined(BSD) && (BSD >= 199306)
  #include <sys/cdefs.h>
  #include <string.h>
diff --context --recurs m:\bindb32/compat/lib/strtoul.c m:\bind/compat/lib/strtoul.c
*** m:\bindb32/compat/lib/strtoul.c	Mon Dec 25 21:59:26 1995
--- m:\bind/compat/lib/strtoul.c	Mon Dec 25 22:04:50 1995
***************
*** 61,67 ****
  #include <limits.h>
  #include <ctype.h>
  #include <errno.h>
! #include <sys/param.h>
  #if defined(BSD) && (BSD >= 199306)
  #include <stdlib.h>
  #else
--- 61,69 ----
  #include <limits.h>
  #include <ctype.h>
  #include <errno.h>
! #ifndef WINNT
! #include <sys/param.h>
! #endif
  #if defined(BSD) && (BSD >= 199306)
  #include <stdlib.h>
  #else
diff --context --recurs m:\bindb32/compat/lib/writev.c m:\bind/compat/lib/writev.c
*** m:\bindb32/compat/lib/writev.c	Mon Dec 25 21:59:26 1995
--- m:\bind/compat/lib/writev.c	Mon Dec 25 22:04:51 1995
***************
*** 6,19 ****
   *
   *	Cray UNICOS
   *	SCO
!  */
  
! #if defined(_CRAY)
  #define OWN_WRITEV
  #include <sys/types.h>
  #include <sys/uio.h>
! #include <sys/stat.h>
! #include <sys/socket.h>
  
  int
  __writev(int fd, struct iovec *iov, int iovlen)
--- 6,20 ----
   *
   *	Cray UNICOS
   *	SCO
!  *  WindowsNT
!  */
  
! #if defined(_CRAY)
  #define OWN_WRITEV
  #include <sys/types.h>
  #include <sys/uio.h>
! #include <sys/stat.h>
! #include <sys/socket.h>
  
  int
  __writev(int fd, struct iovec *iov, int iovlen)
***************
*** 80,85 ****
--- 81,130 ----
  		vp++;
  	}
  	return (count);
+ }
+ #endif
+ 
+ #ifdef WINNT
+ #define OWN_WRITEV
+ #define TIMEOUT_SEC 120
+ #include <stdarg.h>
+ #include "../../conf/portability.h"
+ 
+ 
+ /*
+  * writev --
+  * simplistic writev implementation for WindowsNT using the WriteFile WIN32API.
+  */	
+ int
+ writev(fd, iov, iovcnt)
+ 	int fd;
+ 	struct iovec *iov;
+ 	int iovcnt;
+ {
+ 	int i;
+ 	char *base;
+ 	DWORD BytesWritten, TotalBytesWritten = 0, len, dwWait;
+ 	extern HANDLE hReadWriteEvent;
+ 	OVERLAPPED overlap;
+ 	BOOL ret; 
+ 
+ 	for (i=0; i<iovcnt; i++) {
+ 		base = iov[i].iov_base;
+ 		len = (DWORD)iov[i].iov_len;
+ 		overlap.Offset = overlap.OffsetHigh = (DWORD)0;
+ 		overlap.hEvent = hReadWriteEvent;
+ 		ret = WriteFile((HANDLE)fd, (char *)base, len,
+ 		              (LPDWORD)&BytesWritten, (LPOVERLAPPED)&overlap);
+ 		if ((ret == FALSE) && (errno != ERROR_IO_PENDING)) {
+ 				return (-1);
+ 		}
+ 		dwWait = WaitForSingleObject((HANDLE)hReadWriteEvent, (DWORD)TIMEOUT_SEC * 1000);
+ 		if ((dwWait == WAIT_FAILED) || (dwWait == WAIT_TIMEOUT)){
+ 			return (-1);
+ 		}
+ 		TotalBytesWritten += BytesWritten;
+ 	}
+ 	return((int)TotalBytesWritten);
  }
  #endif
  
diff --context --recurs m:\bindb32/conf/master/root.cache m:\bind/conf/master/root.cache
*** m:\bindb32/conf/master/root.cache	Mon Dec 25 21:59:16 1995
--- m:\bind/conf/master/root.cache	Mon Dec 25 22:04:51 1995
***************
*** 12,19 ****
  ;              submenu          InterNIC Registration Archives
  ;           file                named.root
  ;
! ;       last update:    Nov 8, 1995
! ;       related version of root zone:   1995110800
  ;
  ;
  ; formerly NS.INTERNIC.NET
--- 12,19 ----
  ;              submenu          InterNIC Registration Archives
  ;           file                named.root
  ;
! ;       last update:    Sep 1, 1995
! ;       related version of root zone:   1995090100
  ;
  ;
  ; formerly NS.INTERNIC.NET
diff --context --recurs m:\bindb32/conf/options.h m:\bind/conf/options.h
*** m:\bindb32/conf/options.h	Mon Dec 25 21:59:16 1995
--- m:\bind/conf/options.h	Mon Dec 25 22:04:52 1995
***************
*** 115,121 ****
  #define CLEANCACHE	/* useful and necessary in the face of NCACHE */
  #define PURGE_ZONE	/* remove all traces of a zone when reloading (mpa) */
  #define STATS		/* keep nameserver statistics; uses more memory */
! #define RENICE  	/* named-xfer should run at normal priority */
  #define XSTATS		/* extended statistics, syslogged periodically (bg) */
  /*#define BIND_NOTIFY	/* experimental - do not enable in customer products */
  /*#define LOC_RR	/* support for (draft) LOC record parsing (ckd) */
--- 115,123 ----
  #define CLEANCACHE	/* useful and necessary in the face of NCACHE */
  #define PURGE_ZONE	/* remove all traces of a zone when reloading (mpa) */
  #define STATS		/* keep nameserver statistics; uses more memory */
! #ifndef WINNT
! #define RENICE  	/* named-xfer should run at normal priority */
! #endif
  #define XSTATS		/* extended statistics, syslogged periodically (bg) */
  /*#define BIND_NOTIFY	/* experimental - do not enable in customer products */
  /*#define LOC_RR	/* support for (draft) LOC record parsing (ckd) */
diff --context --recurs m:\bindb32/conf/portability.h m:\bind/conf/portability.h
*** m:\bindb32/conf/portability.h	Mon Dec 25 21:59:16 1995
--- m:\bind/conf/portability.h	Mon Dec 25 22:04:54 1995
***************
*** 64,77 ****
  #include <string.h>
  #include <signal.h>
  #include <sys/types.h>
! #include <sys/param.h>
! #ifndef TIME_H_INCLUDED
! # include <sys/time.h>
! # define TIME_H_INCLUDED
! #endif
  
! #ifdef ISC
! # ifndef _POSIX_SOURCE
  #  define _POSIX_SOURCE
  # endif
  # define SYSV
--- 64,159 ----
  #include <string.h>
  #include <signal.h>
  #include <sys/types.h>
! #ifndef WINNT
! #include <sys/param.h>
! #ifndef TIME_H_INCLUDED
! # include <sys/time.h>
! # define TIME_H_INCLUDED
! #endif
! #endif /* WINNT */
! 
! #ifdef WINNT
! #ifndef _PORTABILITY_H
! #define _PORTABILITY_H
! #include <stdio.h>
! #ifdef BUFSIZ
! #undef BUFSIZ
! #endif
! #define BUFSIZ 1024  /* GMS - added since Unix used 1K and NT 512B */
! #include <string.h>
! #include <process.h>
! #include <sys/timeb.h>
! #include <time.h>
! #include <io.h>
! #include <stdlib.h>
! #define FD_SETSIZE 512
! #include <winsock.h>
! #include <windows.h>
! 
! #define NOWAIT
! #define HAVE_SETVBUF
! #define NEED_GETTIMEOFDAY
! #define USE_MEMCPY
! #undef IP_OPTIONS
! #define PATH_MAX MAX_PATH
! #define ETIMEDOUT WSAETIMEDOUT
! #define ECONNRESET WSAECONNRESET
! #define ECONNREFUSED WSAECONNREFUSED
! #define EADDRINUSE WSAEADDRINUSE
! #define PORT_WOULDBLK WSAEWOULDBLOCK
! #define _TIMEZONE timezoneBSD
  
! struct timezoneBSD {
! 	int tz_minuteswest;
! 	int tz_dsttime;
! };
! struct iovec {
! 	char *  iov_base;
! 	int 	iov_len;
! };
! typedef char *	caddr_t;
! typedef long pid_t;
! #define sleep(t) Sleep(t*1000)
! #define errno WSAGetLastError()
! /* #define close(s) closesocket(s) */
! #define chdir(path) SetCurrentDirectory(path)
! #define dup2(s1, s2) DuplicateHandle(GetCurrentProcess(), (HANDLE)(s1), \
! 					GetCurrentProcess(), (LPHANDLE)&(s2), \
! 					0, FALSE, DUPLICATE_SAME_ACCESS);
! #define strcasecmp(x, y) stricmp(x, y)
! #define strncasecmp(x, y, z) strnicmp(x, y, z)
! 
! void  	service_main(DWORD, LPTSTR *);
! void  	service_ctrl(DWORD);
! void    worker_thread(void *);
! void syslog(int, char *, ...);
! void expand_paths(void);
! int writev(int, struct iovec *, int);
! int mkstemp(char *);
! 
! #define MAXALIASES 35
! #define LOG_EMERG       0       /* system is unusable */
! #define LOG_ALERT       1       /* action must be taken immediately */
! #define LOG_CRIT        2       /* critical conditions */
! #define LOG_ERR         3       /* error conditions */
! #define LOG_WARNING     4       /* warning conditions */
! #define LOG_NOTICE      5       /* normal but signification condition */
! #define LOG_INFO        6       /* informational */
! #define LOG_DEBUG       7       /* debug-level messages */
! /* control codes that the service will accept */
! #define SERVICE_CONTROL_DUMPDB  128
! #define SERVICE_CONTROL_RELOAD  129
! #define SERVICE_CONTROL_STATS   130
! #define SERVICE_CONTROL_TRACE   131
! #define SERVICE_CONTROL_NOTRACE 132
! #define SERVICE_CONTROL_QRYLOG  133
! #define SERVICE_CONTROL_CHKPT   134
! #define SERVICE_CONTROL_EXIT    135
! #endif /* _PORTABILITY_H */
! #endif /* WINNT */
! 
! #ifdef ISC
! # ifndef _POSIX_SOURCE
  #  define _POSIX_SOURCE
  # endif
  # define SYSV
***************
*** 186,192 ****
  #endif
  
  #if !defined(BSD) || (BSD <= 199006)
! # if !defined(NeXT)
  #  define NEED_INETADDR
  # endif
  # define NEED_INETATON
--- 268,274 ----
  #endif
  
  #if !defined(BSD) || (BSD <= 199006)
! # if !defined(NeXT)	&& !defined(WINNT)
  #  define NEED_INETADDR
  # endif
  # define NEED_INETATON
***************
*** 249,262 ****
  # define STDIN_FILENO	0
  # define STDOUT_FILENO	1
  # define STDERR_FILENO	2
! # ifndef NeXT
  extern char *getenv __P((char *));
  # else
  extern char *getenv __P((const char *));
  # endif
  extern int errno;
  
! # if !defined(DMALLOC) && !defined(NeXT)
  extern char *malloc(), *realloc(), *calloc();
  #  if defined(sun)
  extern int free();
--- 331,346 ----
  # define STDIN_FILENO	0
  # define STDOUT_FILENO	1
  # define STDERR_FILENO	2
! # if !defined(NeXT) && !defined(WINNT)
  extern char *getenv __P((char *));
  # else
  extern char *getenv __P((const char *));
  # endif
+ #ifndef WINNT
  extern int errno;
+ #endif
  
! # if !defined(DMALLOC) && !defined(NeXT) && !defined(WINNT)
  extern char *malloc(), *realloc(), *calloc();
  #  if defined(sun)
  extern int free();
***************
*** 302,308 ****
  #undef IP_OPTIONS
  #endif
  
! #if !defined(__STDC__) && !defined(const)
  # define const /*constant*/
  #endif
  
--- 386,392 ----
  #undef IP_OPTIONS
  #endif
  
! #if !defined(__STDC__) && !defined(const) && !defined(WINNT)
  # define const /*constant*/
  #endif
  
***************
*** 313,318 ****
--- 397,403 ----
  /* is USE_POSIX the right thing to use here? */
  #if (!defined(BSD) || (BSD <= 43)) && \
  	!defined(NeXT) && \
+ 	!defined(WINNT) && \
  	!defined(__convex__) && \
  	!defined(USE_POSIX)
  # if !defined(NCR)
***************
*** 325,333 ****
  #endif
  
  #if !defined(bcopy)	/* some machines have their own macros for this */
! # if defined(USE_POSIX) || \
  	 (defined(__STDC__) && !defined(sun) && !defined(sequent) \
! 	  && !defined(M_UNIX))
  /* use ANSI C3.159-1989 (``ANSI C'') functions if possible;
   * ideally we would change the code to use them and then
   * define them in terms of bcopy et al if !defined(__STDC__)
--- 410,418 ----
  #endif
  
  #if !defined(bcopy)	/* some machines have their own macros for this */
! # if defined(USE_POSIX) || defined(WINNT) ||\
  	 (defined(__STDC__) && !defined(sun) && !defined(sequent) \
!  	  && !defined(M_UNIX))
  /* use ANSI C3.159-1989 (``ANSI C'') functions if possible;
   * ideally we would change the code to use them and then
   * define them in terms of bcopy et al if !defined(__STDC__)
***************
*** 349,355 ****
  
  #if (!defined(BSD) || (BSD < 43) || defined(RISCOS_BSD)) \
  	&& !defined(USE_POSIX) && !defined(apollo) && !defined(sequent) \
! 	&& !defined(M_UNIX)
  # define NEED_STRERROR
  #if !defined(ultrix) && !defined(NCR)
  # define NEED_PUTENV
--- 434,440 ----
  
  #if (!defined(BSD) || (BSD < 43) || defined(RISCOS_BSD)) \
  	&& !defined(USE_POSIX) && !defined(apollo) && !defined(sequent) \
! 	&& !defined(M_UNIX)	&& !defined(WINNT)
  # define NEED_STRERROR
  #if !defined(ultrix) && !defined(NCR)
  # define NEED_PUTENV
***************
*** 366,372 ****
  
  #if (!defined(BSD) || (BSD < 43))
  # define NEED_MKSTEMP
! # if !defined(__ultrix) && !defined(apollo)
  #  define NEED_STRCASECMP
  #  define NEED_MKTEMP
  #  if !defined(SVR4)
--- 451,457 ----
  
  #if (!defined(BSD) || (BSD < 43))
  # define NEED_MKSTEMP
! # if !defined(__ultrix) && !defined(apollo) && !defined(WINNT)
  #  define NEED_STRCASECMP
  #  define NEED_MKTEMP
  #  if !defined(SVR4)
***************
*** 416,424 ****
--- 501,511 ----
  # define PORT_NONBLOCK	O_NONBLOCK
  # define PORT_WOULDBLK	EAGAIN
  #else
+ #if !defined(WINNT)
  # define PORT_NONBLOCK	O_NDELAY
  # define PORT_WOULDBLK	EWOULDBLOCK
  #endif
+ #endif
  
  #if defined(USE_POSIX)
  # define USE_SETSID
***************
*** 428,434 ****
  #define USE_WAITPID
  #endif
  
! #if !defined(USE_POSIX)
  #define waitpid(x,y,z) (wait3(y,z,(struct rusage *)NULL))
  #endif
  
--- 515,521 ----
  #define USE_WAITPID
  #endif
  
! #if !defined(USE_POSIX) && !defined(WINNT)
  #define waitpid(x,y,z) (wait3(y,z,(struct rusage *)NULL))
  #endif
  
***************
*** 444,449 ****
--- 531,537 ----
  #define WTERMSIG(x)	((x).w_termsig)
  #endif /* sequent */
  
+ #ifndef WINNT
  #if !defined(WIFEXITED)
  # define WIFEXITED(x) (!(x & 0177))
  #endif
***************
*** 456,461 ****
--- 544,550 ----
  #if !defined(WTERMSIG)
  # define WTERMSIG(x) (x & 0177)
  #endif
+ #endif
  
  #ifndef S_ISDIR
  # ifndef S_IFMT
***************
*** 488,494 ****
  #endif
  
  #if defined(NEED_STRTOUL) && \
! 	(defined(__ultrix) || defined(__osf__) || defined(NeXT))
  # undef NEED_STRTOUL
  #endif
  
--- 577,583 ----
  #endif
  
  #if defined(NEED_STRTOUL) && \
! 	(defined(__ultrix) || defined(__osf__) || defined(NeXT) || defined(WINNT))
  # undef NEED_STRTOUL
  #endif
  
***************
*** 547,553 ****
  /*
   * Assume that a system has fchmod() unless something above says otherwise.
   */
! #if !defined(HAVE_FCHMOD)
  # define HAVE_FCHMOD 1
  #endif
  
--- 636,642 ----
  /*
   * Assume that a system has fchmod() unless something above says otherwise.
   */
! #if !defined(HAVE_FCHMOD) && !defined(WINNT)
  # define HAVE_FCHMOD 1
  #endif
  
***************
*** 564,567 ****
--- 653,662 ----
  
  #if defined(SVR4) && defined(sun)
  extern int gethostname __P((char *, size_t));
+ #endif
+ 
+ #ifdef WINNT /* l kahn new definitions needed for vc++4.0 */
+ #define fstat _fstat
+ #define stat _stat
+ #define fileno _fileno
  #endif
Only in m:\bind/contrib/nutshell: ch09.check_del.c~
diff --context --recurs m:\bindb32/contrib/old/nstest.c m:\bind/contrib/old/nstest.c
*** m:\bindb32/contrib/old/nstest.c	Mon Dec 25 21:59:24 1995
--- m:\bind/contrib/old/nstest.c	Mon Dec 25 22:04:55 1995
***************
*** 65,80 ****
  static char rcsid[] = "$Id: nstest.c,v 8.1 1994/12/15 06:24:29 vixie Exp $";
  #endif /* not lint */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
! #include <stdio.h>
! #include <resolv.h>
! #include "../conf/portability.h"
  
! char *progname;
  FILE *log;
  #define MAXDATA		256   /* really should get this from named/db.h */
  main(argc, argv)
--- 65,87 ----
  static char rcsid[] = "$Id: nstest.c,v 8.1 1994/12/15 06:24:29 vixie Exp $";
  #endif /* not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
! #include <stdio.h>
! #include <resolv.h>
! #include "../../conf/portability.h"
! 
! #ifdef WINNT
! void usage();
! HANDLE hReadWriteEvent;
! #endif
  
! char *progname;
  FILE *log;
  #define MAXDATA		256   /* really should get this from named/db.h */
  main(argc, argv)
***************
*** 94,101 ****
  	NewRR.r_data = (char *) malloc(MAXDATA);
  	progname = argv[0];
  	dump_packet = 0;
- 	_res.options |= RES_DEBUG|RES_RECURSE;
  	(void) res_init();
  	while (argc > 1 && argv[1][0] == '-') {
  		argc--;
  		cp = *++argv;
--- 101,108 ----
  	NewRR.r_data = (char *) malloc(MAXDATA);
  	progname = argv[0];
  	dump_packet = 0;
  	(void) res_init();
+ 	_res.options |= RES_DEBUG|RES_RECURSE;
  	while (argc > 1 && argv[1][0] == '-') {
  		argc--;
  		cp = *++argv;
***************
*** 128,134 ****
  			}
  	}
  	_res.nsaddr.sin_family = AF_INET;
! 	_res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
  	_res.nsaddr.sin_port = port;
   	if (argc > 1) {
  		if (!inet_aton(argv[1],
--- 135,142 ----
  			}
  	}
  	_res.nsaddr.sin_family = AF_INET;
! //	_res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
! 	_res.nsaddr.sin_addr.s_addr = inet_addr("132.233.186.51");
  	_res.nsaddr.sin_port = port;
   	if (argc > 1) {
  		if (!inet_aton(argv[1],
***************
*** 316,321 ****
--- 324,330 ----
  				    for (i = 0; i < oldnbytes; i++) {
  					    OldRRData[i] = (char) i;
  				    }
+ 					_res.options |= RES_DEBUG|RES_RECURSE;
  					n = res_mkquery(UPDATEM, cp,
  							C_IN, Type,
  							OldRRData, oldnbytes,
***************
*** 418,423 ****
--- 427,433 ----
  	}
  }
  
+ void
  usage()
  {
  	fprintf(stderr, "Usage: %s [-v] [-i] [-r] [-d] [-p port] hostaddr\n",
Only in m:\bind/contrib: winnt-dist
Only in m:\bind: creadme.bat
Only in m:\bind: diffs.ksh
Only in m:\bind: diffsb31tont_context.txt
Only in m:\bind: diffsb31tont_nocontext.txt
Only in m:\bind: diffsbindb31_b32_context.txt
Only in m:\bind: diffsbindb31_b32_nocontext.txt
Only in m:\bind/doc/info: Linux-ELF
Only in m:\bind/doc/info: Linux-again
Only in m:\bind/doc/info: Linux-and-more
Only in m:\bind/doc/info: Linux-more
Only in m:\bind/doc/info: Linux-still-more
Only in m:\bind/doc/info: sunshlib.3
Only in m:\bind/doc/misc: notify.txt
Only in m:\bind: eventlib.zip
diff --context --recurs m:\bindb32/include/arpa/inet.h m:\bind/include/arpa/inet.h
*** m:\bindb32/include/arpa/inet.h	Mon Dec 25 21:59:10 1995
--- m:\bind/include/arpa/inet.h	Mon Dec 25 22:04:56 1995
***************
*** 63,84 ****
  
  /* External definitions for functions in inet(3) */
  
! #include <sys/param.h>
! #if (!defined(BSD)) || (BSD < 199306)
! # include <sys/bitypes.h>
! #else
! # include <sys/types.h>
! #endif
! #include <sys/cdefs.h>
! 
! __BEGIN_DECLS
! unsigned long	 inet_addr __P((const char *));
  int		 inet_aton __P((const char *, struct in_addr *));
  unsigned long	 inet_lnaof __P((struct in_addr));
  struct in_addr	 inet_makeaddr __P((u_long , u_long));
  unsigned long	 inet_netof __P((struct in_addr));
  unsigned long	 inet_network __P((const char *));
  char		*inet_ntoa __P((struct in_addr));
  __END_DECLS
  
  #endif /* !_INET_H_ */
--- 63,93 ----
  
  /* External definitions for functions in inet(3) */
  
! #ifndef WINNT
! #include <sys/param.h>
! #if (!defined(BSD)) || (BSD < 199306)
! # include <sys/bitypes.h>
! #else
! # include <sys/types.h>
! #endif
! #else
! #define FD_SETSIZE 512
! #include <winsock.h>
! #endif /* WINNT */
! #include <sys/cdefs.h>
! 
! __BEGIN_DECLS
! #ifndef WINNT
! unsigned long	 inet_addr __P((const char *));
! #endif
  int		 inet_aton __P((const char *, struct in_addr *));
  unsigned long	 inet_lnaof __P((struct in_addr));
  struct in_addr	 inet_makeaddr __P((u_long , u_long));
  unsigned long	 inet_netof __P((struct in_addr));
  unsigned long	 inet_network __P((const char *));
+ #ifndef WINNT
  char		*inet_ntoa __P((struct in_addr));
+ #endif
  __END_DECLS
  
  #endif /* !_INET_H_ */
diff --context --recurs m:\bindb32/include/arpa/nameser.h m:\bind/include/arpa/nameser.h
*** m:\bindb32/include/arpa/nameser.h	Mon Dec 25 21:59:10 1995
--- m:\bind/include/arpa/nameser.h	Mon Dec 25 22:04:56 1995
***************
*** 61,76 ****
  #ifndef _NAMESER_H_
  #define	_NAMESER_H_
  
! #include <sys/param.h>
! #if (!defined(BSD)) || (BSD < 199306)
! # include <sys/bitypes.h>
  #else
! # include <sys/types.h>
  #endif
! #include <sys/cdefs.h>
  
! #ifdef _AUX_SOURCE
! #include <sys/types.h>			/* ech for A/UX */
  #define res_send ucb_res_send		/* already def'd in libc */
  #define _res_close _ucb_res_close    /* removing res_send.o from the library */
  #endif				     /* gives an undefined symbol... */
--- 61,78 ----
  #ifndef _NAMESER_H_
  #define	_NAMESER_H_
  
! #ifndef WINNT
! #include <sys/param.h>
! #endif
! #if (!defined(BSD)) || (BSD < 199306)
! # include <sys/bitypes.h>
  #else
! # include <sys/types.h>
  #endif
! #include <sys/cdefs.h>
  
! #ifdef _AUX_SOURCE
! #include <sys/types.h>			/* ech for A/UX */
  #define res_send ucb_res_send		/* already def'd in libc */
  #define _res_close _ucb_res_close    /* removing res_send.o from the library */
  #endif				     /* gives an undefined symbol... */
***************
*** 126,132 ****
--- 128,136 ----
  /*
   * Currently defined response codes
   */
+ #if !(defined(WINNT) && defined(NOERROR))
  #define NOERROR		0		/* no error */
+ #endif
  #define FORMERR		1		/* format error */
  #define SERVFAIL	2		/* server failure */
  #define NXDOMAIN	3		/* non existent domain */
***************
*** 327,334 ****
  #define PUTSHORT(s, cp) { \
  	register u_int16_t t_s = (u_int16_t)(s); \
  	register u_char *t_cp = (u_char *)(cp); \
! 	*t_cp++ = t_s >> 8; \
! 	*t_cp   = t_s; \
  	(cp) += INT16SZ; \
  }
  
--- 331,338 ----
  #define PUTSHORT(s, cp) { \
  	register u_int16_t t_s = (u_int16_t)(s); \
  	register u_char *t_cp = (u_char *)(cp); \
! 	*t_cp++ = (char) (t_s >> 8); \
! 	*t_cp   = (char) t_s; \
  	(cp) += INT16SZ; \
  }
  
diff --context --recurs m:\bindb32/include/netdb.h m:\bind/include/netdb.h
*** m:\bindb32/include/netdb.h	Mon Dec 25 21:59:11 1995
--- m:\bind/include/netdb.h	Mon Dec 25 22:04:57 1995
***************
*** 61,80 ****
  #ifndef _NETDB_H_
  #define _NETDB_H_
  
! #include <sys/param.h>
! #if (!defined(BSD)) || (BSD < 199306)
! # include <sys/bitypes.h>
! #endif
! #include <sys/cdefs.h>
! 
! #define	_PATH_HEQUIV	"/etc/hosts.equiv"
! #define	_PATH_HOSTS	"/etc/hosts"
! #define	_PATH_NETWORKS	"/etc/networks"
! #define	_PATH_PROTOCOLS	"/etc/protocols"
  #define	_PATH_SERVICES	"/etc/services"
  
  extern int h_errno;
  
  /*
   * Structures returned by network data base library.  All addresses are
   * supplied in host order, and returned in network order (suitable for
--- 61,90 ----
  #ifndef _NETDB_H_
  #define _NETDB_H_
  
! #ifndef WINNT
! #include <sys/param.h>
! #endif /* WINNT */
! #if (!defined(BSD)) || (BSD < 199306)
! # include <sys/bitypes.h>
! #endif
! #include <sys/cdefs.h>
! 
! #ifndef WINNT
! #define	_PATH_HEQUIV	"/etc/hosts.equiv"
! #define	_PATH_HOSTS	"/etc/hosts"
! #define	_PATH_NETWORKS	"/etc/networks"
! #define	_PATH_PROTOCOLS	"/etc/protocols"
  #define	_PATH_SERVICES	"/etc/services"
  
  extern int h_errno;
+ #else /* WINNT */
+ #define	_PATH_HOSTS	"%windir%\\SYSTEM32\\DRIVERS\\ETC\\HOSTS"
+ #define	_PATH_NETWORKS	"%windir%\\SYSTEM32\\DRIVERS\\ETC\\NETWORKS"
+ #define	_PATH_PROTOCOL	"%windir%\\SYSTEM32\\DRIVERS\\ETC\\PROTOCOL"
+ #define	_PATH_SERVICES	"%windir%\\SYSTEM32\\DRIVERS\\ETC\\SERVICES"
+ #endif /* WINNT */
  
+ #ifndef WINNT
  /*
   * Structures returned by network data base library.  All addresses are
   * supplied in host order, and returned in network order (suitable for
***************
*** 112,117 ****
--- 122,128 ----
  	char	**p_aliases;	/* alias list */
  	int	p_proto;	/* protocol # */
  };
+ #endif /* WINNT */
  
  /*
   * Error return codes from gethostbyname() and gethostbyaddr()
***************
*** 120,148 ****
  
  #define	NETDB_INTERNAL	-1	/* see errno */
  #define	NETDB_SUCCESS	0	/* no problem */
  #define	HOST_NOT_FOUND	1 /* Authoritative Answer Host not found */
  #define	TRY_AGAIN	2 /* Non-Authoritive Host not found, or SERVERFAIL */
  #define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  #define	NO_DATA		4 /* Valid name, no data record of requested type */
  #define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */
  
  __BEGIN_DECLS
  void		endhostent __P((void));
  void		endnetent __P((void));
  void		endprotoent __P((void));
  void		endservent __P((void));
  struct hostent	*gethostbyaddr __P((const char *, int, int));
  struct hostent	*gethostbyname __P((const char *));
  struct hostent	*gethostbyname2 __P((const char *, int));
  struct hostent	*gethostent __P((void));
! struct netent	*getnetbyaddr __P((long, int)); /* u_long? */
  struct netent	*getnetbyname __P((const char *));
  struct netent	*getnetent __P((void));
  struct protoent	*getprotobyname __P((const char *));
  struct protoent	*getprotobynumber __P((int));
  struct protoent	*getprotoent __P((void));
  struct servent	*getservbyname __P((const char *, const char *));
  struct servent	*getservbyport __P((int, const char *));
  struct servent	*getservent __P((void));
  void		herror __P((const char *));
  const char	*hstrerror __P((int));
--- 131,167 ----
  
  #define	NETDB_INTERNAL	-1	/* see errno */
  #define	NETDB_SUCCESS	0	/* no problem */
+ #ifndef WINNT
  #define	HOST_NOT_FOUND	1 /* Authoritative Answer Host not found */
  #define	TRY_AGAIN	2 /* Non-Authoritive Host not found, or SERVERFAIL */
  #define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  #define	NO_DATA		4 /* Valid name, no data record of requested type */
  #define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */
+ #endif /* WINNT */
  
  __BEGIN_DECLS
  void		endhostent __P((void));
  void		endnetent __P((void));
  void		endprotoent __P((void));
  void		endservent __P((void));
+ #ifndef WINNT
  struct hostent	*gethostbyaddr __P((const char *, int, int));
  struct hostent	*gethostbyname __P((const char *));
  struct hostent	*gethostbyname2 __P((const char *, int));
  struct hostent	*gethostent __P((void));
! struct netent	*getnetbyaddr __P((u_long, int)); /* u_long? */
  struct netent	*getnetbyname __P((const char *));
+ #endif
  struct netent	*getnetent __P((void));
+ #ifndef WINNT
  struct protoent	*getprotobyname __P((const char *));
  struct protoent	*getprotobynumber __P((int));
+ #endif
  struct protoent	*getprotoent __P((void));
+ #ifndef WINNT
  struct servent	*getservbyname __P((const char *, const char *));
  struct servent	*getservbyport __P((int, const char *));
+ #endif
  struct servent	*getservent __P((void));
  void		herror __P((const char *));
  const char	*hstrerror __P((int));
diff --context --recurs m:\bindb32/include/resolv.h m:\bind/include/resolv.h
*** m:\bindb32/include/resolv.h	Mon Dec 25 21:59:10 1995
--- m:\bind/include/resolv.h	Mon Dec 25 22:04:58 1995
***************
*** 61,74 ****
  #ifndef _RESOLV_H_
  #define	_RESOLV_H_
  
! #include <sys/param.h>
! #if (!defined(BSD)) || (BSD < 199306)
! # include <sys/bitypes.h>
! #else
! # include <sys/types.h>
  #endif
! #include <sys/cdefs.h>
! #include <stdio.h>
  
  /*
   * revision information.  this is the release date in YYYYMMDD format.
--- 61,80 ----
  #ifndef _RESOLV_H_
  #define	_RESOLV_H_
  
! #ifndef WINNT
! #include <sys/param.h>
  #endif
! #if (!defined(BSD)) || (BSD < 199306)
! # include <sys/bitypes.h>
! #else
! # include <sys/types.h>
! #endif
! #include <sys/cdefs.h>
! #include <stdio.h>
! #ifdef WINNT
! #define FD_SETSIZE 512
! #include <winsock.h>
! #endif
  
  /*
   * revision information.  this is the release date in YYYYMMDD format.
***************
*** 87,93 ****
--- 93,104 ----
   */
  
  #ifndef _PATH_RESCONF
+ #ifndef WINNT
  #define _PATH_RESCONF        "/etc/resolv.conf"
+ #else
+ #define _PATH_RESCONF		 "%windir%\\RESOLV.CONF"
+ #define _ALT_PATH_RESCONF	 "%windir%\\RESOLV.INI"
+ #endif /* WINNT */
  #endif
  
  /*
***************
*** 237,243 ****
  int	 res_queriesmatch __P((const u_char *, const u_char *,
  			       const u_char *, const u_char *));
  /* XXX - these last two don't belong in the resolver */
! u_int	 inet_nsap_addr __P((const char *, u_char *, int maxlen));
  char	*inet_nsap_ntoa __P((int, const u_char *, char *ascii));
  __END_DECLS
  
--- 248,254 ----
  int	 res_queriesmatch __P((const u_char *, const u_char *,
  			       const u_char *, const u_char *));
  /* XXX - these last two don't belong in the resolver */
! u_int	 inet_nsap_addr __P((const char *, u_char *, u_int maxlen));
  char	*inet_nsap_ntoa __P((int, const u_char *, char *ascii));
  __END_DECLS
  
Only in m:\bind: mkdist.bat
Only in m:\bind: mksrc.bat
Only in m:\bind: mktxt.bat
Only in m:\bind/named: TAGS
diff --context --recurs m:\bindb32/named/Version.c m:\bind/named/Version.c
*** m:\bindb32/named/Version.c	Mon Dec 25 21:59:13 1995
--- m:\bind/named/Version.c	Mon Dec 25 22:10:30 1995
***************
*** 8,14 ****
  char rcsid[] = "$Id: Version.c,v 8.1 1994/12/15 06:24:14 vixie Exp $";
  #endif /* not lint */
  
! char Version[] = "named %VERSION% %WHEN%\n\t%WHOANDWHERE%";
  
  #ifdef COMMENT
  
--- 8,19 ----
  char rcsid[] = "$Id: Version.c,v 8.1 1994/12/15 06:24:14 vixie Exp $";
  #endif /* not lint */
  
! #ifndef WINNT
! char Version[] = "named %VERSION% %WHEN%\n\t%WHOANDWHERE%";
! #else
! char Version[] = "named 4.9.3-BETA32-Monday-25-Dec\n\tGregSchueman-LarryKahn-VirajBais";
! #endif
! 
  
  #ifdef COMMENT
  
Only in m:\bind/named: WinRel
diff --context --recurs m:\bindb32/named/db_defs.h m:\bind/named/db_defs.h
*** m:\bindb32/named/db_defs.h	Mon Dec 25 21:59:12 1995
--- m:\bind/named/db_defs.h	Mon Dec 25 22:05:00 1995
***************
*** 76,82 ****
   */
  struct databuf {
  	struct databuf	*d_next;	/* linked list */
! 	u_int32_t	d_ttl;		/* time to live */
  					/* if d_zone == DB_Z_CACHE, then
  					 * d_ttl is actually the time when
  					 * the record will expire.
--- 76,86 ----
   */
  struct databuf {
  	struct databuf	*d_next;	/* linked list */
! #ifndef WINNT
! 	u_int32_t	d_ttl;		/* time to live */
! #else
! 	int32_t	        d_ttl;		/* time to live */
! #endif
  					/* if d_zone == DB_Z_CACHE, then
  					 * d_ttl is actually the time when
  					 * the record will expire.
diff --context --recurs m:\bindb32/named/db_dump.c m:\bind/named/db_dump.c
*** m:\bindb32/named/db_dump.c	Mon Dec 25 21:59:13 1995
--- m:\bind/named/db_dump.c	Mon Dec 25 22:05:01 1995
***************
*** 58,73 ****
   * --Copyright--
   */
  
! #include <sys/param.h>
! #include <sys/stat.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <netdb.h>
! #include <stdio.h>
! #include <syslog.h>
! #include <resolv.h>
! #include <errno.h>
  
  #include "named.h"
  
--- 58,77 ----
   * --Copyright--
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/stat.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <netdb.h>
! #include <stdio.h>
! #ifndef WINNT
! #include <syslog.h>
! #endif
! #include <resolv.h>
! #include <errno.h>
  
  #include "named.h"
  
***************
*** 413,426 ****
  			}
  			if (dp->d_zone == DB_Z_CACHE) {
  			    if (dp->d_flags & DB_F_HINT
! 				&& (int32_t)(dp->d_ttl - tt.tv_sec)
  				    < DB_ROOT_TIMBUF)
  				    fprintf(fp, "%d\t", DB_ROOT_TIMBUF);
  			    else
  				    fprintf(fp, "%d\t",
  				        (int)(dp->d_ttl - tt.tv_sec));
  			} else if (dp->d_ttl != 0 &&
! 			    dp->d_ttl != zones[dp->d_zone].z_minimum)
  				fprintf(fp, "%d\t", (int)dp->d_ttl);
  			else if (tab)
  			    (void) putc('\t', fp);
--- 417,430 ----
  			}
  			if (dp->d_zone == DB_Z_CACHE) {
  			    if (dp->d_flags & DB_F_HINT
! 				&& (int)(dp->d_ttl - tt.tv_sec)
  				    < DB_ROOT_TIMBUF)
  				    fprintf(fp, "%d\t", DB_ROOT_TIMBUF);
  			    else
  				    fprintf(fp, "%d\t",
  				        (int)(dp->d_ttl - tt.tv_sec));
  			} else if (dp->d_ttl != 0 &&
! 			    (u_int32_t)dp->d_ttl != zones[dp->d_zone].z_minimum)
  				fprintf(fp, "%d\t", (int)dp->d_ttl);
  			else if (tab)
  			    (void) putc('\t', fp);
***************
*** 573,579 ****
  				if (dp->d_size == INT32SZ) {
  					GETLONG(n, cp);
  				} else {
! 					n = -2;		/* XXX - hack */
  				}
  				fprintf(fp, "%u", n);
  				break;
--- 577,583 ----
  				if (dp->d_size == INT32SZ) {
  					GETLONG(n, cp);
  				} else {
! 					n = (u_int32_t) -2;		/* XXX - hack */
  				}
  				fprintf(fp, "%u", n);
  				break;
diff --context --recurs m:\bindb32/named/db_glue.c m:\bind/named/db_glue.c
*** m:\bindb32/named/db_glue.c	Mon Dec 25 21:59:13 1995
--- m:\bind/named/db_glue.c	Mon Dec 25 22:05:02 1995
***************
*** 59,74 ****
   */
  
  #include <sys/types.h>
! #include <sys/uio.h>
! #include <sys/param.h>
! #include <sys/stat.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
! #include <stdio.h>
! #include <syslog.h>
! #include <ctype.h>
! #include <netdb.h>
  #include <resolv.h>
  #include <errno.h>
  #include <signal.h>
--- 59,78 ----
   */
  
  #include <sys/types.h>
! #ifndef WINNT
! #include <sys/uio.h>
! #include <sys/param.h>
! #include <sys/stat.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
! #include <stdio.h>
! #ifndef WINNT
! #include <syslog.h>
! #endif
! #include <ctype.h>
! #include <netdb.h>
  #include <resolv.h>
  #include <errno.h>
  #include <signal.h>
***************
*** 122,129 ****
--- 126,140 ----
  		syslog(LOG_CRIT, "%s - ABORT", msg);
  	else
  		syslog(LOG_CRIT, "%s: %s - ABORT", msg, strerror(err));
+ #ifndef WINNT
  	signal(SIGIOT, SIG_DFL);	/* no POSIX needed here. */
  	abort();
+ #else
+   	/* under Windows, abort() does not call raise(SIGABRT)
+   	 * or flush stream buffers
+   	 */
+   	 exit(3);
+   #endif
  }
  
  void
***************
*** 139,151 ****
  #endif
  	while (sp = getservent()) {
  		slp = (struct valuelist *)malloc(sizeof(struct valuelist));
! 		if (!slp)
! 			panic(errno, "malloc(servent)");
! 		slp->name = savestr(sp->s_name);
  		slp->proto = savestr(sp->s_proto);
! 		slp->port = ntohs((u_int16_t)sp->s_port);  /* host byt order */
! 		slp->next = servicelist;
! 		slp->prev = NULL;
  		if (servicelist)
  			servicelist->prev = slp;
  		servicelist = slp;
--- 150,162 ----
  #endif
  	while (sp = getservent()) {
  		slp = (struct valuelist *)malloc(sizeof(struct valuelist));
!  		if (!slp)
!   			panic(errno, "malloc(servent)");
!  		slp->name  = savestr(sp->s_name);
  		slp->proto = savestr(sp->s_proto);
! 		slp->port = ntohs((u_int16_t)sp->s_port); /* host byte order */
! 		slp->next  = servicelist;
! 		slp->prev  = NULL;
  		if (servicelist)
  			servicelist->prev = slp;
  		servicelist = slp;
***************
*** 368,378 ****
--- 379,401 ----
  	int s;
  
  	do {
+ #ifndef WINNT
  		errno = 0;
+ #else
+ 		WSASetLastError(0);
+ #endif
+ #ifndef WINNT
  		s = close(fd);
+ #else
+ 		s = closesocket(fd);
+ #endif
  	} while (s < 0 && errno == EINTR);
  
+ #ifndef WINNT
  	if (s < 0 && errno != EBADF)
+ #else
+ 	if (s < 0 && errno != WSAEBADF)
+ #endif
  		syslog(LOG_INFO, "close(%d) failed: %m", fd);
  	else
  		dprintf(3, (ddt, "close(%d) succeeded\n", fd));
***************
*** 1179,1184 ****
--- 1202,1208 ----
  }
  
  /* Signal abstraction. */
+ #ifndef WINNT
  
  void
  setsignal(catch, block, handler)
***************
*** 1222,1224 ****
--- 1246,1249 ----
  	setsignal(catch, block, handler);
  #endif
  }
+ #endif /* WINNT */
diff --context --recurs m:\bindb32/named/db_load.c m:\bind/named/db_load.c
*** m:\bindb32/named/db_load.c	Mon Dec 25 21:59:12 1995
--- m:\bind/named/db_load.c	Mon Dec 25 22:05:03 1995
***************
*** 62,77 ****
   * Load data base from ascii backupfile.  Format similar to RFC 883.
   */
  
! #include <sys/param.h>
! #include <sys/stat.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <stdio.h>
! #include <syslog.h>
! #include <ctype.h>
! #include <netdb.h>
! #include <resolv.h>
  #include <errno.h>
  
  #include "named.h"
--- 62,81 ----
   * Load data base from ascii backupfile.  Format similar to RFC 883.
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <netinet/in.h>
! #endif
! #include <sys/stat.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <stdio.h>
! #ifndef WINNT
! #include <syslog.h>
! #endif
! #include <ctype.h>
! #include <netdb.h>
! #include <resolv.h>
  #include <errno.h>
  
  #include "named.h"
***************
*** 208,214 ****
  	(void) strcpy(origin, in_origin);
  	if ((fp = fopen(filename, "r")) == NULL) {
  		syslog(LOG_WARNING, "%s: %m", filename);
! 		dprintf(1, (ddt, "db_load: error opening file %s\n",
  			    filename));
  		return (-1);
  	}
--- 212,218 ----
  	(void) strcpy(origin, in_origin);
  	if ((fp = fopen(filename, "r")) == NULL) {
  		syslog(LOG_WARNING, "%s: %m", filename);
! 		dprintf(1, (ddt, "db_load: error opening file %s \n",
  			    filename));
  		return (-1);
  	}
***************
*** 294,300 ****
  			if (isdigit(*cp)) {
  				n = 0;
  				do {
! 				    if (n > (INT_MAX - (*cp - '0')) / 10) {
  					syslog(LOG_INFO, 
  					   "%s: line %d: number > %lu\n",
  					   filename, lineno, (u_long)INT_MAX);
--- 298,304 ----
  			if (isdigit(*cp)) {
  				n = 0;
  				do {
! 				    if (n > (((u_int32_t)INT_MAX - (u_int32_t)(*cp - '0')) / (u_int32_t)10)) {
  					syslog(LOG_INFO, 
  					   "%s: line %d: number > %lu\n",
  					   filename, lineno, (u_long)INT_MAX);
***************
*** 307,313 ****
  				if (zp->z_type == Z_CACHE) {
  				    /* this allows the cache entry to age */
  				    /* while sitting on disk (powered off) */
! 				    if (n > max_cache_ttl)
  					n = max_cache_ttl;
  				    n += sb.st_mtime;
  				}
--- 311,317 ----
  				if (zp->z_type == Z_CACHE) {
  				    /* this allows the cache entry to age */
  				    /* while sitting on disk (powered off) */
! 				    if (n > (u_int32_t)max_cache_ttl)
  					n = max_cache_ttl;
  				    n += sb.st_mtime;
  				}
***************
*** 526,532 ****
--- 530,540 ----
  						goto err;
  				}
                                  read_soa++;
+ #ifndef WINNT
  				if (zp->z_expire < zp->z_refresh ) {
+ #else
+ 				if ((u_int32_t)zp->z_expire < zp->z_refresh ) {
+ #endif
  				    syslog(LOG_WARNING,
      "%s: WARNING SOA expire value is less then SOA refresh (%lu < %lu)",
  				    filename, zp->z_expire, zp->z_refresh);
***************
*** 665,671 ****
  				    i = (sizeof data) * 255 / 256;
  				}
  				while (i > 255) {
! 				    *cp++ = 255;
  				    bcopy(cp1, cp, 255);
  				    cp += 255;
  				    cp1 += 255;
--- 673,679 ----
  				    i = (sizeof data) * 255 / 256;
  				}
  				while (i > 255) {
! 				    *cp++ = (char)255;
  				    bcopy(cp1, cp, 255);
  				    cp += 255;
  				    cp1 += 255;
diff --context --recurs m:\bindb32/named/db_lookup.c m:\bind/named/db_lookup.c
*** m:\bindb32/named/db_lookup.c	Mon Dec 25 21:59:12 1995
--- m:\bind/named/db_lookup.c	Mon Dec 25 22:05:03 1995
***************
*** 62,71 ****
   * Table lookup routines.
   */
  
! #include <syslog.h>
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
  #include <arpa/nameser.h>
  #include <stdio.h>
  #include <ctype.h>
--- 62,73 ----
   * Table lookup routines.
   */
  
! #ifndef WINNT
! #include <syslog.h>
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
  #include <arpa/nameser.h>
  #include <stdio.h>
  #include <ctype.h>
diff --context --recurs m:\bindb32/named/db_reload.c m:\bind/named/db_reload.c
*** m:\bindb32/named/db_reload.c	Mon Dec 25 21:59:13 1995
--- m:\bind/named/db_reload.c	Mon Dec 25 22:05:04 1995
***************
*** 58,69 ****
   * --Copyright--
   */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <stdio.h>
! #include <syslog.h>
  
  #include "named.h"
  
--- 58,73 ----
   * --Copyright--
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <stdio.h>
! #ifndef WINNT
! #include <syslog.h>
! #endif
  
  #include "named.h"
  
diff --context --recurs m:\bindb32/named/db_save.c m:\bind/named/db_save.c
*** m:\bindb32/named/db_save.c	Mon Dec 25 21:59:12 1995
--- m:\bind/named/db_save.c	Mon Dec 25 22:05:05 1995
***************
*** 62,72 ****
   * Buffer allocation and deallocation routines.
   */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <syslog.h>
  #include <stdio.h>
  #include <errno.h>
  
--- 62,76 ----
   * Buffer allocation and deallocation routines.
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #ifndef WINNT
! #include <syslog.h>
! #endif
  #include <stdio.h>
  #include <errno.h>
  
diff --context --recurs m:\bindb32/named/db_secure.c m:\bind/named/db_secure.c
*** m:\bindb32/named/db_secure.c	Mon Dec 25 21:59:12 1995
--- m:\bind/named/db_secure.c	Mon Dec 25 22:05:05 1995
***************
*** 6,17 ****
  
  #include <stdio.h>
  #include <sys/types.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <syslog.h>
! #include <errno.h>
  
  #include "named.h"
  
--- 6,22 ----
  
  #include <stdio.h>
  #include <sys/types.h>
! #ifndef WINNT
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #ifndef WINNT
! #include <syslog.h>
! #include <errno.h>
! 
! #endif
  
  #include "named.h"
  
diff --context --recurs m:\bindb32/named/db_update.c m:\bind/named/db_update.c
*** m:\bindb32/named/db_update.c	Mon Dec 25 21:59:13 1995
--- m:\bind/named/db_update.c	Mon Dec 25 22:05:06 1995
***************
*** 59,69 ****
   */
  
  #include <stdio.h>
! #include <syslog.h>
! 
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
  #include <arpa/inet.h>
  #include <arpa/nameser.h>
  #include <resolv.h>
--- 59,70 ----
   */
  
  #include <stdio.h>
! #ifndef WINNT
! #include <syslog.h>
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
  #include <arpa/inet.h>
  #include <arpa/nameser.h>
  #include <resolv.h>
Only in m:\bind/named: ipaddr.mak
Only in m:\bind/named: ipaddr.vcp
diff --context --recurs m:\bindb32/named/named-xfer.c m:\bind/named/named-xfer.c
*** m:\bindb32/named/named-xfer.c	Mon Dec 25 21:59:13 1995
--- m:\bind/named/named-xfer.c	Mon Dec 25 22:05:08 1995
***************
*** 73,103 ****
  static char rcsid[] = "$Id: named-xfer.c,v 8.10 1995/12/06 20:34:38 vixie Exp $";
  #endif /* not lint */
  
! #include <sys/param.h>
! #include <sys/file.h>
! #include <sys/stat.h>
! #include <sys/socket.h>
! 
! #include <netinet/in.h>
! #if defined(__osf__)
! # include <sys/mbuf.h>
! # include <net/route.h>
  #endif
  #if defined(_AIX)
  # include <sys/time.h>
  # define TIME_H_INCLUDED
  #endif
  #include <net/if.h>
  #include <netdb.h>
  #include <arpa/inet.h>
  #include <arpa/nameser.h>
- 
  #include <errno.h>
  #include <resolv.h>
  #include <stdio.h>
  #include <syslog.h>
  #if !defined(SVR4) || !defined(sun)
! # include <math.h>
  #endif
  #include <ctype.h>
  #include <signal.h>
--- 73,109 ----
  static char rcsid[] = "$Id: named-xfer.c,v 8.10 1995/12/06 20:34:38 vixie Exp $";
  #endif /* not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/file.h>
! #include <sys/stat.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #if defined(__osf__)
! # include <sys/mbuf.h>
! # include <net/route.h>
  #endif
  #if defined(_AIX)
  # include <sys/time.h>
  # define TIME_H_INCLUDED
  #endif
  #include <net/if.h>
+ 
+ #else
+ #include <sys/stat.h>
+ #include <limits.h>
+ #endif /* WINNT */
  #include <netdb.h>
  #include <arpa/inet.h>
  #include <arpa/nameser.h>
  #include <errno.h>
  #include <resolv.h>
  #include <stdio.h>
+ #ifndef WINNT
  #include <syslog.h>
+ #endif
  #if !defined(SVR4) || !defined(sun)
! #include <math.h>
  #endif
  #include <ctype.h>
  #include <signal.h>
***************
*** 110,119 ****
--- 116,135 ----
  # define LOG_PERROR 0
  #endif
  
+ #ifdef WINNT
+ #define exit(x) ExitProcess(x);
+ HANDLE hReadWriteEvent = NULL;
+ char pathtmpxfer[MAX_PATH], pathtmpdir[MAX_PATH];
+ #endif
+ 
  static	struct zoneinfo	zone;		/* zone information */
  
+ #ifndef WINNT
  static	char		ddtfilename[] = _PATH_TMPXFER,
  			*ddtfile = ddtfilename,
+ #else
+ static char	*ddtfile = pathtmpxfer,
+ #endif
  			*tmpname,
  			*domain;		/* domain being xfered */
  
***************
*** 131,137 ****
--- 147,155 ----
  static	int		getzone __P((struct zoneinfo *, u_int32_t, int)),
  			print_output __P((u_char *, int, u_char *)),
  			netread __P((int, char *, int, int));
+ #ifndef WINNT
  static	SIG_FN		read_alarm __P(());
+ #endif
  static	const char	*soa_zinfo __P((struct zoneinfo *, u_char *, u_char*));
  
  extern char *optarg;
***************
*** 145,151 ****
  	register struct zoneinfo *zp;
  	register struct hostent *hp;
   	char *dbfile = NULL, *tracefile = NULL, *tm = NULL;
! 	int dbfd, ddtd, result, c, fd, closed = 0;
  	u_int32_t serial_no = 0;
  	u_int16_t port = htons(NAMESERVER_PORT);
  	struct stat statbuf;
--- 163,172 ----
  	register struct zoneinfo *zp;
  	register struct hostent *hp;
   	char *dbfile = NULL, *tracefile = NULL, *tm = NULL;
! 	int dbfd, ddtd, result, c, closed = 0;
! #ifndef WINNT
! 	int fd;
! #endif
  	u_int32_t serial_no = 0;
  	u_int16_t port = htons(NAMESERVER_PORT);
  	struct stat statbuf;
***************
*** 156,161 ****
--- 177,194 ----
  	int class = C_IN;
  #endif
  
+ #ifdef WINNT
+  	WORD wVersionRequested;
+ 	WSADATA wsaData;
+ 
+ 	wVersionRequested = MAKEWORD(1,1);
+ 	if (WSAStartup(wVersionRequested, &wsaData)) {
+ 		syslog(LOG_ERR, "No useable winsock.dll: %m");
+ 		exit(XFER_FAIL); 
+ 	}
+ 
+ #endif
+ 
  	if (ProgName = strrchr(argv[0], '/'))
  		ProgName++;
  	else
***************
*** 163,183 ****
--- 196,229 ----
  
  	(void) umask(022);
  
+ #ifndef WINNT
  	/* this is a hack; closing everything in the parent is hard. */
  	for (fd = getdtablesize()-1;  fd > STDERR_FILENO;  fd--)
  		closed += (close(fd) == 0);
+ #endif
  
  #ifdef RENICE
  	nice(-40);	/* this is the recommended procedure to        */
  	nice(20);	/*   reset the priority of the current process */
  	nice(0);	/*   to "normal" (== 0) - see nice(3)          */
  #endif
+ #ifdef WINNT
+ 	(void) SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
+ 	if (!GetTempPath(MAX_PATH, pathtmpdir))
+ 		syslog(LOG_ERR, "GetTempPath() failed: %m");
+ 	else {
+ 		strcpy(pathtmpxfer, pathtmpdir);
+ 		strcat(pathtmpxfer, _PATH_TMPXFER);
+ 	}
+ #endif
  
+ #ifndef WINNT
  #ifdef LOG_DAEMON
  	openlog(ProgName, LOG_PID|LOG_CONS|LOG_PERROR, LOGFAC);
  #else
  	openlog(ProgName, LOG_PID);
  #endif
+ #endif /* WINNT */
  #ifdef STUBS
  	while ((c = getopt(argc, argv, "C:d:l:s:t:z:f:p:P:qS")) != EOF)
  #else
***************
*** 325,330 ****
--- 371,377 ----
  	 * considers important- if not, the user controlling named with
  	 * signals usually kills us.
  	 */
+ #ifndef WINNT
  	(void) signal(SIGHUP, SIG_IGN);
  #ifdef SIGSYS
  	(void) signal(SIGSYS, SIG_IGN);
***************
*** 345,357 ****
  	(void) signal(SIGEMT, SIG_IGN);
  	(void) signal(SIGFPE, SIG_IGN);
  #endif /* SIGUSR1&&SIGUSR2 */
  
  	dprintf(1, (ddt,
  		    "domain `%s'; file `%s'; serial %lu; closed %d\n",
  		    domain, dbfile, (u_long)serial_no, closed));
  
! 	buildservicelist();
! 	buildprotolist();
  
  	/* init zone data */
   
--- 392,405 ----
  	(void) signal(SIGEMT, SIG_IGN);
  	(void) signal(SIGFPE, SIG_IGN);
  #endif /* SIGUSR1&&SIGUSR2 */
+ #endif /* WINNT */
  
  	dprintf(1, (ddt,
  		    "domain `%s'; file `%s'; serial %lu; closed %d\n",
  		    domain, dbfile, (u_long)serial_no, closed));
  
! 	  buildservicelist();
! 	  buildprotolist();
  
  	/* init zone data */
   
***************
*** 378,394 ****
  	for (;  optind != argc;  optind++) {
  		tm = argv[optind];
  		if (!inet_aton(tm, &zp->z_addr[zp->z_addrcnt])) {
! 			hp = gethostbyname(tm);
  			if (hp == NULL) {
  				syslog(LOG_NOTICE,
  				       "uninterpretable server (%s) for %s\n",
! 				       tm, zp->z_origin);
  				continue;
  			}
! 			bcopy(hp->h_addr,
  			      (char *)&zp->z_addr[zp->z_addrcnt],
  			      INADDRSZ);
  			dprintf(1, (ddt, "Arg: \"%s\"\n", tm));
  		}
  		if (zp->z_addr[zp->z_addrcnt].s_addr == 0) {
  			syslog(LOG_NOTICE,
--- 426,444 ----
  	for (;  optind != argc;  optind++) {
  		tm = argv[optind];
  		if (!inet_aton(tm, &zp->z_addr[zp->z_addrcnt])) {
! 		   hp = gethostbyname(tm);
  			if (hp == NULL) {
  				syslog(LOG_NOTICE,
  				       "uninterpretable server (%s) for %s\n",
! 				       tm, zp->z_origin); 
! 
  				continue;
  			}
!                   bcopy(hp->h_addr,
  			      (char *)&zp->z_addr[zp->z_addrcnt],
  			      INADDRSZ);
  			dprintf(1, (ddt, "Arg: \"%s\"\n", tm));
+ 
  		}
  		if (zp->z_addr[zp->z_addrcnt].s_addr == 0) {
  			syslog(LOG_NOTICE,
***************
*** 411,417 ****
--- 461,472 ----
  	switch (result) {
  
  	case XFER_SUCCESS:			/* ok exit */
+ #ifndef WINNT
  		if (rename(tmpname, dbfile) == -1) {
+ #else
+ 		/* C run time rename function under NT does not overwrite */
+ 		if(!MoveFileEx(tmpname, dbfile, MOVEFILE_REPLACE_EXISTING)) {
+ #endif
  			perror("rename");
  			if (!quiet)
  			    syslog(LOG_ERR, "rename %s to %s: %m",
***************
*** 475,481 ****
  
  #define DEF_DNAME	'\001'		/* '\0' means the root domain */
  /* XXX: The following variables should probably all be "static" */
! int	minimum_ttl = 0, got_soa = 0;
  int	prev_comment = 0;		/* was previous record a comment? */
  char	zone_top[MAXDNAME];		/* the top of the zone */
  char	prev_origin[MAXDNAME];		/* from most recent $ORIGIN line */
--- 530,537 ----
  
  #define DEF_DNAME	'\001'		/* '\0' means the root domain */
  /* XXX: The following variables should probably all be "static" */
! u_int32_t	minimum_ttl = 0;
! int	got_soa = 0;
  int	prev_comment = 0;		/* was previous record a comment? */
  char	zone_top[MAXDNAME];		/* the top of the zone */
  char	prev_origin[MAXDNAME];		/* from most recent $ORIGIN line */
***************
*** 499,512 ****
  	char name[MAXDNAME], name2[MAXDNAME];
  	struct sockaddr_in sin;
  	struct zoneinfo zp_start, zp_finish;
  #ifdef POSIX_SIGNALS
  	struct sigaction sv, osv;
  #else
  	struct sigvec sv, osv;
  #endif
! 	int qdcount, ancount, aucount, class, type;
  	const char *badsoa_msg = "Nil";
  
  #ifdef DEBUG
  	if (debug) {
  		(void)fprintf(ddt,"getzone() %s ", zp->z_origin);
--- 555,577 ----
  	char name[MAXDNAME], name2[MAXDNAME];
  	struct sockaddr_in sin;
  	struct zoneinfo zp_start, zp_finish;
+ #ifndef WINNT
  #ifdef POSIX_SIGNALS
  	struct sigaction sv, osv;
  #else
  	struct sigvec sv, osv;
  #endif
! #endif
! 	u_short qdcount, ancount, aucount;
! 	int class, type;
  	const char *badsoa_msg = "Nil";
  
+ #ifdef WINNT
+ /* lgk moved startup to beginning.. */
+ 
+ 	hReadWriteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ #endif /* WINNT */
+ 
  #ifdef DEBUG
  	if (debug) {
  		(void)fprintf(ddt,"getzone() %s ", zp->z_origin);
***************
*** 522,527 ****
--- 587,594 ----
  		}
  	}
  #endif
+ 
+ #ifndef WINNT
  #ifdef POSIX_SIGNALS
  	bzero((char *)&sv, sizeof sv);
  	sv.sa_handler = (SIG_FN (*)()) read_alarm;
***************
*** 536,541 ****
--- 603,609 ----
  	sv.sv_mask = ~0;
  	(void) sigvec(SIGALRM, &sv, &osv);
  #endif
+ #endif /* WINNT */
  
  	strcpy(zone_top, zp->z_origin);
  	if ((l = strlen(zone_top)) != 0 && zone_top[l - 1] == '.')
***************
*** 558,563 ****
--- 626,632 ----
  			}
  			bufsize = 2 * PACKETSZ;
  		}
+ 
  		bzero((char *)&sin, sizeof(sin));
  		sin.sin_family = AF_INET;
  		sin.sin_port = (u_int16_t)port;
***************
*** 566,572 ****
  			syslog(LOG_INFO, "socket: %m");
  			error++;
  			break;
! 		}	
  		dprintf(2, (ddt, "connecting to server #%d [%s].%d\n",
  			    cnt+1, inet_ntoa(sin.sin_addr),
  			    ntohs(sin.sin_port)));
--- 635,641 ----
  			syslog(LOG_INFO, "socket: %m");
  			error++;
  			break;
! 		}
  		dprintf(2, (ddt, "connecting to server #%d [%s].%d\n",
  			    cnt+1, inet_ntoa(sin.sin_addr),
  			    ntohs(sin.sin_port)));
***************
*** 590,600 ****
--- 659,671 ----
  				       "zone %s: res_mkquery T_SOA failed",
  				       zp->z_origin);
  			(void) my_close(s);
+ #ifndef WINNT
  #ifdef POSIX_SIGNALS
  			(void) sigaction(SIGALRM, &osv, (struct sigaction *)0);
  #else
  			(void) sigvec(SIGALRM, &osv, (struct sigvec *)0);
  #endif
+ #endif /* WINNT */
  			return (XFER_FAIL);
  		}
  		/*
***************
*** 642,650 ****
  		}
  #endif
  		hp = (HEADER *) buf;
! 		qdcount = ntohs(hp->qdcount);
! 		ancount = ntohs(hp->ancount);
! 		aucount = ntohs(hp->nscount);
  
  		/*
  		 * close socket if any of these apply:
--- 713,721 ----
  		}
  #endif
  		hp = (HEADER *) buf;
! 		qdcount = ntohs( (u_short) hp->qdcount);
! 		ancount = ntohs( (u_short) hp->ancount);
! 		aucount = ntohs( (u_short) hp->nscount);
  
  		/*
  		 * close socket if any of these apply:
***************
*** 791,796 ****
--- 862,868 ----
  							       zp->z_origin);
  						}
  						(void) my_close(s);
+ #ifndef WINNT
  #ifdef POSIX_SIGNALS
  						sigaction(SIGALRM, &osv,
  							(struct sigaction *)0);
***************
*** 798,803 ****
--- 870,876 ----
  						sigvec(SIGALRM, &osv,
  						       (struct sigvec *)0);
  #endif
+ #endif /* WINNT */
  						return (XFER_FAIL);
  					}
  					/*
***************
*** 858,879 ****
  				tmp = cp + n;
  #ifdef STUBS
  			if (zp->z_type == Z_STUB) {
! 				ancount = ntohs(hp->ancount);
! 				for (cnt = 0 ; cnt < ancount ; cnt++) {
  
  					n = print_output(buf, bufsize, cp);
  					cp += n;
  				}
  				if (hp->nscount) {
  					/* we should not get here */
! 					ancount = ntohs(hp->nscount);
! 					for (cnt = 0 ; cnt < ancount ; cnt++) {
  					    n = print_output(buf, bufsize, cp);
  						cp += n;
  					}
  				}
! 				ancount = ntohs(hp->arcount);
! 				for (cnt = 0 ; cnt < ancount ; cnt ++) {
  					n = print_output(buf, bufsize, cp);
  					cp += n;
  				}
--- 931,952 ----
  				tmp = cp + n;
  #ifdef STUBS
  			if (zp->z_type == Z_STUB) {
! 				ancount = ntohs( (u_short) hp->ancount);
! 				for (cnt = 0 ; cnt < (u_int) ancount ; cnt++) {
  
  					n = print_output(buf, bufsize, cp);
  					cp += n;
  				}
  				if (hp->nscount) {
  					/* we should not get here */
! 					ancount = ntohs( (u_short) hp->nscount);
! 					for (cnt = 0 ; cnt < (u_int) ancount ; cnt++) {
  					    n = print_output(buf, bufsize, cp);
  						cp += n;
  					}
  				}
! 				ancount = ntohs( (u_short) hp->arcount);
! 				for (cnt = 0 ; cnt < (u_int) ancount ; cnt ++) {
  					n = print_output(buf, bufsize, cp);
  					cp += n;
  				}
***************
*** 973,979 ****
--- 1046,1057 ----
  					 * and seek to beginning to restart.
  					 */
  					fflush(dbfp);
+ #ifndef WINNT
  					if (ftruncate(fileno(dbfp), 0) != 0) {
+ #else
+ 					if (fseek(dbfp, 0L, SEEK_SET) || 
+ 						!SetEndOfFile((HANDLE)fileno(dbfp))) {
+ #endif
  						if (!quiet)
  						    syslog(LOG_INFO,
  							  "ftruncate %s: %m\n",
***************
*** 993,1004 ****
--- 1071,1084 ----
  		}
  		(void) my_close(s);
  		if (error == 0) {
+ #ifndef WINNT
  #ifdef POSIX_SIGNALS
  			(void) sigaction(SIGALRM, &osv,
  					 (struct sigaction *)0);
  #else
  			(void) sigvec(SIGALRM, &osv, (struct sigvec *)0);
  #endif
+ #endif /* WINNT */
  			return (XFER_SUCCESS);
  		}
  		dprintf(2, (ddt, "error receiving zone transfer\n"));
***************
*** 1018,1028 ****
--- 1098,1110 ----
  		return (XFER_FAIL);
  	    }
  	}
+ #ifndef WINNT
  #ifdef POSIX_SIGNALS
  	(void) sigaction(SIGALRM, &osv, (struct sigaction *)0);
  #else
  	(void) sigvec(SIGALRM, &osv, (struct sigvec *)0);
  #endif
+ #endif /* WINNT */
  	if (error)
  		return (XFER_TIMEOUT);
  	return (XFER_FAIL);
***************
*** 1046,1066 ****
  	int timeout;
  {
  	static const char setitimerStr[] = "setitimer: %m";
- 	struct itimerval ival, zeroival;
  	register int n;
  #if defined(NETREAD_BROKEN)
  	int retries = 0;
  #endif
  
  	memset(&zeroival, 0, sizeof zeroival);
  	ival = zeroival;
  	ival.it_value.tv_sec = timeout;
  	while (len > 0) {
  		if (setitimer(ITIMER_REAL, &ival, NULL) < 0) {
  			syslog(LOG_INFO, setitimerStr);
  			return (-1);
  		}
  		errno = 0;
  		n = recv(fd, buf, len, 0);
  		if (n == 0 && errno == 0) {
  #if defined(NETREAD_BROKEN)
--- 1128,1156 ----
  	int timeout;
  {
  	static const char setitimerStr[] = "setitimer: %m";
  	register int n;
  #if defined(NETREAD_BROKEN)
  	int retries = 0;
  #endif
+ #ifndef WINNT
+ 	struct itimerval ival, zeroival;
  
  	memset(&zeroival, 0, sizeof zeroival);
  	ival = zeroival;
  	ival.it_value.tv_sec = timeout;
+ #else
+ 	int ret;
+ 	struct timeval tvout;
+ 	fd_set fdset;	
+ #endif
  	while (len > 0) {
+ #ifndef WINNT
  		if (setitimer(ITIMER_REAL, &ival, NULL) < 0) {
  			syslog(LOG_INFO, setitimerStr);
  			return (-1);
  		}
  		errno = 0;
+ 		
  		n = recv(fd, buf, len, 0);
  		if (n == 0 && errno == 0) {
  #if defined(NETREAD_BROKEN)
***************
*** 1092,1104 ****
--- 1182,1229 ----
  			syslog(LOG_INFO, "recv(len=%d): %m", len);
  			return (-1);
  		}
+ #else /* WINNT */
+ 		/* our socket is kept nonblocking due to timeout considerations
+ 		 * there are two ways to ensure that a recv on the nonblocking
+ 		 * socket will not return prematurely:
+ 		 * 1) use select() to wait (with timeout) for the socket to be ready
+ 		 * 2) use the ReadFile() win32 API to do asynchronous I/O using
+ 		 *    signalled events (as has been done in writev() implementation
+ 		 * The first is being used here because it will work for Unix
+ 		 * systems also, and some day the setitimer() alarms may be 
+ 		 * replaced by select() to create a single scheme for both
+ 		 * Unix and NT
+ 		 */
+ 		 tvout.tv_sec = timeout;
+ 		 tvout.tv_usec = 0;
+ 		 FD_ZERO(&fdset);
+ 		 FD_SET(fd, &fdset);
+ 		 ret = select(fd+1, &fdset, (fd_set *)0, (fd_set *)0, &tvout);
+ 		 if (ret != SOCKET_ERROR && ret > 0) {
+ 		 	n = recv(fd, buf, len, 0);
+ 			if (n == SOCKET_ERROR)
+ 				if (WSAGetLastError() == WSAEWOULDBLOCK)
+ 					continue;
+ 				else {
+ 					syslog(LOG_INFO, "recv(len=%d): %m", len);
+ 					return (-1);
+ 				}
+ 		 } else {
+ 		 	if (ret == 0)
+ 				WSASetLastError(WSAETIMEDOUT);
+ 			syslog(LOG_INFO, "select error: %m");
+ 			return (-1);
+ 		}
+ #endif /* WINNT */
  		buf += n;
  		len -= n;
  	}
+ #ifndef WINNT
  	if (setitimer(ITIMER_REAL, &zeroival, NULL) < 0) {
  		syslog(LOG_INFO, setitimerStr);
  		return (-1);
  	}
+ #endif
  	return (0);
  }
  
Only in m:\bind/named: named.mak
Only in m:\bind/named: named.mdp
Only in m:\bind/named: named.ncb
Only in m:\bind/named: named.vcp
Only in m:\bind/named: ndc.c
Only in m:\bind/named: ndc.mak
Only in m:\bind/named: ndc.mdp
Only in m:\bind/named: ndc.ncb
Only in m:\bind/named: ndc.vcp
diff --context --recurs m:\bindb32/named/ns_defs.h m:\bind/named/ns_defs.h
*** m:\bindb32/named/ns_defs.h	Mon Dec 25 21:59:12 1995
--- m:\bind/named/ns_defs.h	Mon Dec 25 22:05:10 1995
***************
*** 122,138 ****
  	time_t		z_lastupdate;	/* time of last refresh */
  	u_int32_t	z_refresh;	/* refresh interval */
  	u_int32_t	z_retry;	/* refresh retry interval */
! 	u_int32_t	z_expire;	/* expiration time for cached info */
! 	u_int32_t	z_minimum;	/* minimum TTL value */
! 	u_int32_t	z_serial;	/* changes if zone modified */
! 	char		*z_source;	/* source location of data */
! 	time_t		z_ftime;	/* modification time of source file */
! 	struct in_addr	z_xaddr;	/* override server for next xfer */
! 	struct in_addr	z_addr[NSMAX];	/* list of master servers for zone */
! 	u_char		z_addrcnt;	/* number of entries in z_addr[] */
! 	u_char		z_type;		/* type of zone; see below */
! 	u_int16_t	z_flags;	/* state bits; see below */
  	pid_t		z_xferpid;	/* xfer child pid */
  	int		z_class;	/* class of zone */
  #ifdef SECURE_ZONES
  	struct netinfo *secure_nets;	/* list of secure networks for zone */
--- 122,146 ----
  	time_t		z_lastupdate;	/* time of last refresh */
  	u_int32_t	z_refresh;	/* refresh interval */
  	u_int32_t	z_retry;	/* refresh retry interval */
! #ifndef WINNT
! 	u_int32_t	z_expire;	/* expiration time for cached info */
! #else
! 	int32_t	z_expire;	/* expiration time for cached info */
! #endif
! 	u_int32_t	z_minimum;	/* minimum TTL value Changes */
! 	u_int32_t	z_serial;	/* changes if zone modified */
! 	char		*z_source;	/* source location of data */
! 	time_t		z_ftime;	/* modification time of source file */
! 	struct in_addr	z_xaddr;	/* override server for next xfer */
! 	struct in_addr	z_addr[NSMAX];	/* list of master servers for zone */
! 	u_char		z_addrcnt;	/* number of entries in z_addr[] */
! 	u_char		z_type;		/* type of zone; see below */
! 	u_int16_t	z_flags;	/* state bits; see below */
! #ifndef WINNT
  	pid_t		z_xferpid;	/* xfer child pid */
+ #else
+ 	HANDLE		z_xferpid;	/* handle for thread doing xfer */
+ #endif
  	int		z_class;	/* class of zone */
  #ifdef SECURE_ZONES
  	struct netinfo *secure_nets;	/* list of secure networks for zone */
***************
*** 183,190 ****
--- 191,203 ----
  #define	XFER_SUCCESS	1		/* performed transfer successfully */
  #define	XFER_TIMEOUT	2		/* no server reachable/xfer timeout */
  #define	XFER_FAIL	3		/* other failure, has been logged */
+ #ifdef WINNT
+ #define XFER_KILLED 	4
+ #endif
  
+ #ifndef WINNT
  #include <sys/time.h>
+ #endif
  
  /* XXX - "struct qserv" is deprecated in favor of "struct nameser" */
  struct qserv {
***************
*** 258,264 ****
--- 271,281 ----
  #define	FW_SERVFAIL	3
  
  struct qstream {
+ #ifndef WINNT
  	int		s_rfd;		/* stream file descriptor */
+ #else
+ 	SOCKET	s_rfd;
+ #endif
  	int		s_size;		/* expected amount of data to recive */
  	int		s_bufsize;	/* amount of data recived in s_buf */
  	u_char		*s_buf;		/* buffer of received data */
***************
*** 273,279 ****
--- 290,300 ----
  #define QSTREAM_NULL	((struct qstream *)0)
  
  struct qdatagram {
+ #ifndef WINNT
  	int		dq_dfd;		/* datagram file descriptor */
+ #else
+ 	u_int		dq_dfd;		/* datagram file descriptor */
+ #endif
  	time_t		dq_gen;		/* generation number */
  	struct qdatagram
  			*dq_next;	/* next datagram */
diff --context --recurs m:\bindb32/named/ns_forw.c m:\bind/named/ns_forw.c
*** m:\bindb32/named/ns_forw.c	Mon Dec 25 21:59:13 1995
--- m:\bind/named/ns_forw.c	Mon Dec 25 22:05:11 1995
***************
*** 58,76 ****
   * --Copyright--
   */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
  
! #include <syslog.h>
! #include <resolv.h>
! #include <stdio.h>
! #include <errno.h>
  
  #include "named.h"
  
  /*
   * Forward the query to get the answer since its not in the database.
   * Returns FW_OK if a request struct is allocated and the query sent.
--- 58,87 ----
   * --Copyright--
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
  
! #ifndef WINNT
! #include <syslog.h>
! #else
! #include <stdlib.h>
! #include <search.h>
! #endif
! #include <resolv.h>
! #include <stdio.h>
! #include <errno.h>
  
  #include "named.h"
  
+ #ifdef WINNT
+ int qcomp(const void *, const void *);
+ #endif
+ 
  /*
   * Forward the query to get the answer since its not in the database.
   * Returns FW_OK if a request struct is allocated and the query sent.
***************
*** 350,356 ****
  	register struct namebuf *np;
  	register struct databuf *dp, *nsdp;
  	register struct qserv *qs;
! 	register int n;
  	register unsigned int i;
  	struct hashbuf *tmphtp;
  	char *dname;
--- 361,367 ----
  	register struct namebuf *np;
  	register struct databuf *dp, *nsdp;
  	register struct qserv *qs;
! 	register unsigned int n;
  	register unsigned int i;
  	struct hashbuf *tmphtp;
  	char *dname;
***************
*** 556,563 ****
--- 567,578 ----
  	}
  #endif
  	if (n > 1) {
+ #ifndef WINNT
  		qsort((char *)qp->q_addr, n, sizeof(struct qserv),
  		      (int (*)__P((const void *, const void *)))qcomp);
+ #else
+ 		qsort((char *)qp->q_addr, n, sizeof(struct qserv), qcomp);
+ #endif
  	}
  	return (n - naddr);
  }
diff --context --recurs m:\bindb32/named/ns_func.h m:\bind/named/ns_func.h
*** m:\bindb32/named/ns_func.h	Mon Dec 25 21:59:12 1995
--- m:\bind/named/ns_func.h	Mon Dec 25 22:05:11 1995
***************
*** 105,114 ****
  			loadxfer __P((void)),
  			qserial_query __P((struct zoneinfo *)),
  			qserial_answer __P((struct qinfo *, u_int32_t));
! extern void		holdsigchld __P((void));
! extern void		releasesigchld __P((void));
! extern SIG_FN		reapchild __P(());
! extern void		endxfer __P((void));
  extern const char *	zoneTypeString __P((const struct zoneinfo *));
  #ifdef DEBUG
  extern void		printzoneinfo __P((int));
--- 105,118 ----
  			loadxfer __P((void)),
  			qserial_query __P((struct zoneinfo *)),
  			qserial_answer __P((struct qinfo *, u_int32_t));
! #ifndef WINNT
! extern void		holdsigchld __P((void));
! extern void		releasesigchld __P((void));
! extern SIG_FN		reapchild __P(());
! extern void		endxfer __P((void));
! #else
! extern	void		endxfer __P((DWORD));
! #endif
  extern const char *	zoneTypeString __P((const struct zoneinfo *));
  #ifdef DEBUG
  extern void		printzoneinfo __P((int));
diff --context --recurs m:\bindb32/named/ns_glob.h m:\bind/named/ns_glob.h
*** m:\bindb32/named/ns_glob.h	Mon Dec 25 21:59:12 1995
--- m:\bind/named/ns_glob.h	Mon Dec 25 22:05:12 1995
***************
*** 86,93 ****
  DECL	int			ds		INIT(-1);
  
  	/* listening TCP socket */
! DECL	int			vs		INIT(-1);
! 
  	/* received SIGHUP, need to reload db */
  DECL	int			needreload	INIT(0);
  
--- 86,96 ----
  DECL	int			ds		INIT(-1);
  
  	/* listening TCP socket */
! #ifndef WINNT
! DECL	int			vs		INIT(-1);
! #else
! DECL	int			vs		INIT(INVALID_SOCKET);
! #endif
  	/* received SIGHUP, need to reload db */
  DECL	int			needreload	INIT(0);
  
diff --context --recurs m:\bindb32/named/ns_init.c m:\bind/named/ns_init.c
*** m:\bindb32/named/ns_init.c	Mon Dec 25 21:59:12 1995
--- m:\bind/named/ns_init.c	Mon Dec 25 22:05:12 1995
***************
*** 58,73 ****
   * --Copyright--
   */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <sys/stat.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <syslog.h>
! #include <resolv.h>
! #include <stdio.h>
! #include <errno.h>
  #include <ctype.h>
  #include <assert.h>
  
--- 58,77 ----
   * --Copyright--
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <sys/stat.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #ifndef WINNT
! #include <syslog.h>
! #endif
! #include <resolv.h>
! #include <stdio.h>
! #include <errno.h>
  #include <ctype.h>
  #include <assert.h>
  
***************
*** 100,109 ****
  ns_refreshtime(zp, timebase)
  	struct zoneinfo	*zp;
  	time_t		timebase;
! {
! 	u_long refresh = (zp->z_refresh > 0) ? zp->z_refresh : INIT_REFRESH;
! 	time_t half = (refresh + 1) / 2;
! 
  	zp->z_time = timebase + half + (rand() % half);
  }
  
--- 104,113 ----
  ns_refreshtime(zp, timebase)
  	struct zoneinfo	*zp;
  	time_t		timebase;
!    {
!   	u_long refresh = (zp->z_refresh > 0) ? zp->z_refresh : INIT_REFRESH;
!   	time_t half = (refresh + 1) / 2;
!  
  	zp->z_time = timebase + half + (rand() % half);
  }
  
***************
*** 234,239 ****
--- 238,246 ----
  #ifdef ALLOW_UPDATES
  	char *flag;
  #endif
+ #ifdef WINNT
+ 	extern char *pathtmpdir;
+ #endif
  	int slineno;			/* Saved global line number. */
  	int i;
  
***************
*** 258,264 ****
--- 265,275 ----
  		}
  		if (strcasecmp(buf, "directory") == 0) {
  			(void) getword(buf, sizeof(buf), fp, 0);
+ #ifndef WINNT
  			if (chdir(buf) < 0) {
+ #else
+ 			if (chdir(buf) != TRUE) {
+ #endif
  				syslog(LOG_CRIT, "directory %s: %m\n",
  					buf);
  				exit(1);
***************
*** 574,580 ****
--- 585,595 ----
  				 * We will always transfer this zone again
  				 * after a reload.
  				 */
+ #ifndef WINNT
  				sprintf(buf, "%s/NsTmp%ld.%d", _PATH_TMPDIR,
+ #else
+ 				sprintf(buf, "%sNsTmp%ld.%d", pathtmpdir,
+ #endif
  					(long)getpid(), tmpnum++);
  				source = savestr(buf);
  				zp->z_flags |= Z_TMP_FILE;
diff --context --recurs m:\bindb32/named/ns_main.c m:\bind/named/ns_main.c
*** m:\bindb32/named/ns_main.c	Mon Dec 25 21:59:14 1995
--- m:\bind/named/ns_main.c	Mon Dec 25 22:05:14 1995
***************
*** 70,89 ****
   * Internet Name server (see RCF1035 & others).
   */
  
! #include <sys/param.h>
! #include <sys/file.h>
! #include <sys/stat.h>
! #if !defined(SYSV) && defined(XXX)
! #include <sys/wait.h>
! #endif /* !SYSV */
  #if defined(__osf__)
! # define _SOCKADDR_LEN		/* XXX - should be in portability.h but that
! 				 * would need to be included before socket.h
! 				 */
  #endif
  #include <sys/ioctl.h>
  #include <sys/socket.h>
  #include <netinet/in.h>
  #if defined(__osf__)
  # include <sys/mbuf.h>
  # include <net/route.h>
--- 70,93 ----
   * Internet Name server (see RCF1035 & others).
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/file.h>
! #endif
! #include <sys/stat.h>
! #if !defined(SYSV) && defined(XXX)
! #include <sys/wait.h>
! #endif /* !SYSV */
  #if defined(__osf__)
! # define _SOCKADDR_LEN		/* XXX - should be in portability.h but that
! 				 * would need to be included before socket.h
! 				 */
  #endif
+ #ifndef WINNT
  #include <sys/ioctl.h>
  #include <sys/socket.h>
  #include <netinet/in.h>
+ #endif
  #if defined(__osf__)
  # include <sys/mbuf.h>
  # include <net/route.h>
***************
*** 92,103 ****
--- 96,113 ----
  # include <sys/time.h>
  # define TIME_H_INCLUDED
  #endif
+ #ifndef WINNT
  #include <net/if.h>
+ #else
+ #include "ntif.h" /* hacked version for nt only */
+ #endif
  #include <arpa/nameser.h>
  #include <arpa/inet.h>
  #include <fcntl.h>
  #include <stdio.h>
+ #ifndef WINNT
  #include <syslog.h>
+ #endif
  #include <errno.h>
  #include <signal.h>
  #include <netdb.h>
***************
*** 112,117 ****
--- 122,132 ----
  
  #undef nsaddr
  
+ #ifdef WINNT
+ #include <process.h> 
+ #include "../compat/lib/log.h"
+ #endif
+ 
  				/* UDP receive, TCP send buffer size */
  static	const int		rbufsize = 8 * 1024,
  				/* TCP send window size */
***************
*** 124,129 ****
--- 139,170 ----
  static	char			**Argv = NULL;
  static	char			*LastArg = NULL;	/* end of argv */
  
+ #ifdef WINNT
+ 	/* handles for various threads, process, and objects */
+ 	HANDLE hReadWriteEvent = NULL, hServDoneEvent = NULL, hWorkerThread = NULL;
+ 	/* variables used to inform the Service Control Manager of our current state */
+ 	SERVICE_STATUS ServiceStatus;
+ 	SERVICE_STATUS_HANDLE   hServiceStatus;
+ 	OVERLAPPED overlap; 
+ 	int was_stopped = 0;
+ 	char *pathboot, *pathxfer, *pathdebug,
+ 	 	 *pathdumpfile, *pathpidfile, *pathstats,
+ 	 	 *pathxfertrace, *pathxferddt, *pathtmpdir;
+     CRITICAL_SECTION protected_zp;
+     CRITICAL_SECTION maint_section;
+     /* critical section used to synchronize the named xfers */
+ #define exit(x) { if (hServDoneEvent != NULL) \
+ 						SetEvent(hServDoneEvent);\
+ 				  ExitThread(x); \
+ 				}
+ char szMsgPath[255];
+ #ifdef NOWAIT
+ 	char loopbuf[] = "";
+ 	struct sockaddr_in loopback;
+ #endif
+ #endif /* WINNT */
+ 
+ 
  static	struct qstream		*sqadd __P((void));
  static	void			sq_query __P((struct qstream *)),
  				opensocket __P((struct qdatagram *)),
***************
*** 133,138 ****
--- 174,180 ----
  				setdebug __P((int));
  static	int			sq_here __P((struct qstream *));
  
+ #ifndef WINNT
  static	SIG_FN			onintr __P(()),
  				maint_alarm __P(()),
  				setdumpflg __P(()),
***************
*** 147,152 ****
--- 189,195 ----
  #endif /* SIGSYS */
  				setchkptflg __P(()),
  				setstatsflg __P(());
+ #endif /* WINNT */
  
  static void
  usage()
***************
*** 162,174 ****
  	int argc;
  	char *argv[], *envp[];
  {
! 	register int n, udpcnt;
! 	register char *arg;
  	register struct qstream *sp;
  	register struct qdatagram *dqp;
  	struct qstream *nextsp;
  	int nfds;
- 	const int on = 1;
  	int rfd, size, len;
  	time_t lasttime, maxctime;
  	u_char buf[BUFSIZ];
--- 205,220 ----
  	int argc;
  	char *argv[], *envp[];
  {
!   	register int n;
! 	register char *arg;	
! 	const int on = 1;
! 
! #ifndef WINNT
!     register int udpcnt;
  	register struct qstream *sp;
  	register struct qdatagram *dqp;
  	struct qstream *nextsp;
  	int nfds;
  	int rfd, size, len;
  	time_t lasttime, maxctime;
  	u_char buf[BUFSIZ];
***************
*** 178,189 ****
  #ifndef SYSV
  	struct sigvec vec;
  #endif
! #endif
  #ifdef NeXT
  	int old_sigmask;
  #endif
  	fd_set tmpmask;
! 	struct timeval t, *tp;
  	struct qstream *candidate = QSTREAM_NULL;
  	char **argp;
  #ifdef PID_FIX
--- 224,238 ----
  #ifndef SYSV
  	struct sigvec vec;
  #endif
! #endif 
  #ifdef NeXT
  	int old_sigmask;
  #endif
  	fd_set tmpmask;
! 	struct timeval *tp;
! #endif /* WINNT */
! 
! 	struct timeval t;
  	struct qstream *candidate = QSTREAM_NULL;
  	char **argp;
  #ifdef PID_FIX
***************
*** 196,201 ****
--- 245,275 ----
  	u_char ip_opts[50];		/* arbitrary size */
  #endif
  
+ #ifdef WINNT
+  	WORD wVersionRequested;
+ 	WSADATA wsaData;
+ 
+ 	/* initialize the winsock dll version needed */
+ 	wVersionRequested = MAKEWORD(1,1);
+ 	if (WSAStartup(wVersionRequested, &wsaData)) {
+ 		syslog(LOG_ERR, "No useable winsock.dll: %m");
+ 		return;
+ 	}
+ 
+     /* initialize the critical section */
+    InitializeCriticalSection(&protected_zp);
+    InitializeCriticalSection(&maint_section);
+ 	/* initialize all pathnames */
+ 	expand_paths();
+ 
+        /* lgk add startup code here */
+          /* Set the Event-ID message-file name. */
+           GetCurrentDirectory(sizeof(szMsgPath), szMsgPath);
+           strcat(szMsgPath, "\\named.exe");
+           addSourceToRegistry("DNS", szMsgPath);
+ 
+ #endif /* WINNT */
+ 
  	local_ns_port = ns_port = htons(NAMESERVER_PORT);
  
  	/* BSD has a better random number generator but it's not clear
***************
*** 305,315 ****
--- 379,391 ----
  	if (debug)
  		n = LOG_PERROR;
  #endif
+ #ifndef WINNT
  #ifdef LOG_DAEMON
  	openlog("named", LOG_PID|LOG_CONS|LOG_NDELAY|n, LOGFAC);
  #else
  	openlog("named", LOG_PID);
  #endif
+ #endif /* WINNT */
  
  #ifdef WANT_PIDFILE
  	/* tuck my process id away */
***************
*** 343,349 ****
--- 419,429 ----
  	** Open stream port.
  	*/
  	for (n = 0; ; n++) {
+ #ifndef WINNT
  		if ((vs = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+ #else
+ 		if ((vs = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
+ #endif
  			syslog(LOG_ERR, "socket(SOCK_STREAM): %m");
  			exit(1);
  		}	
***************
*** 386,391 ****
--- 466,472 ----
  		exit(1);
  	}
  
+ #ifndef WINNT
    	/*
  	 * named would be terminated if one of these is sent and no handler.
  	 */
***************
*** 398,403 ****
--- 479,485 ----
  #if defined(SIGWINCH) && defined(QRYLOG)
  	setsignal(SIGWINCH, -1, setQrylogFlg);
  #endif
+ #endif /* WINNT */
  
  	/*
  	 * Get list of local addresses and set up datagram sockets.
***************
*** 423,428 ****
--- 505,511 ----
  	time(&boottime);
  	resettime = boottime;
  
+ #ifndef WINNT
  	setsignal(SIGALRM, SIGCHLD, maint_alarm);
  	setsignal(SIGCHLD, SIGALRM, reapchild);
  	setsignal(SIGPIPE, -1, (SIG_FN (*)())SIG_IGN);
***************
*** 447,452 ****
--- 530,536 ----
          /* Catch SIGTERM so we can write stats before exiting. */
  	setsignal(SIGTERM, -1, onintr);
  #endif
+ #endif /* WINNT */
  
  	dprintf(1, (ddt, "database initialized\n"));
  	t.tv_usec = 0;
***************
*** 456,461 ****
--- 540,546 ----
  	 * we've done any slow initialization
  	 * and are ready to answer queries.
  	 */
+ #ifndef WINNT
  #ifdef USE_SETSID
  	if (
  #ifdef DEBUG
***************
*** 534,539 ****
--- 619,784 ----
  #endif /* HAVE_DAEMON */
  	}
  #endif /* USE_SETSID */
+ 
+ #else /* WINNT */
+ #ifdef DEBUG
+ 	if (!debug)
+ #endif
+ 	{
+ 		SERVICE_TABLE_ENTRY dispatchTable[] = {
+         	{ TEXT("DomainNameService"), (LPSERVICE_MAIN_FUNCTION)service_main },
+         	{ NULL, NULL }
+     	};
+ 
+ 	/* daemonize */
+     	if (!StartServiceCtrlDispatcher(dispatchTable)) {
+ 			if (!was_stopped) {
+ 				syslog(LOG_ERR, "StartServiceCtrlDispatcher: %m");
+ 				ExitProcess(2);
+ 			} else {
+ 				syslog(LOG_INFO, "StartServiceCtrlDispatcher: service stopped");
+ 				ExitProcess(0);
+ 			}
+ 		}
+ 	}
+ #ifdef DEBUG
+ 	else
+ 	   service_main(argc, argv);
+ #endif /* DEBUG */
+ } /* end main */
+ 
+ /*
+  * If this runs as a service under NT, the main thread will block at StartServiceCtrlDispatcher()
+  * and another thread will be started by the Service Control Dispatcher which will begin execution 
+  * at the routine specified in that call (viz. service_main) 
+  */
+ void
+ service_main(argc, argv)
+ 	DWORD argc;
+ 	LPTSTR *argv;
+ {
+ 	DWORD dwWait;
+ 
+ #ifdef DEBUG
+ 	if(!debug) {
+ #endif /* DEBUG */
+ 
+ #ifdef NOWAIT
+ 	loopback.sin_family = AF_INET;
+ 	loopback.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ 	loopback.sin_port = local_ns_port;
+ #endif
+     	/* register our service control handler */
+ 		if (!(hServiceStatus = RegisterServiceCtrlHandler( TEXT("DomainNameService"),
+                         			(LPHANDLER_FUNCTION)service_ctrl))) {
+ 			syslog(LOG_ERR, "RegisterServiceCtrlHandler() failed: %m");
+ 			return;
+ 		}
+ 
+ 		/* report pending status to Service Control Manager */
+ 		ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
+ 		ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
+ 		ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
+ 		ServiceStatus.dwWin32ExitCode = NO_ERROR;
+     	        ServiceStatus.dwServiceSpecificExitCode = 0;
+ 		ServiceStatus.dwCheckPoint = 1;
+ 		ServiceStatus.dwWaitHint = 5000;
+ 		if (!SetServiceStatus(hServiceStatus, &ServiceStatus)) {
+ 			syslog(LOG_ERR, "SetServiceStatus(): %m");
+         	ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ 			SetServiceStatus(hServiceStatus, &ServiceStatus);
+ 			return;
+     	}
+ 
+ 		/* create an event object that the control handler function
+ 	 	* will signal when it receives the "stop" control code */
+ 		if (!(hServDoneEvent = CreateEvent(
+         				NULL,    /* no security attributes */
+         				FALSE,   /* auto-reset event */
+         				FALSE,   /* not-signalled */
+         				NULL))){ /* no name */
+ 				syslog(LOG_ERR, "CreateEvent() failed: %m");
+         		ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ 				SetServiceStatus(hServiceStatus, &ServiceStatus);
+ 				return;
+     	}
+ 
+ 	/* 
+ 	 * the service_main() thread will have to wait for start/stop/pause/continue requests
+ 	 * from the services icon in the Control Panel or from any WIN32 application
+      * start a new thread to perform all the work of the NTP service 
+      */
+         if (!(hWorkerThread = (HANDLE)_beginthread(
+                     worker_thread,
+                     0,       /* stack size			*/
+                     NULL))){    /* argument to thread	*/
+ 			syslog(LOG_ERR, "_beginthread: %m");
+ 			if (hServDoneEvent != NULL)
+ 				CloseHandle(hServDoneEvent);
+         	ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ 			SetServiceStatus(hServiceStatus, &ServiceStatus);
+ 			return;
+ 		}
+ 
+     	/* report to the service control manager that the service is running */
+ 		ServiceStatus.dwCurrentState = SERVICE_RUNNING;
+ 		ServiceStatus.dwWin32ExitCode = NO_ERROR;
+ 		if (!SetServiceStatus(hServiceStatus, &ServiceStatus)) {
+ 			syslog(LOG_ERR, "SetServiceStatus(): %m");
+ 			if (hServDoneEvent != NULL)
+ 				CloseHandle(hServDoneEvent);
+         	ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ 			SetServiceStatus(hServiceStatus, &ServiceStatus);
+ 			return;
+ 		}
+ 
+     	/* wait indefinitely until hServDoneEvent is signaled */
+     	dwWait = WaitForSingleObject(hServDoneEvent,INFINITE);
+ 		if (hServDoneEvent != NULL)
+ 			CloseHandle(hServDoneEvent);
+ 		if (hWorkerThread != NULL)
+ 			CloseHandle(hWorkerThread);
+     	ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ 		SetServiceStatus(hServiceStatus, &ServiceStatus);
+ 		return;
+ 	}
+ #ifdef DEBUG
+ 	else 
+ 	    worker_thread(NULL);
+ #endif /* DEBUG */
+ } /* end service_main() */
+ 
+ 
+ /*
+  * worker_thread - perform all remaining functions after initialization and and becoming a service
+  */
+ void
+ worker_thread(notUsed)
+ 	void *notUsed;
+ {
+ #ifdef WANT_PIDFILE
+ 	FILE *fp;
+ #endif
+ 	register int n, udpcnt;
+ 	register struct qstream *sp;
+ 	register struct qdatagram *dqp;
+ 	struct qstream *nextsp;
+ 	int nfds;
+ 	const int on = 1;
+ 	int size;
+ 	SOCKET rfd;
+ 	time_t lasttime, maxctime;
+ 	u_char buf[BUFSIZ];
+ 	struct timeval t, *tp;
+ 	fd_set tmpmask;
+ 	struct qstream *candidate = QSTREAM_NULL;
+ 
+ 	hReadWriteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ 	overlap.Offset = overlap.OffsetHigh = (DWORD)0;
+ 	overlap.hEvent = hReadWriteEvent;
+ 
+ #endif /* WINNT */
+ 
  #ifdef WANT_PIDFILE
  	/* tuck my process id away again */
  	fp = fopen(PidFile, "w");
***************
*** 591,602 ****
--- 836,857 ----
  			needStatsDump = 0;
  			ns_stats();
  		}
+ // this should never be called from nt as the needendxfer is only set
+ // vai a call to reapchild in ns_maint.c through a signal
  		if (needendxfer) {
+ #ifndef WINNT
  			holdsigchld();
  			needendxfer = 0; /* should be safe even if not held */
  			endxfer(); /* releases SIGCHLD */
+ #else
+                 needendxfer = 0;
+ 		syslog(LOG_ERR, "Needendxfer was Set under Windows NT... Shouldn't happen!");
+ #endif
  		}
+ 
+ #ifndef WINNT 
  		releasesigchld();
+ #endif
  		if (needzoneload) {
  			needzoneload = 0;
  			loadxfer();
***************
*** 638,644 ****
--- 893,903 ----
  #ifdef NeXT
  		old_sigmask = sigblock(sigmask(SIGCHLD));
  #endif
+ #ifndef WINNT
  		if (n < 0 && errno != EINTR) {
+ #else
+ 		if (n < 0 && errno != WSAEINTR) {
+ #endif
  			syslog(LOG_ERR, "select: %m");
  			sleep(60);
  		}
***************
*** 666,671 ****
--- 925,938 ----
  			    }
  			    if (n == 0)
  				break;
+ #if defined(WINNT) && defined(NOWAIT)
+ 				if ((n ==1) && !strcmp(buf, "")) {
+ 				/* dummy packet intended to terminate select
+ 				 * because a control code has been received or
+ 				 * needmaint flag has been set by the timer thread */
+ 					break;
+ 				}
+ #endif
  			    gettime(&tt);
  			    dprintf(1, (ddt,
  			     "\ndatagram from [%s].%d, fd %d, len %d; now %s",
***************
*** 697,705 ****
--- 964,980 ----
  			rfd = accept(vs,
  				     (struct sockaddr *)&from_addr,
  				     &from_len);
+ #ifndef WINNT
  			if (rfd < 0 && errno == EINTR)
+ #else
+ 			if (rfd == INVALID_SOCKET && WSAGetLastError() == WSAEINTR)
+ #endif
  				continue;
+ #ifndef WINNT
  			if (rfd < 0 && errno == EMFILE && streamq) {
+ #else
+ 			if (rfd == INVALID_SOCKET && WSAGetLastError() == WSAEMFILE && streamq) {
+ #endif
  				maxctime = 0;
  				candidate = NULL;
  				for (sp = streamq; sp; sp = nextsp) {
***************
*** 719,728 ****
--- 994,1008 ----
  					sqrm(candidate);
  				continue;
  			}
+ #ifndef WINNT
  			if (rfd < 0) {
+ #else
+ 			if (rfd == INVALID_SOCKET) {
+ #endif
  				syslog(LOG_INFO, "accept: %m");
  				continue;
  			}
+ #ifndef WINNT 
  			if ((n = fcntl(rfd, F_GETFL, 0)) < 0) {
  				syslog(LOG_INFO, "fcntl(rfd, F_GETFL): %m");
  				(void) my_close(rfd);
***************
*** 733,738 ****
--- 1013,1025 ----
  				(void) my_close(rfd);
  				continue;
  			}
+ #else
+ 			if(ioctlsocket(rfd, FIONBIO, (u_long *)&on) == SOCKET_ERROR) {
+ 				syslog(LOG_INFO, "ioctlsocket(rfd, NONBLOCK): %m");
+ 				(void) my_close(rfd);
+ 				continue;
+ 			}
+ #endif
  #if defined(IP_OPTIONS)
  			len = sizeof ip_opts;
  			if (getsockopt(rfd, IPPROTO_IP, IP_OPTIONS,
***************
*** 812,818 ****
--- 1099,1110 ----
  				size = INT16SZ
  				    - (sp->s_bufp - (u_char *)&sp->s_tempsize);
  			        while (size > 0 &&
+ #ifndef WINNT
  			           (n = read(sp->s_rfd, sp->s_bufp, size)) > 0
+ #else
+  			           (n = recv(sp->s_rfd, sp->s_bufp, size, 0)) >0
+ 
+ #endif
  				       ) {
  					sp->s_bufp += n;
  					size -= n;
***************
*** 856,865 ****
--- 1148,1164 ----
  			gettime(&tt);
  			sp->s_time = tt.tv_sec;
  			while (sp->s_size > 0 &&
+ #ifndef WINNT
  			      (n = read(sp->s_rfd,
  					sp->s_bufp,
  					sp->s_size)
  			       ) > 0
+ #else
+ 				  (n = recv(sp->s_rfd,
+ 					sp->s_bufp,
+ 					sp->s_size, 0)
+ 			       ) > 0
+ #endif
  			) {
  				sp->s_bufp += n;
  				sp->s_size -= n;
***************
*** 885,891 ****
--- 1184,1194 ----
  						HFIXEDSZ);
  				continue;
  			}
+ #ifndef WINNT
  			if ((n == -1) && (errno == PORT_WOULDBLK))
+ #else
+ 			if ((n == SOCKET_ERROR) && (errno == PORT_WOULDBLK))
+ #endif
  				continue;
  			if (n <= 0) {
  				sqrm(sp);
***************
*** 928,937 ****
--- 1231,1250 ----
  
  	ifc.ifc_len = sizeof buf;
  	ifc.ifc_buf = buf;
+ #ifndef WINNT /* nt dos not have this functionality so call our new fx */
  	if (ioctl(vs, SIOCGIFCONF, (char *)&ifc) < 0) {
  		syslog(LOG_ERR, "get interface configuration: %m - exiting");
  		exit(1);
  	}
+ #else
+         if (get_winnt_interfaces(&ifc) < 0)
+ 
+          {
+ 	   syslog(LOG_ERR, "get interface configuration: %m - exiting");
+ 	   exit(1);
+ 	}
+ #endif
+ 
  	ntp = NULL;
  #if defined(AF_LINK) && !defined(RISCOS_BSD)
  #define my_max(a, b) (a > b ? a : b)
***************
*** 942,950 ****
  	cplim = buf + ifc.ifc_len;    /* skip over if's with big ifr_addr's */
  	for (cp = buf;
  	     cp < cplim;
  	     cp += sizeof (ifr->ifr_name) + my_size(ifr->ifr_addr)) {
  #undef my_size
! 		ifr = (struct ifreq *)cp;
  		if (ifr->ifr_addr.sa_family != AF_INET ||
  		   ((struct sockaddr_in *)
  		    &ifr->ifr_addr)->sin_addr.s_addr == 0) {
--- 1255,1268 ----
  	cplim = buf + ifc.ifc_len;    /* skip over if's with big ifr_addr's */
  	for (cp = buf;
  	     cp < cplim;
+ #ifndef WINNT
  	     cp += sizeof (ifr->ifr_name) + my_size(ifr->ifr_addr)) {
+ #else
+              
+ 	     cp += sizeof (ifr->ifr_name) + my_size(ifr->ifr_addr) + sizeof(ifr->ifr_mask)) {
+ #endif
  #undef my_size
! 		 ifr = (struct ifreq *)cp;
  		if (ifr->ifr_addr.sa_family != AF_INET ||
  		   ((struct sockaddr_in *)
  		    &ifr->ifr_addr)->sin_addr.s_addr == 0) {
***************
*** 955,969 ****
  		 * Don't test IFF_UP, packets may still be received at this
  		 * address if any other interface is up.
  		 */
! #if !defined(BSD) || (BSD < 199103)
  		if (ioctl(vs, SIOCGIFADDR, (char *)&ifreq) < 0) {
  			syslog(LOG_NOTICE, "get interface addr: %m");
  			continue;
  		}
  #endif
  		dprintf(1, (ddt, "considering [%s]\n",
! 			    inet_ntoa(((struct sockaddr_in *)
  				       &ifreq.ifr_addr)->sin_addr)));
  		/* build datagram queue */
  		/* 
  		 * look for an already existing source interface address.
--- 1273,1288 ----
  		 * Don't test IFF_UP, packets may still be received at this
  		 * address if any other interface is up.
  		 */
! #if (!defined(BSD) || (BSD < 199103)) && !defined(WINNT)
  		if (ioctl(vs, SIOCGIFADDR, (char *)&ifreq) < 0) {
  			syslog(LOG_NOTICE, "get interface addr: %m");
  			continue;
  		}
  #endif
  		dprintf(1, (ddt, "considering [%s]\n",
! 			    inet_ntoa(((struct sockaddr_in *)   
  				       &ifreq.ifr_addr)->sin_addr)));
+ 
  		/* build datagram queue */
  		/* 
  		 * look for an already existing source interface address.
***************
*** 1020,1025 ****
--- 1339,1345 ----
  		}
  		ntp->my_addr = ((struct sockaddr_in *)
  				&ifreq.ifr_addr)->sin_addr;
+ #ifndef WINNT				
  #ifdef SIOCGIFNETMASK
  		if (ioctl(vs, SIOCGIFNETMASK, (char *)&ifreq) < 0) {
  			syslog(LOG_NOTICE, "get netmask: %m");
***************
*** 1031,1040 ****
--- 1351,1368 ----
  		/* 4.2 does not support subnets */
  		ntp->mask = net_mask(ntp->my_addr);
  #endif
+ #else /* nt masks are supported */
+                    ntp->mask = inet_addr(ifreq.ifr_mask);
+ #endif
+ 
+ #ifndef WINNT /* no interface flags on NT */
+ 
  		if (ioctl(vs, SIOCGIFFLAGS, (char *)&ifreq) < 0) {
  			syslog(LOG_NOTICE, "get interface flags: %m");
  			continue;
  		}
+ #endif
+ 
  #ifdef IFF_LOOPBACK
  		if (ifreq.ifr_flags & IFF_LOOPBACK)
  #else
***************
*** 1050,1066 ****
  					    netloop.my_addr.s_addr));
  			}
  			continue;
- 		} else if ((ifreq.ifr_flags & IFF_POINTOPOINT)) {
- 			if (ioctl(vs, SIOCGIFDSTADDR, (char *)&ifreq) < 0) {
- 				syslog(LOG_NOTICE, "get dst addr: %m");
- 				continue;
- 			}
- 			ntp->mask = 0xffffffff;
- 			ntp->addr = ((struct sockaddr_in *)
- 				     &ifreq.ifr_addr)->sin_addr.s_addr;
- 		} else {
- 			ntp->addr = ntp->mask & ntp->my_addr.s_addr;
  		}
  		/*
  		 * Place on end of list of locally-attached (sub)nets,
  		 * but before logical nets for subnetted nets.
--- 1378,1403 ----
  					    netloop.my_addr.s_addr));
  			}
  			continue;
  		}
+ #ifndef WINNT /* no interface flags on NT */
+                      else if ((ifreq.ifr_flags & IFF_POINTOPOINT))
+                             {
+ 			      if (ioctl(vs, SIOCGIFDSTADDR, (char *)&ifreq) < 0)
+                                 {
+ 			    	   syslog(LOG_NOTICE, "get dst addr: %m");
+ 				    continue;
+ 			        }
+ 			      ntp->mask = 0xffffffff;
+ 		  	      ntp->addr = ((struct sockaddr_in *)
+ 			   	          &ifreq.ifr_addr)->sin_addr.s_addr;
+ 			    } else
+                             {
+ 			     ntp->addr = ntp->mask & ntp->my_addr.s_addr;
+ 			    }
+ #else
+ 			     ntp->addr = ntp->mask & ntp->my_addr.s_addr;
+ 
+ #endif
  		/*
  		 * Place on end of list of locally-attached (sub)nets,
  		 * but before logical nets for subnetted nets.
***************
*** 1122,1127 ****
--- 1459,1471 ----
  			enettab = &ontp->next;
  		}
  	}
+ 	/* don't know how to get interface information on multihomed NT
+ 	 * machines. I'm told that gethostbyname(gethostname()) should
+ 	 * return all IP addresses of the local machine (except 127.0.0.1)
+ 	 * but there still remains the question of netmasks and flags etc
+ 	 * This whole issue needs to be addressed more thoroughly.
+ 	 * Implications of this???
+ 	 */
  	first = 0;
  }
  
***************
*** 1189,1194 ****
--- 1533,1539 ----
  				  (char *)&rbufsize, sizeof(rbufsize));
  	}
  #endif /* SO_RCVBUF */
+ #ifndef WINNT
  	if ((n = fcntl(dqp->dq_dfd, F_GETFL, 0)) < 0) {
  		syslog(LOG_NOTICE, "fcntl(dfd, F_GETFL): %m");
  		/* XXX press on regardless, but this really is a problem. */
***************
*** 1196,1201 ****
--- 1541,1551 ----
  		syslog(LOG_NOTICE, "fcntl(dqp->dq_dfd, non-blocking): %m");
  		/* XXX press on regardless, but this really is a problem. */
  	}
+ #else
+ 	if(ioctlsocket(dqp->dq_dfd, FIONBIO, (u_long *)&on) == SOCKET_ERROR) {
+ 		syslog(LOG_NOTICE, "ioctlsocket(dqp->dq_dfd, nonblocking): %m");
+ 	}
+ #endif
  	/*
  	 *   NOTE: Some versions of SunOS have problems with the following
  	 *   call to bind.  Bind still seems to function on these systems
***************
*** 1215,1220 ****
--- 1565,1571 ----
  	FD_SET(dqp->dq_dfd, &mask);
  }
  
+ #ifndef WINNT
  /*
  ** Set flag saying to reload database upon receiving SIGHUP.
  ** Must make sure that someone isn't walking through a data
***************
*** 1294,1302 ****
          needToDoadump = 1;
  	errno = save_errno;
  }
  
  /*
! ** Turn on or off debuging by open or closeing the debug file
  */
  
  static void
--- 1645,1654 ----
          needToDoadump = 1;
  	errno = save_errno;
  }
+ #endif /* WINNT */
  
  /*
! ** Turn on or off debuging by open or closing the debug file
  */
  
  static void
***************
*** 1309,1315 ****
--- 1661,1669 ----
  #ifdef DEBUG
  
  	if (code) {
+ #ifndef WINNT
  		int n;
+ #endif
  
  		ddt = freopen(debugfile, "w+", stderr);
  		if ( ddt == NULL) {
***************
*** 1322,1333 ****
--- 1676,1689 ----
  #else
  			setlinebuf(ddt);
  #endif
+ #ifndef WINNT
  			if ((n = fcntl(fileno(ddt), F_GETFL, 0)) < 0) {
  				syslog(LOG_INFO,
  				       "fcntl(ddt, F_GETFL): %m");
  			} else {
  				(void) fcntl(fileno(ddt), F_SETFL, n|O_APPEND);
  			}
+ #endif /* WINNT */
  		}
  	} else
  		debug = 0;
***************
*** 1335,1340 ****
--- 1691,1697 ----
  #endif
  }
  
+ #ifndef WINNT
  /*
  ** Catch a special signal and set debug level.
  **
***************
*** 1439,1444 ****
--- 1796,1803 ----
  }
  #endif /* SIGSYS */
  
+ #endif /* WINNT */
+ 
  /*
  ** Routines for managing stream queue
  */
***************
*** 1541,1547 ****
  			syslog(LOG_NOTICE, "interface [%s] missing; deleting",
  			       inet_ntoa(this->dq_addr));
  		}
! 		FD_CLR(this->dq_dfd, &mask);
  		my_close(this->dq_dfd);
  		free(this);
  		if (prev == NULL)
--- 1900,1906 ----
  			syslog(LOG_NOTICE, "interface [%s] missing; deleting",
  			       inet_ntoa(this->dq_addr));
  		}
!  		FD_CLR(this->dq_dfd, &mask);
  		my_close(this->dq_dfd);
  		free(this);
  		if (prev == NULL)
***************
*** 1663,1665 ****
--- 2022,2408 ----
  extern char *dn_skipname();
  char *(*hack_skipname)() = dn_skipname;
  #endif
+ 
+ 
+ #ifdef WINNT
+ /* service_ctrl - control handler for NTP service
+  * signals the service_main routine of start/stop requests
+  * from the control panel or other applications making
+  * win32API calls
+  */
+ void
+ service_ctrl(dwCtrlCode)
+ 	DWORD dwCtrlCode;
+ {
+     DWORD  dwState = SERVICE_RUNNING;
+ 	int len;
+ 
+     /* Handle the requested control code */
+     switch(dwCtrlCode) {
+ 
+         case SERVICE_CONTROL_PAUSE:
+ 		/* see no reason to support this */
+ 		break;
+ 
+         case SERVICE_CONTROL_CONTINUE:
+  		/* see no reason to support this */
+   		break;
+ 
+         case SERVICE_CONTROL_STOP:
+             dwState = SERVICE_STOP_PENDING;
+             /* Report the status, specifying the checkpoint and waithint,
+              *  before setting the termination event.
+              */
+ 			ServiceStatus.dwCurrentState = dwState;
+ 			ServiceStatus.dwWin32ExitCode = NO_ERROR;
+ 			ServiceStatus.dwWaitHint = 1000;
+ 			if (!SetServiceStatus(hServiceStatus, &ServiceStatus)) {
+ 				syslog(LOG_ERR, "SetServiceStatus(): %m");
+ 			}
+ 			was_stopped = 1;
+             SetEvent(hServDoneEvent);
+             return;
+ 
+         case SERVICE_CONTROL_INTERROGATE:
+             	/* Update the service status */
+ 			break;
+ 
+         case SERVICE_CONTROL_DUMPDB:
+             needToDoadump = 1;
+ 			break;
+ 
+         case SERVICE_CONTROL_RELOAD:
+ 			needreload = 1;
+ 			break;
+ 
+         case SERVICE_CONTROL_STATS:
+ 			needStatsDump = 1;
+ 			break;
+ 
+         case SERVICE_CONTROL_TRACE:
+ 			debug++;
+ 			if (debug == 1)
+ 				setdebug(1);
+ 			fprintf(ddt, "Debug turned ON, Level %d\n", debug);
+ 			break;
+ 
+         case SERVICE_CONTROL_NOTRACE:
+ 			setdebug(0);
+ 			break;
+ 
+         case SERVICE_CONTROL_QRYLOG:
+ 			qrylog = !qrylog;
+ 			syslog(LOG_NOTICE, "querylog %s\n", qrylog ? "on":"off");
+ 			break;
+ 
+         case SERVICE_CONTROL_CHKPT:
+ 			needToChkpt = 1;
+ 			break;
+ 
+         case SERVICE_CONTROL_EXIT:
+  #ifdef XSTATS
+         	               needToExit = 1;
+  #endif
+         	               was_stopped = 1;	
+                        	break;
+ 
+         default:
+         	/* invalid control code */
+ 			syslog(LOG_ERR, "invalid control code: %d", dwCtrlCode);
+             break;
+ 
+     }
+ 
+ #ifdef NOWAIT
+ 	if((len = sendto(datagramq->dq_dfd, loopbuf, 1, 0, (struct sockaddr *)&loopback,
+ 	          sizeof(struct sockaddr_in))) == SOCKET_ERROR)
+ 		syslog(LOG_ERR, "failed to send the control code immediately: %m");
+  
+ #endif
+ 
+ 	ServiceStatus.dwCurrentState = dwState;
+ 	ServiceStatus.dwWin32ExitCode = NO_ERROR;
+ 	if (!SetServiceStatus(hServiceStatus, &ServiceStatus)) {
+ 		syslog(LOG_ERR, "SetServiceStatus(): %m");
+ 	}
+ }
+ 
+ 
+ /* Expand environmental variables in file pathnames */
+ /* XXX - Would it be better to store/retrieve pathnames from the registry? */
+ void
+ expand_paths(void)
+ {
+   FILE *fp;
+ 
+         /* change name back to named.boot but for backwards compat. this fails go back to the
+            alternate name named.ini... unfort. since bootfile is passed a few layers down it
+            would be a pain to changeall these calls in the stock bind so attempt to open the
+            file here and decide which name to use */
+            
+ 	pathtmpdir = (char *)malloc(MAX_PATH);
+ 	if (!GetTempPath(MAX_PATH, pathtmpdir))
+ 		syslog(LOG_ERR, "GetTempPath() failed: %m");
+ 
+ 	pathboot = (char *)malloc(MAX_PATH);
+ 	if (!ExpandEnvironmentStrings(_PATH_BOOT, pathboot, MAX_PATH)) {
+ 		syslog(LOG_ERR, "ExpandEnvironmentStrings(_PATH_BOOT) failed: %m\n");
+ 	} else
+            {
+ 	     if ((fp = fopen(pathboot, "r")) == NULL)
+ 	       {
+                  /* try alternate name */
+ 
+ 	         if (!ExpandEnvironmentStrings(_ALT_PATH_BOOT, pathboot, MAX_PATH)) {
+ 		   syslog(LOG_ERR, "ExpandEnvironmentStrings(_ALT_PATH_BOOT) failed: %m\n");
+ 	         } else
+ 		   bootfile = pathboot;
+ 	       } /* else it opened ok so close it */
+ 	      else
+                {
+                  fclose(fp);
+                  bootfile = pathboot;
+                }
+            }
+                
+ 	pathpidfile = (char *)malloc(MAX_PATH);
+ 	if (!ExpandEnvironmentStrings(_PATH_PIDFILE, pathpidfile, MAX_PATH)) {
+ 		syslog(LOG_ERR, "ExpandEnvironmentStrings(_PATH_PIDFILE) failed: %m\n");
+ 	} else
+ 		PidFile = pathpidfile;
+ 		 
+ 	pathxfer = (char *)malloc(MAX_PATH);
+ 	if (!ExpandEnvironmentStrings(_PATH_XFER, pathxfer, MAX_PATH)) {
+ 		syslog(LOG_ERR, "ExpandEnvironmentStrings(_PATH_XFER) failed: %m\n");
+ 	}
+ 
+ 	pathdebug = (char *)malloc(MAX_PATH);
+ 	strcpy(pathdebug, pathtmpdir);
+ 	debugfile = strcat(pathdebug, _PATH_DEBUG);
+ 	
+ 	pathdumpfile = (char *)malloc(MAX_PATH);
+ 	strcpy(pathdumpfile, pathtmpdir);
+ 	dumpfile = strcat(pathdumpfile, _PATH_DUMPFILE);
+ 	 
+ 	pathstats = (char *)malloc(MAX_PATH);
+ 	strcpy(pathstats, pathtmpdir);
+ 	statsfile = strcat(pathstats, _PATH_STATS);
+ 	 
+ 	pathxfertrace = (char *)malloc(MAX_PATH);
+ 	strcpy(pathxfertrace, pathtmpdir);
+ 	strcat(pathxfertrace, _PATH_XFERTRACE);
+ 
+ 	pathxferddt = (char *)malloc(MAX_PATH);
+ 	strcpy(pathxferddt, pathtmpdir);
+ 	strcat(pathxferddt, _PATH_XFERDDT);
+ }
+ 
+ 
+ /* new function for nt only l. kahn go through registry and get nt interfaces included masks... ignore wan inteffaces
+    for now */
+    
+   int get_winnt_interfaces(ifc)
+ 
+     struct ifconf *ifc;
+     
+ 
+   {
+         char *ifc_buffer = ifc->ifc_buf;
+ 
+     	struct ifreq *ifr;
+         int maxsize = sizeof(ifc_buffer);
+         HKEY hk, hksub;                      /* registry key handle */
+         BOOL bSuccess;
+         char dummy[100] = "";
+         LONG rvalue;
+         char newkey[200];
+         DWORD dwIndex;
+         LONG cb;
+ 
+         char servicename[50];
+         DWORD sizeofservicename = 50;
+         int Done = 0;
+         
+         /* these need to be big as they are multi_sz in type and hold all ip addresses and subnet mask for a
+            given interface */
+         char IpAddresses[10000];
+         char *ipptr = IpAddresses;
+         DWORD sizeofipaddresses = 10000;
+         char SubNetMasks[10000];
+         char *subptr = SubNetMasks;
+         DWORD sizeofsubnetmasks = 10000;
+ 
+        char oneIpAddress[16];
+        char oneSubNetMask[16];
+        int count = 0;
+ 
+     /* get key for our application */
+     bSuccess = RegOpenKey(HKEY_LOCAL_MACHINE,
+                           "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards",&hk);
+     if(bSuccess != ERROR_SUCCESS)
+     {
+       syslog(LOG_ERR, "failed to Open NetworkCards Registry key: %m");
+       return -1;
+     }
+ 
+     /* now loop through and get all then netcard values */ 
+     dwIndex = 0;       
+     while (1)
+     {
+ 
+         rvalue  = RegEnumKey(hk, dwIndex, dummy,sizeof(dummy));
+         if (rvalue == ERROR_NO_MORE_ITEMS)
+           break;
+         if (rvalue != ERROR_SUCCESS)
+            {
+              syslog(LOG_ERR, "Error in regenumkey fetching network cards info: %m");
+              RegCloseKey(hk);
+              return -1;
+            }
+         if (*dummy == '.')
+           continue; /* no more */
+ 
+           
+         cb = sizeof(dummy);
+         /* now open the subkey */
+         strcpy(newkey,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\");
+         strncat(newkey,dummy,cb);
+         
+         bSuccess = RegOpenKey(HKEY_LOCAL_MACHINE,newkey,&hksub);
+         if(bSuccess != ERROR_SUCCESS)
+          {
+           sprintf(dummy,"failed to open network card key: %s",newkey);
+           syslog(LOG_ERR,dummy);
+           RegCloseKey(hk);
+           return -1;
+          }
+             
+          /* ok now get the servicename parameter  */
+          sizeofservicename = 50;
+          bSuccess = RegQueryValueEx(hksub,  /* subkey handle         */
+          "ServiceName",                     /* value name            */
+           NULL,                             /* must be zero          */
+           NULL,                             /* value type          not required  */
+           (LPBYTE) &servicename,             /* address of value data */
+           &sizeofservicename);   /* length of value data  */
+           if(bSuccess != ERROR_SUCCESS)
+             {
+              syslog(LOG_ERR, "Error in RegQueryValueEx fetching service name parameter: %m");
+              RegCloseKey(hksub);
+              RegCloseKey(hk);
+              return -1;
+         }
+ 
+         /* skip services that are NDISWAN... since these are temporary interfaces like ras and if we bind to these
+            we would have to check if the socket is still ok everytime before using it as when the link goes down
+            and comes back up the socket is no longer any good... and the server eventually crashes if we don't check
+            this.. and to check it entails a lot of overhead... shouldn't be a problem with machines with only a RAS
+            interface anyway as we can bind to the loopback or 0.0.0.0 */
+         if ((strlen(servicename) >= 7) && (strncmp(strupr(servicename),"NDISWAN",7) == 0))
+           {
+             /* skip it */
+ 	        dprintf(1, (ddt, "Skippping temporary interface [%s]\n",servicename));
+             RegCloseKey(hksub);
+           }
+        else {
+   
+         /* if opening this key fails we can assume it is not a network card ie digiboard and go on.. */
+ 
+         /* ok now that we have the service name parameter close the key and go get the ipaddress and subnet mask */
+         RegCloseKey(hksub);
+ 
+         strcpy(newkey,"SYSTEM\\Currentcontrolset\\Services\\");
+         strcat(newkey,servicename);
+         strcat(newkey,"\\parameters\\tcpip");
+        
+         bSuccess = RegOpenKey(HKEY_LOCAL_MACHINE,newkey,&hksub);
+         if(bSuccess != ERROR_SUCCESS)
+          {
+           dprintf(1, (ddt, "Skipping interface [%s] ... It is not a network card.\n",servicename));
+          }
+ 
+          else { /* ok it is a network card */            
+          /* ok now get the ipaddress and subnetmask */
+          sizeofipaddresses = 10000;
+          bSuccess = RegQueryValueEx(hksub,  /* subkey handle         */
+          "IpAddress",                       /* value name            */
+           NULL,                             /* must be zero          */
+           NULL,                             /* value type          not required  */
+           (LPBYTE) &IpAddresses,               /* address of value data */
+           &sizeofipaddresses);                /* length of value data  */
+           if(bSuccess != ERROR_SUCCESS)
+             {
+              syslog(LOG_ERR, "Error in RegQueryValueEx fetching IpAddress parameter: %m");
+              RegCloseKey(hksub);
+              RegCloseKey(hk);
+              return -1;
+             }
+ 
+          /* ok now get the ipaddress and subnetmask */
+          sizeofsubnetmasks = 10000;
+          bSuccess = RegQueryValueEx(hksub,  /* subkey handle         */
+          "SubNetMask",                      /* value name            */
+           NULL,                             /* must be zero          */
+           NULL,                             /* value type          not required  */
+           (LPBYTE) &SubNetMasks,              /* address of value data */
+           &sizeofsubnetmasks);               /* length of value data  */
+           if(bSuccess != ERROR_SUCCESS)
+             {
+              syslog(LOG_ERR, "Error in RegQueryValueEx fetching SubNetMask parameter: %m");
+              RegCloseKey(hksub);
+              RegCloseKey(hk);
+              return -1;
+             }
+ 
+         RegCloseKey(hksub);
+         /* ok now that we have some addresses and subnet masks go through each one and add to our structure... */
+         /* multi_sz strings are terminated by two \0 in a row */
+ 
+         ipptr = IpAddresses;
+         subptr = SubNetMasks;
+         Done = 0;
+         while (!Done)
+         {
+          ifr = (struct ifreq *)ifc_buffer;
+          if (sscanf(ipptr,"%s",oneIpAddress) != EOF)
+            ipptr+= strlen(oneIpAddress) + 1; /* add one for terminator \0 */
+          else Done = 1;
+          
+          if (sscanf(subptr,"%s",oneSubNetMask) != EOF)
+            subptr += strlen(oneSubNetMask) + 1;
+          else Done = 1;
+ 
+          /* now add to interface structure */
+          if (!Done)                  
+           {
+            ifr->ifr_addr.sa_family = AF_INET;
+            ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr = inet_addr(oneIpAddress);
+            strcpy(ifr->ifr_mask,oneSubNetMask);
+ 
+            if (strlen(servicename) > 15)
+              strncpy(ifr->ifr_name,servicename,15);
+            else strcpy(ifr->ifr_name,servicename);
+ 
+            /* now increment pointer */
+ 	       ifc_buffer += sizeof (ifr->ifr_name) + sizeof(ifr->ifr_addr) + sizeof(ifr->ifr_mask);
+            ++count;
+            if (((char *)ipptr == '\0') || ((char *)subptr == '\0')) 
+              Done = 1;
+          }
+           
+         }
+         } /* it is a network card */
+        } /* end of skip WAN interfaces */
+       
+       ++dwIndex;
+     } /* end of loop  */
+ 
+     RegCloseKey(hk);
+     /* now reset the length */
+     ifc->ifc_len = count * (sizeof(ifr->ifr_name) + sizeof(ifr->ifr_addr) + sizeof(ifr->ifr_mask));
+     return 0;
+ }
+ 
+ #endif /* WINNT */
+ 
+ 
diff --context --recurs m:\bindb32/named/ns_maint.c m:\bind/named/ns_maint.c
*** m:\bindb32/named/ns_maint.c	Mon Dec 25 21:59:13 1995
--- m:\bind/named/ns_maint.c	Mon Dec 25 22:05:15 1995
***************
*** 19,34 ****
   *    documentation and/or other materials provided with the distribution.
   * 3. All advertising materials mentioning features or use of this software
   *    must display the following acknowledgement:
!  * 	This product includes software developed by the University of
!  * 	California, Berkeley and its contributors.
!  * 4. Neither the name of the University nor the names of its contributors
!  *    may be used to endorse or promote products derived from this software
!  *    without specific prior written permission.
   * 
!  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
!  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
!  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
!  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
--- 19,34 ----
   *    documentation and/or other materials provided with the distribution.
   * 3. All advertising materials mentioning features or use of this software
   *    must display the following acknowledgement:
!  *      This product includes software developed by the University of
!  *      California, Berkeley and its contributors.
!  * 4. Neither the name of the University nor the names of its contributors
!  *    may be used to endorse or promote products derived from this software
!  *    without specific prior written permission.
   * 
!  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
!  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
!  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
!  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
***************
*** 58,72 ****
--- 58,78 ----
   * --Copyright--
   */
  
+ #ifndef WINNT
  #include <sys/param.h>
  #include <sys/types.h>
  #include <sys/socket.h>
  #include <netinet/in.h>
+ #endif
  #include <arpa/inet.h>
  #include <arpa/nameser.h>
+ #ifndef WINNT
  #include <sys/wait.h>
+ #endif
  #include <stdio.h>
+ #ifndef WINNT
  #include <syslog.h>
+ #endif
  #include <signal.h>
  #include <errno.h>
  #include <sys/stat.h>
***************
*** 74,101 ****
  #include "named.h"
  
  #ifdef USE_UTIME
  # include <utime.h>
  #endif
  
! static int		xfers_running,	/* # of xfers running */
! 			xfers_deferred,	/* # of needed xfers not run yet */
  			qserials_running,
! 			alarm_pending,	/* flag */
  			nxfers __P((struct zoneinfo *, int));
  
! static void		startxfer __P((struct zoneinfo *)),
  			abortxfer __P((struct zoneinfo *)),
  			addxfer __P((struct zoneinfo *)),
  			tryxfer __P((void));
  
! #define	qserial_qfull()	(qserials_running == MAXQSERIAL)
  
  #ifdef CLEANCACHE
! static time_t cache_time;
  #endif
  #ifdef XSTATS
! static time_t stats_time;
  #endif
  /*
   * Invoked at regular intervals by signal interrupt; refresh all secondary
   * zones from primary name server and remove old cache entries.  Also,
--- 80,185 ----
  #include "named.h"
  
  #ifdef USE_UTIME
+ #ifndef WINNT
  # include <utime.h>
+ #else
+ # include <sys/utime.h>
+ #endif
  #endif
  
! static int              xfers_running,  /* # of xfers running */
! 			xfers_deferred, /* # of needed xfers not run yet */
  			qserials_running,
! 			alarm_pending,  /* flag */
  			nxfers __P((struct zoneinfo *, int));
  
! static void             startxfer __P((struct zoneinfo *)),
  			abortxfer __P((struct zoneinfo *)),
  			addxfer __P((struct zoneinfo *)),
  			tryxfer __P((void));
  
! #define qserial_qfull() (qserials_running == MAXQSERIAL)
  
  #ifdef CLEANCACHE
! static time_t cache_time = 0;
  #endif
  #ifdef XSTATS
! static time_t stats_time = 0;
  #endif
+ 
+ #ifdef WINNT
+ /* lgk since timer resolution on nt (at least my box) only goes to 1000 seconds
+  * our method using mmedia times is no good therefore use a thread that
+  * we create that sleeps the timeout period and then when done calls maint_alarm
+  * and exits...
+  * lgk dec. 95 change again to use a waitforsingleobject on an event for the specified
+  * timeout instead of sleep so it can be signaled with a reschedule request..
+  */
+     
+ DWORD pending_delay = 0;
+ volatile HANDLE rescheduleevent = 0x00;
+ DWORD threadid;
+ HANDLE threadhandle = 0x00;
+ static void named_xfer __P((HANDLE *));
+ static void CALLBACK maint_alarm __P((UINT,UINT,DWORD,DWORD,DWORD));
+ extern CRITICAL_SECTION protected_zp;
+ extern CRITICAL_SECTION maint_section;
+ volatile BOOLEAN maint_thread_running = FALSE;
+ PROCESS_INFORMATION *proc_info_copy;
+ 
+ DWORD thread_timer_fx(DWORD timeout)
+   {
+ 
+     DWORD rvalue;
+ 
+     /* now wait on the handle */
+     rvalue = WaitForSingleObject(rescheduleevent,timeout);
+ 
+     /* now check reason we woke up */
+     switch (rvalue)
+      {
+ 
+       case WAIT_FAILED:
+         dprintf(1, (ddt, "Wait for thread timer event object failed!\n")); 
+         syslog(LOG_ERR, "Wait for thread timer event object failed!");
+         EnterCriticalSection(&maint_section);
+         maint_thread_running = FALSE;
+         LeaveCriticalSection(&maint_section);
+         ExitThread(0);
+         break;
+       
+       case WAIT_OBJECT_0:
+         dprintf(1, (ddt, "In Maintenance thread... current thread is exiting for reschedule request!\n"));
+         /* don't set thread running to false here as by the time this gets hit and the
+            thread terminates we may overwrite someone else setting it to true */
+         ExitThread(0);
+         break;
+ 
+       case WAIT_TIMEOUT:
+         dprintf(1, (ddt, "In Maintenance thread... timer has expired!\n"));
+         break;
+       
+       default:
+         dprintf(1, (ddt, "Unknown return type from WaitForSingleObject in thread_timer_fx (%d)!\n",rvalue));
+         syslog(LOG_ERR, "Unknown return type from WaitForSingleObject in thread_timer_fx (%d)!\n",rvalue);
+         EnterCriticalSection(&maint_section);
+         maint_thread_running = FALSE;
+         LeaveCriticalSection(&maint_section);
+         ExitThread(0);
+         break;
+       
+      }
+ 
+     EnterCriticalSection(&maint_section);
+     maint_thread_running = FALSE;
+     LeaveCriticalSection(&maint_section);
+     maint_alarm(0,0,0,0,0);
+     return 0;
+ }
+ 
+ 
+ #endif /* WINNT */
+ 
  /*
   * Invoked at regular intervals by signal interrupt; refresh all secondary
   * zones from primary name server and remove old cache entries.  Also,
***************
*** 109,117 ****
  	int zonenum;
  
  	gettime(&tt);
- 
  	dprintf(1, (ddt, "\nns_maint(); now %s", ctimel(tt.tv_sec)));
- 
  	alarm_pending = 0;
  	for (zp = zones, zonenum = 0; zp < &zones[nzones]; zp++, zonenum++) {
  #ifdef DEBUG
--- 193,199 ----
***************
*** 164,184 ****
  		}
  	}
  #ifdef CLEANCACHE
! 	if ((cache_time + cache_interval) <= tt.tv_sec) {
  		if (cache_time)
! 			remove_zone(hashtab, 0, 0);
  		cache_time = tt.tv_sec;
! 	}
  #endif
  #ifdef XSTATS
! 	if (stats_time + stats_interval <= tt.tv_sec) {
  		if (stats_time)
! 			ns_logstats();
  		stats_time = tt.tv_sec;
! 	}
  #endif
  	if (!needmaint)
! 		sched_maint();
  	dprintf(1, (ddt, "exit ns_maint()\n"));
  }
  
--- 246,269 ----
  		}
  	}
  #ifdef CLEANCACHE
! 	if ((cache_time + cache_interval) <= tt.tv_sec)
! 	  {
  		if (cache_time)
! 		  remove_zone(hashtab, 0, 0);
  		cache_time = tt.tv_sec;
! 	  }
  #endif
  #ifdef XSTATS
!     dprintf(1, (ddt, "\nns_maint(); stats interval is %d\n",stats_interval));
! 	if (stats_time + stats_interval <= tt.tv_sec)
! 	  {
  		if (stats_time)
! 		  ns_logstats();
  		stats_time = tt.tv_sec;
! 	  }
  #endif
  	if (!needmaint)
! 	  sched_maint();
  	dprintf(1, (ddt, "exit ns_maint()\n"));
  }
  
***************
*** 190,212 ****
  sched_maint()
  {
  	register struct zoneinfo *zp;
  	struct itimerval ival;
! #ifdef	CLEANCACHE
  	time_t next_refresh = cache_time + cache_interval;
  #else
  	time_t next_refresh = 0;
  #endif
! 	static time_t next_alarm;
  
  	for (zp = zones; zp < &zones[nzones]; zp++)
  		if (zp->z_time != 0 &&
  		    (next_refresh == 0 || next_refresh > zp->z_time))
  			next_refresh = zp->z_time;
!         /*
  	 *  Schedule the next call to ns_maint.
  	 *  Don't visit any sooner than maint_interval.
  	 */
! 	bzero((char *)&ival, sizeof ival);
  	if (next_refresh != 0) {
  		if (next_refresh == next_alarm && alarm_pending) {
  			dprintf(1, (ddt, "sched_maint: no schedule change\n"));
--- 275,303 ----
  sched_maint()
  {
  	register struct zoneinfo *zp;
+ #ifndef WINNT
  	struct itimerval ival;
! #else
! 	DWORD wDelay;
! #endif
! #ifdef  CLEANCACHE
  	time_t next_refresh = cache_time + cache_interval;
  #else
  	time_t next_refresh = 0;
  #endif
! 	static time_t next_alarm  ;
  
  	for (zp = zones; zp < &zones[nzones]; zp++)
  		if (zp->z_time != 0 &&
  		    (next_refresh == 0 || next_refresh > zp->z_time))
  			next_refresh = zp->z_time;
! 	/*
  	 *  Schedule the next call to ns_maint.
  	 *  Don't visit any sooner than maint_interval.
  	 */
! #ifndef WINNT
! 	bzero((char *)&ival, sizeof (ival));
! #endif
  	if (next_refresh != 0) {
  		if (next_refresh == next_alarm && alarm_pending) {
  			dprintf(1, (ddt, "sched_maint: no schedule change\n"));
***************
*** 218,232 ****
--- 309,377 ----
  		 */
  		if (next_refresh < tt.tv_sec)
  			next_refresh = tt.tv_sec;
+ #ifndef WINNT
  		ival.it_value.tv_sec = next_refresh - tt.tv_sec;
  		if ((long) ival.it_value.tv_sec < maint_interval)
  			ival.it_value.tv_sec = maint_interval;
+ #else
+ 		wDelay = (next_refresh - tt.tv_sec) * 1000;
+ 		if ((long) wDelay < (maint_interval * 1000))
+ 			wDelay = maint_interval * 1000;
+ #endif
  		next_alarm = next_refresh;
  		alarm_pending = 1;
  	}
+ #ifndef WINNT
  	(void) setitimer(ITIMER_REAL, &ival, (struct itimerval *)NULL);
  	dprintf(1, (ddt, "sched_maint: Next interrupt in %lu sec\n",
  		    (u_long)ival.it_value.tv_sec));
+ #else
+       /* lgk under my h/w for nt maximum timer values are 1000 seconds... the above values are not for resolution
+        * as the original author supposed but for the minimum and maximum timer values that mm timers supports..
+        * and since they don't supprt 1 hour... the create of the timer object was failing... therefore the only
+        * way I figured out to do this was create a thread that sleeps for the timeout and then waits up and calls
+        * maint alarm... seems to work ok now... 
+        * lgk dec. 95 change again to use a waitforsingleobject on an event for the specified
+        * timeout instead of sleep so it can be signaled with a reschedule request..
+        */
+ 
+        /* lgk 12/95 there is a problem here were it tries to reschedule
+           when a timer thread is already running... under nt now see comment above */
+ 
+       if (rescheduleevent == 0x00)
+         {
+           if ((rescheduleevent = CreateEvent(NULL,TRUE,FALSE,NULL)) == 0x00)
+             {
+              syslog(LOG_ERR,"Error: Couldn't create the maint. reschedule event object!");
+              dprintf(1, (ddt, "Error: Couldn't create the maint. reschedule event object!"));
+              return;
+             }
+         }
+ 
+       /* first check if already one running */
+       EnterCriticalSection(&maint_section);
+       
+       if (maint_thread_running)
+         { /* ok now check if we have a smaller time */
+           dprintf(1,(ddt,"sched_maint: Rescheduling maint. from %d sec to %d sec.\n",pending_delay/1000,wDelay/1000));
+           /* signal other waiting thread to exit */
+           PulseEvent(rescheduleevent);
+         }
+ 
+        maint_thread_running = TRUE;
+ 
+        if (threadhandle != 0x00)
+          CloseHandle(threadhandle );
+        /* reset the event */
+        ResetEvent(rescheduleevent);   
+ 
+        threadhandle = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread_timer_fx,(LPVOID)wDelay,0,&threadid);
+ 
+        pending_delay = wDelay;
+  	   dprintf(1, (ddt, "sched_maint: Next interrupt in %d sec\n",wDelay/1000));
+        LeaveCriticalSection(&maint_section);
+ 
+ #endif
  }
  
  /*
***************
*** 292,298 ****
  	if (!qp) {
  		syslog(LOG_INFO, "qserial_query(%s): sysquery FAILED",
  		       zp->z_origin);
! 		return;		/* XXX - this is bad, we should do something */
  	}
  	qp->q_flags |= Q_ZSERIAL;
  	qp->q_zquery = zp;
--- 437,443 ----
  	if (!qp) {
  		syslog(LOG_INFO, "qserial_query(%s): sysquery FAILED",
  		       zp->z_origin);
! 		return;         /* XXX - this is bad, we should do something */
  	}
  	qp->q_flags |= Q_ZSERIAL;
  	qp->q_zquery = zp;
***************
*** 313,319 ****
  	dprintf(1, (ddt, "qserial_answer(%s, %lu)\n",
  		    zp->z_origin, (u_long)serial));
  	zp->z_flags &= ~Z_QSERIAL;
! 	qp->q_flags &= ~Q_ZSERIAL;	/* keeps us from being called twice */
  	qserials_running--;
  	if (serial == 0) {
  		/* an error occurred, or the query timed out.
--- 458,464 ----
  	dprintf(1, (ddt, "qserial_answer(%s, %lu)\n",
  		    zp->z_origin, (u_long)serial));
  	zp->z_flags &= ~Z_QSERIAL;
! 	qp->q_flags &= ~Q_ZSERIAL;      /* keeps us from being called twice */
  	qserials_running--;
  	if (serial == 0) {
  		/* an error occurred, or the query timed out.
***************
*** 354,359 ****
--- 499,505 ----
  #endif
  #endif /* POSIX_SIGNALS */
  
+ #ifndef WINNT
  void holdsigchld()
  {
  #ifdef POSIX_SIGNALS
***************
*** 380,385 ****
--- 526,532 ----
  #endif /* POSIX_SIGNALS */
  }
  
+ #endif
  	/* State of all running zone transfers */
  static struct {
  	pid_t 	xfer_pid;
***************
*** 404,410 ****
  	struct zoneinfo *zp;
  {
  	static char *argv[NSMAX + 20], argv_ns[NSMAX][MAXDNAME];
! 	int argc = 0, argc_ns = 0, pid, i;
  	unsigned int cnt;
  	char debug_str[10];
  	char serial_str[10];
--- 551,560 ----
  	struct zoneinfo *zp;
  {
  	static char *argv[NSMAX + 20], argv_ns[NSMAX][MAXDNAME];
! 	int argc = 0, argc_ns = 0, i;
! #ifdef WINNT
! 	extern char *pathxferddt, *pathxfertrace;
! #endif
  	unsigned int cnt;
  	char debug_str[10];
  	char serial_str[10];
***************
*** 412,421 ****
  #ifdef GEN_AXFR
  	char class_str[10];
  #endif
  
  	dprintf(1, (ddt, "startxfer() %s\n", zp->z_origin));
  
! 	argv[argc++] = _PATH_XFER;
  	argv[argc++] = "-z";
  	argv[argc++] = zp->z_origin;
  	argv[argc++] = "-f";
--- 562,587 ----
  #ifdef GEN_AXFR
  	char class_str[10];
  #endif
+ #ifdef WINNT
+ 	char *pos;
+ 	DWORD xfer_thread_id;
+ 	PROCESS_INFORMATION xfer_proc;
+ 	STARTUPINFO sui;
+ 	static char CommandLine[NSMAX*(MAXDNAME+1)+20*10];
+ 	HANDLE ppid;
+     
+ 
+ #else
+ 	int pid;
+ #endif
  
  	dprintf(1, (ddt, "startxfer() %s\n", zp->z_origin));
  
! #ifndef WINNT
! 	argv[argc++] = "_PATH_XFER";
! #else
! 	argv[argc++] = "xfer";
! #endif
  	argv[argc++] = "-z";
  	argv[argc++] = zp->z_origin;
  	argv[argc++] = "-f";
***************
*** 428,434 ****
  	sprintf(class_str, "%d", zp->z_class);
  	argv[argc++] = class_str;
  #endif
!  	if (zp->z_flags & Z_SYSLOGGED)
  		argv[argc++] = "-q";
  	argv[argc++] = "-P";
  	sprintf(port_str, "%d", ns_port);
--- 594,600 ----
  	sprintf(class_str, "%d", zp->z_class);
  	argv[argc++] = class_str;
  #endif
! 	if (zp->z_flags & Z_SYSLOGGED)
  		argv[argc++] = "-q";
  	argv[argc++] = "-P";
  	sprintf(port_str, "%d", ns_port);
***************
*** 443,452 ****
--- 609,626 ----
  		sprintf(debug_str, "%d", debug);
  		argv[argc++] = debug_str;
  		argv[argc++] = "-l";
+ #ifndef WINNT
  		argv[argc++] = _PATH_XFERDDT;
+ #else
+ 		argv[argc++] = pathxferddt;
+ #endif
  		if (debug > 5) {
  			argv[argc++] = "-t";
+ #ifndef WINNT
  			argv[argc++] = _PATH_XFERTRACE;
+ #else
+ 			argv[argc++] = pathxfertrace;
+ #endif
  		}
  	}
  #endif
***************
*** 474,503 ****
  			argv[argc++] = strcpy(argv_ns[argc_ns++],
  					      inet_ntoa(a));
  		}
!         }
  
  	argv[argc] = 0;
  
  #ifdef DEBUG
  #ifdef ECHOARGS
  	if (debug) {
  		for (i = 0; i < argc; i++) 
  			fprintf(ddt, "Arg %d=%s\n", i, argv[i]);
!         }
  #endif /* ECHOARGS */
  #endif /* DEBUG */
  
  	gettime(&tt);
! 	holdsigchld();
! 	for (i = 0; i < MAX_XFERS_RUNNING; i++) {
! 		if (xferstatus[i].xfer_pid == 0) {
! 			xferstatus[i].xfer_state = XFER_RUNNING;
! 			break;
! 		}
! 	}
  	if ((pid = vfork()) == -1) {
  		syslog(LOG_ERR, "xfer vfork: %m");
! 		releasesigchld();
  		zp->z_time = tt.tv_sec + 10;
  		return;
  	}
--- 648,691 ----
  			argv[argc++] = strcpy(argv_ns[argc_ns++],
  					      inet_ntoa(a));
  		}
! 	}
  
  	argv[argc] = 0;
  
+ #ifdef WINNT
+ 	/* need the arguments in the form of a string not in argv format */
+ 	pos = CommandLine;
+ 	for (i = 0; i < argc; i++) {
+ 		sprintf(pos, argv[i]);
+ 		pos += strlen(pos);
+ 		*pos++ = ' ';
+ 	}
+ 	*pos = '\0';
+ #endif 
+ 
  #ifdef DEBUG
  #ifdef ECHOARGS
  	if (debug) {
  		for (i = 0; i < argc; i++) 
  			fprintf(ddt, "Arg %d=%s\n", i, argv[i]);
! 	}
  #endif /* ECHOARGS */
  #endif /* DEBUG */
  
  	gettime(&tt);
! #ifndef WINNT
!    	holdsigchld();
! #endif
!   	for (i = 0; i < MAX_XFERS_RUNNING; i++) {
!   		if (xferstatus[i].xfer_pid == 0) {
!   			xferstatus[i].xfer_state = XFER_RUNNING;
!   			break;
!   		}
!   	}
! #ifndef WINNT
  	if ((pid = vfork()) == -1) {
  		syslog(LOG_ERR, "xfer vfork: %m");
!   		releasesigchld();
  		zp->z_time = tt.tv_sec + 10;
  		return;
  	}
***************
*** 506,538 ****
  		/* Child. */
  		execv(_PATH_XFER, argv);
  		syslog(LOG_ERR, "can't exec %s: %m", _PATH_XFER);
! 		_exit(XFER_FAIL);	/* Avoid duplicate buffer flushes. */
  	}
! 	/* Parent. */
! 	xferstatus[i].xfer_pid = pid;  /* XXX - small race condition here if we
! 					* can't hold signals */
  	dprintf(1, (ddt, "started xfer child %d\n", pid));
  	zp->z_flags &= ~Z_NEED_XFER;
  	zp->z_flags |= Z_XFER_RUNNING;
! 	zp->z_xferpid = pid;
  	xfers_running++;
  	zp->z_time = tt.tv_sec + MAX_XFER_TIME;
! 	releasesigchld();
  }
  
  const char *
  zoneTypeString(zp)
  	const struct zoneinfo *zp;
  {
! 	static char ret[sizeof "(4294967296?)"];	/* 2^32 */
  
  	switch (zp->z_type) {
! 	case Z_PRIMARY:		return ("primary");
! 	case Z_SECONDARY:	return ("secondary");
  #ifdef STUBS
! 	case Z_STUB:		return ("stub");
  #endif
! 	case Z_CACHE:		return ("cache");
  	default:
  		sprintf(ret, "(%lu?)", (u_long)zp->z_type);
  		return (ret);
--- 694,770 ----
  		/* Child. */
  		execv(_PATH_XFER, argv);
  		syslog(LOG_ERR, "can't exec %s: %m", _PATH_XFER);
! 		_exit(XFER_FAIL);       /* Avoid duplicate buffer flushes. */
  	}
! #else /* WINNT */
! 	bzero((char *)&sui, sizeof(STARTUPINFO));
! 	sui.cb = sizeof(STARTUPINFO);
! 	if (!CreateProcess(NULL, CommandLine, NULL, NULL, FALSE, DETACHED_PROCESS, NULL,
! 					   NULL, &sui, (LPPROCESS_INFORMATION)&xfer_proc)) {
! 			syslog(LOG_ERR, "CreateProcess(): %m");
! 			return;
! 	}
!    if (proc_info_copy == 0x00){
!      proc_info_copy = (PROCESS_INFORMATION *)malloc(sizeof(PROCESS_INFORMATION));
!      }
! 
!   bcopy(&(xfer_proc), proc_info_copy, sizeof(PROCESS_INFORMATION));
!   ppid = xfer_proc.hProcess; 
! 
!     if (!CreateThread(
! 	NULL,                                /* no security attributes  */
! 	0,                                   /* use default stack size  */
! 	(LPTHREAD_START_ROUTINE) named_xfer, /* thread function         */
! 	(LPVOID) proc_info_copy,             /* argument to thread function   */
! 	0,                                   /* use default creation flags    */
! 	(LPDWORD) &xfer_thread_id)) {        /* returns the thread identifier */
! 			syslog(LOG_ERR, "CreateThread(): %m");
! 			return;
! 	}
! #endif /* WINNT */
! 	/* parent */
! #ifdef WINNT
! 	/* probably need a mutex here to synchronize access to zp variables
! 	 * between various endxfer's and startxfer's
! 	 */
!      /* lgk use critical section here for this and in endxfer where this is read */
! 
!     EnterCriticalSection(&protected_zp);
! 	dprintf(1, (ddt, "started xfer child %d\n", ppid));
! 	zp->z_xferpid = ppid;
!   	xferstatus[i].xfer_pid = (long)ppid;
! #else
! 	zp->z_xferpid = pid;
!   	xferstatus[i].xfer_pid = pid;  /* XXX - small race condition here if we
!   					* can't hold signals */
  	dprintf(1, (ddt, "started xfer child %d\n", pid));
+ #endif
  	zp->z_flags &= ~Z_NEED_XFER;
  	zp->z_flags |= Z_XFER_RUNNING;
! 
  	xfers_running++;
  	zp->z_time = tt.tv_sec + MAX_XFER_TIME;
! #ifdef WINNT
!     LeaveCriticalSection(&protected_zp);
! #else
!   	releasesigchld();
! #endif
!     
  }
  
  const char *
  zoneTypeString(zp)
  	const struct zoneinfo *zp;
  {
! 	static char ret[sizeof "(4294967296?)"];        /* 2^32 */
  
  	switch (zp->z_type) {
! 	case Z_PRIMARY:         return ("primary");
! 	case Z_SECONDARY:       return ("secondary");
  #ifdef STUBS
! 	case Z_STUB:            return ("stub");
  #endif
! 	case Z_CACHE:           return ("cache");
  	default:
  		sprintf(ret, "(%lu?)", (u_long)zp->z_type);
  		return (ret);
***************
*** 560,566 ****
  #ifdef GEN_AXFR
  	fprintf(ddt, ", class = %d", zp->z_class);
  #endif
!  	fprintf(ddt, ", type = %s", zoneTypeString(zp));
  	if (zp->z_source)
  		fprintf(ddt,", source = %s\n", zp->z_source);
  	fprintf(ddt, "z_refresh = %lu", (u_long)zp->z_refresh);
--- 792,798 ----
  #ifdef GEN_AXFR
  	fprintf(ddt, ", class = %d", zp->z_class);
  #endif
! 	fprintf(ddt, ", type = %s", zoneTypeString(zp));
  	if (zp->z_source)
  		fprintf(ddt,", source = %s\n", zp->z_source);
  	fprintf(ddt, "z_refresh = %lu", (u_long)zp->z_refresh);
***************
*** 590,596 ****
  #endif
  	register struct hashbuf *htp;
  	register int zone;
! #ifdef	CLEANCACHE
  	register int all;
  #endif
  {
--- 822,828 ----
  #endif
  	register struct hashbuf *htp;
  	register int zone;
! #ifdef  CLEANCACHE
  	register int all;
  #endif
  {
***************
*** 657,666 ****
  
  	dprintf(1, (ddt, "purge_zone(%s,%d)\n", dname, class));
  	if ((np = nlookup(dname, &phtp, &fname, 0)) && dname == fname &&
! 	    !WILDCARD_P(dname)) {
  		for (pdp = NULL, dp = np->n_data; dp != NULL; ) {
  			if (dp->d_class == class)
! 				dp = rm_datum(dp, np, pdp);
  			else {
  				pdp = dp;
  				dp = dp->d_next;
--- 889,898 ----
  
  	dprintf(1, (ddt, "purge_zone(%s,%d)\n", dname, class));
  	if ((np = nlookup(dname, &phtp, &fname, 0)) && dname == fname &&
!   	    !WILDCARD_P(dname)) {
  		for (pdp = NULL, dp = np->n_data; dp != NULL; ) {
  			if (dp->d_class == class)
! 			    dp = rm_datum(dp, np, pdp);
  			else {
  				pdp = dp;
  				dp = dp->d_next;
***************
*** 766,772 ****
  		if (dp->d_zone == 0)
  			continue;
  #ifdef NCACHE
! 		if (dp->d_rcode)	/* this should not occur */
  			continue;
  #endif
  		if (dp->d_type == T_SOA)
--- 998,1004 ----
  		if (dp->d_zone == 0)
  			continue;
  #ifdef NCACHE
! 		if (dp->d_rcode)        /* this should not occur */
  			continue;
  #endif
  		if (dp->d_type == T_SOA)
***************
*** 790,825 ****
  	int ret;
  
  	if (zp->z_xaddr.s_addr)
! 		nsa = zp->z_xaddr;	/* qserial overrode address */
  	else if (!zp->z_addrcnt)
  		return (-1);
  	else
! 		nsa = zp->z_addr[0];	/* first ns holds zone's xfer limit */
  
  	if (!(nsp = nameserFind(nsa, NS_F_INSERT)))
! 		return (-1);		/* probably ENOMEM */
  
  	ret = nsp->xfers;
  	if (delta < 0 && -delta > ret)
! 		return (-1);		/* taking more than we have */
  
  	nsp->xfers += delta;
  	return (ret);
  }
  
  /*
   * Abort an xfer that has taken too long.
   */
  static void
  abortxfer(zp)
  	struct zoneinfo *zp;
! {
  	if (zp->z_flags & (Z_XFER_GONE|Z_XFER_ABORTED)) {
  		int i;
  
  		for (i = 0; i < MAX_XFERS_RUNNING; i++) {
! 			if (xferstatus[i].xfer_pid == zp->z_xferpid) {
! 				xferstatus[i].xfer_pid = 0;
  				xferstatus[i].xfer_state = XFER_IDLE;
  				break;
  			}
--- 1022,1060 ----
  	int ret;
  
  	if (zp->z_xaddr.s_addr)
! 		nsa = zp->z_xaddr;      /* qserial overrode address */
  	else if (!zp->z_addrcnt)
  		return (-1);
  	else
! 		nsa = zp->z_addr[0];    /* first ns holds zone's xfer limit */
  
  	if (!(nsp = nameserFind(nsa, NS_F_INSERT)))
! 		return (-1);            /* probably ENOMEM */
  
  	ret = nsp->xfers;
  	if (delta < 0 && -delta > ret)
! 		return (-1);            /* taking more than we have */
  
  	nsp->xfers += delta;
  	return (ret);
  }
  
+ 
  /*
   * Abort an xfer that has taken too long.
   */
+ 
  static void
  abortxfer(zp)
  	struct zoneinfo *zp;
!    {
! 
  	if (zp->z_flags & (Z_XFER_GONE|Z_XFER_ABORTED)) {
  		int i;
  
  		for (i = 0; i < MAX_XFERS_RUNNING; i++) {
! 			if (xferstatus[i].xfer_pid == (long)zp->z_xferpid) {
! 			    xferstatus[i].xfer_pid = 0;
  				xferstatus[i].xfer_state = XFER_IDLE;
  				break;
  			}
***************
*** 829,849 ****
  			syslog(LOG_WARNING,
  			   "zone transfer timeout for \"%s\"; pid %lu missing",
  			       zp->z_origin, (u_long)zp->z_xferpid);
  		else if (kill(zp->z_xferpid, SIGKILL) == -1)
  			syslog(LOG_WARNING,
  			  "zone transfer timeout for \"%s\"; kill pid %lu: %m",
  			       zp->z_origin, (u_long)zp->z_xferpid);
  		else
  			syslog(LOG_WARNING,
! "zone transfer timeout for \"%s\"; second kill\
! pid %lu - forgetting, processes may accumulate",
! 			       zp->z_origin, (u_long)zp->z_xferpid);
  
  		zp->z_xferpid = 0;
  		xfers_running--;
  		(void)nxfers(zp, -1);
  		zp->z_flags &= ~(Z_XFER_RUNNING|Z_XFER_ABORTED|Z_XFER_GONE);
! 	} else if (kill(zp->z_xferpid, SIGKILL) == -1) {
  		if (errno == ESRCH)
  			/* No warning on first time, it may have just exited */
  			zp->z_flags |= Z_XFER_GONE;
--- 1064,1096 ----
  			syslog(LOG_WARNING,
  			   "zone transfer timeout for \"%s\"; pid %lu missing",
  			       zp->z_origin, (u_long)zp->z_xferpid);
+ #ifndef WINNT
  		else if (kill(zp->z_xferpid, SIGKILL) == -1)
  			syslog(LOG_WARNING,
  			  "zone transfer timeout for \"%s\"; kill pid %lu: %m",
  			       zp->z_origin, (u_long)zp->z_xferpid);
  		else
  			syslog(LOG_WARNING,
!                             "zone transfer timeout for \"%s\"; second kill\
!                              pid %lu - forgetting, processes may accumulate",
! 			     zp->z_origin, (u_long)zp->z_xferpid);
! #else
  
+ else
+  {
+ 	TerminateProcess(zp->z_xferpid, (UINT)XFER_KILLED);
+ 	CloseHandle(zp->z_xferpid);
+  	ns_retrytime(zp, tt.tv_sec);
+  }
+ #endif
  		zp->z_xferpid = 0;
  		xfers_running--;
  		(void)nxfers(zp, -1);
  		zp->z_flags &= ~(Z_XFER_RUNNING|Z_XFER_ABORTED|Z_XFER_GONE);
! 	}
! 
! #ifndef WINNT
!         else if (kill(zp->z_xferpid, SIGKILL) == -1) {
  		if (errno == ESRCH)
  			/* No warning on first time, it may have just exited */
  			zp->z_flags |= Z_XFER_GONE;
***************
*** 859,866 ****
--- 1106,1166 ----
  		       zp->z_origin, (u_long)zp->z_xferpid);
  		zp->z_flags |= Z_XFER_ABORTED;
  	}
+ 	
+ #else
+       else
+           {
+         int i;
+ 	    TerminateProcess(zp->z_xferpid, (UINT)XFER_KILLED);
+ 
+         // clear out the entry in the table
+ 		for (i = 0; i < MAX_XFERS_RUNNING; i++) {
+ 			if (xferstatus[i].xfer_pid == (long)zp->z_xferpid) {
+ 				xferstatus[i].xfer_pid = 0;
+ 				xferstatus[i].xfer_state = XFER_IDLE;
+ 				break;
+ 			}
+ 		}
+ 
+ 
+ 	    CloseHandle(zp->z_xferpid);
+ 	    syslog(LOG_NOTICE,
+ 		"zone transfer timeout for \"%s\"; pid %lu killed",
+ 		zp->z_origin, (u_long)zp->z_xferpid);
+ 		zp->z_flags |= Z_XFER_ABORTED;
+ 	     ns_retrytime(zp, tt.tv_sec);
+ 	     (void) nxfers(zp, -1);
+ 	     xfers_running--;
+ 	  }
+ #endif
+ 	
+    }
+ 
+ 
+ /*
+  * Abort an xfer that has taken too long.
+  */
+ 
+ /* old code static void
+ abortxfer(zp)
+ 	struct zoneinfo *zp;
+ {
+ #ifndef WINNT
+ 	kill(zp->z_xferpid, SIGKILL);
+ #else
+ 	TerminateProcess(zp->z_xferpid, (UINT)XFER_KILLED);
+ 	CloseHandle(zp->z_xferpid);
+ #endif
+ 	syslog(LOG_NOTICE, "zone transfer timeout for \"%s\"; pid %lu killed",
+ 	       zp->z_origin, (u_long)zp->z_xferpid);
+ 	ns_retrytime(zp, tt.tv_sec);
+ 	(void) nxfers(zp, -1);
+ 	xfers_running--;
  }
+ */
+ 
  
+ #ifndef WINNT
  /*
   * SIGCHLD signal handler: process exit of xfer's.
   * (Note: also called when outgoing transfer completes.)
***************
*** 898,936 ****
  	errno = save_errno;
  }
  
  /*
!  * Finish processing of of finished xfers
   */
  void
  endxfer()
  {
!     	register struct zoneinfo *zp;   
! 	int exitstatus, pid, i;
  #if defined(sequent)
  	union wait status;
  #else
  	int status;
  #endif /* sequent */
  
! 	gettime(&tt);
  
! 	for (i = 0; i < MAX_XFERS_RUNNING; i++) {
! 		if (xferstatus[i].xfer_state != XFER_DONE)
! 			continue;
! 		pid = xferstatus[i].xfer_pid;
! 		status = xferstatus[i].xfer_status;
! 		exitstatus = WIFEXITED(status) ?WEXITSTATUS(status) :0;
  
! 		for (zp = zones; zp < &zones[nzones]; zp++) {
  			if (zp->z_xferpid != pid)
  				continue;
  			xfers_running--;
  			(void) nxfers(zp, -1);
  			zp->z_xferpid = 0;
! 			zp->z_flags &=
! 				~(Z_XFER_RUNNING|Z_XFER_ABORTED|Z_XFER_GONE);
  			dprintf(1, (ddt,
! 		 "\nendxfer: child %d zone %s returned status=%d termsig=%d\n",
  				    pid, zp->z_origin, exitstatus,
  				    WIFSIGNALED(status) ?WTERMSIG(status) :-1
  				    )
--- 1198,1286 ----
  	errno = save_errno;
  }
  
+ 
+ #endif
+ 
  /*
!  * SIGCHLD signal handler: process exit of xfer's.
!  * (Note: also called when outgoing transfer completes.)
   */
+ /* the semantics here have changed now we call reapchild when a transfer ends which sets the
+    variable needendxfer... however under nt since there are no signals endxfer is called
+    directly when a transfer ends... therefore we need to clear out the entry here under 
+    nt, also under nt we determine the pid to clear because it is passed in ... lgk */
+ 
+ #ifndef WINNT
  void
  endxfer()
+ #else
+ void
+ endxfer(pid)
+ 	HANDLE pid;
+ #endif
  {
!     register struct zoneinfo *zp;
! #ifndef WINNT   
!  	int exitstatus, pid;
! #else
!     int i;
! 	DWORD exitstatus;
! #endif
! #ifndef WINNT
  #if defined(sequent)
  	union wait status;
  #else
  	int status;
  #endif /* sequent */
+ #endif
  
! gettime(&tt);
  
! // under nt this should not get called unless a transfer has complete or aborted
! #ifndef WINNT
!   	for (i = 0; i < MAX_XFERS_RUNNING; i++) {
!   		if (xferstatus[i].xfer_state != XFER_DONE)
!   			continue;
!   		pid = xferstatus[i].xfer_pid;
!   		status = xferstatus[i].xfer_status;
! 
!     		exitstatus = WIFEXITED(status) ?WEXITSTATUS(status) :0;
! #else
!  
! 	if (!GetExitCodeProcess(pid, &exitstatus))
!           {
! 	    syslog(LOG_ERR, "endxfer: cannot determine return code of the xfer process: %m");
! 	    return;
! 	  }
! #endif /* WINNT */
  
! 		for (zp = zones; zp < &zones[nzones]; zp++)
!                    {
  			if (zp->z_xferpid != pid)
  				continue;
+             // ok found our zone
+ #ifdef WINNT
+             // regardless of how it terminated if under nt clear it out here
+             // first find the entry 
+              
+   	         for (i = 0; i < MAX_XFERS_RUNNING; i++) {
+ 			    if (xferstatus[i].xfer_pid == (long)pid) {
+ 				    xferstatus[i].xfer_status = exitstatus;
+                     xferstatus[i].xfer_state = XFER_IDLE;
+ 			    	xferstatus[i].xfer_pid = 0;
+ 			    	
+ 			   } 
+ 		      }   
+ 		     CloseHandle(zp->z_xferpid);
+ #endif
  			xfers_running--;
  			(void) nxfers(zp, -1);
  			zp->z_xferpid = 0;
!   			zp->z_flags &=
!   				~(Z_XFER_RUNNING|Z_XFER_ABORTED|Z_XFER_GONE);
! #ifndef WINNT
  			dprintf(1, (ddt,
! 		            "\nendxfer: child %d zone %s returned status=%d termsig=%d\n", 
  				    pid, zp->z_origin, exitstatus,
  				    WIFSIGNALED(status) ?WTERMSIG(status) :-1
  				    )
***************
*** 943,948 ****
--- 1293,1299 ----
  				}
  				ns_retrytime(zp, tt.tv_sec);
  			} else {
+ #endif /* WINNT */
  				switch (exitstatus) {
  				case XFER_UPTODATE:
  					markUpToDate(zp);
***************
*** 953,991 ****
  					zp->z_flags |= Z_NEED_RELOAD;
  					zp->z_flags &= ~Z_SYSLOGGED;
  					needzoneload++;
  					break;
  
  				case XFER_TIMEOUT:
  					if (!(zp->z_flags & Z_SYSLOGGED)) {
  						zp->z_flags |= Z_SYSLOGGED;
  						syslog(LOG_NOTICE,
! 		      "zoneref: Masters for secondary zone \"%s\" unreachable",
  						       zp->z_origin);
  					}
  					ns_retrytime(zp, tt.tv_sec);
  					break;
! 
  				default:
  					if (!(zp->z_flags & Z_SYSLOGGED)) {
  						zp->z_flags |= Z_SYSLOGGED;
  						syslog(LOG_NOTICE,
! 					     "named-xfer for \"%s\" exited %d",
! 						       zp->z_origin,
! 						       exitstatus);
  					}
  					/* FALLTHROUGH */
  				case XFER_FAIL:
  					zp->z_flags |= Z_SYSLOGGED;
  					ns_retrytime(zp, tt.tv_sec);
  					break;
! 				}
  				break;
! 			}
! 		}
! 		xferstatus[i].xfer_state = XFER_IDLE;
! 		xferstatus[i].xfer_pid = 0;
! 	}
  	releasesigchld();
  	tryxfer();
  }
  
--- 1304,1352 ----
  					zp->z_flags |= Z_NEED_RELOAD;
  					zp->z_flags &= ~Z_SYSLOGGED;
  					needzoneload++;
+                     dprintf(1, (ddt, "named-xfer for %s ended successfully (child = %d)\n",zp->z_origin,pid));
  					break;
  
  				case XFER_TIMEOUT:
  					if (!(zp->z_flags & Z_SYSLOGGED)) {
  						zp->z_flags |= Z_SYSLOGGED;
  						syslog(LOG_NOTICE,
! 		                      "zoneref: Masters for secondary zone \"%s\" unreachable",
  						       zp->z_origin);
  					}
  					ns_retrytime(zp, tt.tv_sec);
  					break;
! #ifdef WINNT
! 				case XFER_KILLED:
! 					ns_retrytime(zp, tt.tv_sec);
! 					break;
! #endif
  				default:
  					if (!(zp->z_flags & Z_SYSLOGGED)) {
  						zp->z_flags |= Z_SYSLOGGED;
  						syslog(LOG_NOTICE,
! 					         "named-xfer for \"%s\" exited %d",
! 						    zp->z_origin, exitstatus);
  					}
  					/* FALLTHROUGH */
  				case XFER_FAIL:
  					zp->z_flags |= Z_SYSLOGGED;
  					ns_retrytime(zp, tt.tv_sec);
  					break;
! 				} /*switch*/
  				break;
! #ifndef WINNT
! 			} /*if/else*/
! #endif
! 		   } /* inner for */
! 
! #ifndef WINNT
!  	 xferstatus[i].xfer_state = XFER_IDLE;
! 	 xferstatus[i].xfer_pid = 0;
! 	} /* outter for */
! 
  	releasesigchld();
+ #endif
  	tryxfer();
  }
  
***************
*** 1060,1066 ****
   */
  void
  loadxfer() {
!     	register struct zoneinfo *zp;   
  
  	gettime(&tt);
  	for (zp = zones; zp < &zones[nzones]; zp++) {
--- 1421,1427 ----
   */
  void
  loadxfer() {
! 	register struct zoneinfo *zp;   
  
  	gettime(&tt);
  	for (zp = zones; zp < &zones[nzones]; zp++) {
***************
*** 1099,1101 ****
--- 1460,1521 ----
  		tryxfer();
  	}
  }
+ 
+ 
+ #ifdef WINNT
+ void CALLBACK maint_alarm (UINT wTimerID, UINT msg,
+     DWORD dwUser, DWORD dw1, DWORD dw2)
+ {
+ 	int len;
+ 	char loopbuf[] = "";
+ 	    struct sockaddr_in loopback; 
+ 	    needmaint = 1;
+ 	dprintf(1, (ddt, "in maint_alarm ...\n"));
+ 	printf("in maint_alarm ...\n");
+ 
+ #ifdef NOWAIT
+ 	loopback.sin_family = AF_INET;
+ 	loopback.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ 	loopback.sin_port = htons(NAMESERVER_PORT);
+ 	if(len = sendto(datagramq->dq_dfd, loopbuf, 1, 0, (struct sockaddr *)&loopback,
+ 		  sizeof(struct sockaddr_in)) == SOCKET_ERROR)
+ 		{
+ 		syslog(LOG_ERR, "failed to break select for maintenance: %m, maintenance delayed");
+ 		syslog(LOG_ERR, "WSA ERRORCODE WAS: %d", WSAGetLastError());
+ 		}
+ #endif
+ 
+ 
+     UNREFERENCED_PARAMETER(dw1);
+     UNREFERENCED_PARAMETER(dw2);
+     UNREFERENCED_PARAMETER(dwUser);
+     UNREFERENCED_PARAMETER(msg);
+     UNREFERENCED_PARAMETER(wTimerID);
+ }
+ 
+ void
+ named_xfer(PROCESS_INFORMATION *proc_info)
+ {
+ 	DWORD dwWait;
+ 
+ 	dwWait = WaitForSingleObject((*proc_info).hProcess, (DWORD) MAX_XFER_TIME * 1000);
+ 	if ((dwWait == WAIT_FAILED) || (dwWait == WAIT_TIMEOUT)) {
+ 		syslog(LOG_ERR, "WaitForSingleObject() on named-xfer process timed out: %m");
+ 		ExitThread(1);
+ 	}
+ 
+ 	/* probably need a mutex here to synchronize access to zp variables
+ 	 * between various endxfer's and startxfer's
+ 	 */
+     
+     /* lgk new code using critical section to synchronize */
+     EnterCriticalSection(&protected_zp);
+ 	endxfer((*proc_info).hProcess);
+     LeaveCriticalSection(&protected_zp);
+ 
+ 	CloseHandle((*proc_info).hProcess);
+     CloseHandle((*proc_info).hThread);
+ 	free((char *)proc_info);
+ 	 ExitThread(0); 
+ }
+ #endif /* WINNT */
diff --context --recurs m:\bindb32/named/ns_ncache.c m:\bind/named/ns_ncache.c
*** m:\bindb32/named/ns_ncache.c	Mon Dec 25 21:59:14 1995
--- m:\bind/named/ns_ncache.c	Mon Dec 25 22:05:16 1995
***************
*** 6,17 ****
   * implements negative caching
   */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <sys/file.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <syslog.h>
  #include <errno.h>
  #include <stdio.h>
  #include <resolv.h>
--- 6,21 ----
   * implements negative caching
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <sys/file.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #ifndef WINNT
! #include <syslog.h>
! #endif
  #include <errno.h>
  #include <stdio.h>
  #include <resolv.h>
diff --context --recurs m:\bindb32/named/ns_req.c m:\bind/named/ns_req.c
*** m:\bindb32/named/ns_req.c	Mon Dec 25 21:59:12 1995
--- m:\bind/named/ns_req.c	Mon Dec 25 22:05:17 1995
***************
*** 58,73 ****
   * --Copyright--
   */
  
! #include <sys/param.h>
! #include <sys/uio.h>
! #include <sys/file.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <fcntl.h>
! #include <syslog.h>
! #include <errno.h>
  #include <stdio.h>
  #include <resolv.h>
  
--- 58,77 ----
   * --Copyright--
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/uio.h>
! #include <sys/file.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <fcntl.h>
! #ifndef WINNT
! #include <syslog.h>
! #endif
! #include <errno.h>
  #include <stdio.h>
  #include <resolv.h>
  
***************
*** 80,85 ****
--- 84,100 ----
  	u_int16_t	a_class;		/* class for address */
  };
  
+ #ifdef WINNT
+ #define _exit(x) ExitThread(x)
+ struct ntxfr {
+ 	struct qstream *qsp;
+ 	struct namebuf *np;
+ 	u_char *soa;
+ 	int soalen;
+ 	int class;
+ };
+ #endif
+ 
  enum req_action { Finish, Refuse, Return };
  
  static enum req_action	req_query __P((HEADER *hp, u_char **cpp, u_char *eom,
***************
*** 97,110 ****
--- 112,137 ----
  					u_char *msg,struct sockaddr_in *from));
  #endif
  
+ #ifndef WINNT
  static void		fwritemsg __P((FILE *, u_char *, int)),
+ #else
+ static void		fwritemsg __P((SOCKET, u_char *, int)),
+ #endif
  #ifdef DEBUG
  			printSOAdata __P((struct databuf)),
  #endif
+ #ifndef WINNT
  			doaxfr __P((struct namebuf *, FILE *,
  				    struct namebuf *, int)),
+ #else
+ 			doaxfr __P((struct namebuf *, SOCKET,
+ 				    struct namebuf *, int)),
+ #endif
  			startxfr __P((struct qstream *, struct namebuf *,
  				      u_char *, int, int, const char *));
+ #ifdef WINNT
+ static void startxfr_child __P((struct ntxfr *));
+ #endif
  
  #ifdef ALLOW_UPDATES
  static int		InitDynUpdate __P((register HEADER *hp,
***************
*** 267,279 ****
  
  #ifdef DEBUG
  #ifdef SORT_RESPONSE
! 	sortmsgtxt = local(from) == NULL ? "Remote" : "Local";
  #else /*SORT*/
! 	sortmsgtxt = "(not sorting)";
  #endif /*SORT*/
! 	dprintf(1, (ddt, "ns_req: answer -> %s fd=%d id=%d size=%d %s\n",
! 		    sin_ntoa(from), (qsp == QSTREAM_NULL) ? dfd : qsp->s_rfd,
! 		    ntohs(hp->id), cp - msg, sortmsgtxt));
  	if (debug >= 10)
  		fp_nquery(msg, cp - msg, ddt);
  #endif /*DEBUG*/
--- 294,307 ----
  
  #ifdef DEBUG
  #ifdef SORT_RESPONSE
!    	sortmsgtxt = local(from) == NULL ? "Remote" : "Local";
  #else /*SORT*/
!   	sortmsgtxt = "(not sorting)";
  #endif /*SORT*/
!   	dprintf(1, (ddt, "ns_req: answer -> %s fd=%d id=%d size=%d %s\n",
!   		    sin_ntoa(from), (qsp == QSTREAM_NULL) ? dfd : qsp->s_rfd,
!   		    ntohs((u_short)hp->id), cp - msg, sortmsgtxt));
! 
  	if (debug >= 10)
  		fp_nquery(msg, cp - msg, ddt);
  #endif /*DEBUG*/
***************
*** 465,479 ****
  	*dpp = NULL;
  
  	/* valid queries have one question and zero answers */
! 	if ((ntohs(hp->qdcount) != 1)
! 	    || ntohs(hp->ancount) != 0
! 	    || ntohs(hp->nscount) != 0
! 	    || ntohs(hp->arcount) != 0) {
  		dprintf(1, (ddt, "FORMERR Query header counts wrong\n"));
! 		hp->qdcount = htons(0);
! 		hp->ancount = htons(0);
! 		hp->nscount = htons(0);
! 		hp->arcount = htons(0);
  		hp->rcode = FORMERR;
  		return (Finish);
  	}
--- 493,507 ----
  	*dpp = NULL;
  
  	/* valid queries have one question and zero answers */
! 	if ((ntohs((u_short)  hp->qdcount) != 1)
!  	    || ntohs((u_short) hp->ancount) != 0
!  	    || ntohs((u_short) hp->nscount) != 0
!  	    || ntohs((u_short) hp->arcount) != 0) {
  		dprintf(1, (ddt, "FORMERR Query header counts wrong\n"));
!  		hp->qdcount = htons(0);
!  		hp->ancount = htons(0);
!  		hp->nscount = htons(0);
!  		hp->arcount = htons(0);
  		hp->rcode = FORMERR;
  		return (Finish);
  	}
***************
*** 556,562 ****
  
  try_again:
  	dprintf(1, (ddt, "req: nlookup(%s) id %d type=%d class=%d\n",
! 		    dname, ntohs(hp->id), type, class));
  	htp = hashtab;		/* lookup relative to root */
  	if ((anp = np = nlookup(dname, &htp, &fname, 0)) == NULL)
  		fname = "";
--- 584,590 ----
  
  try_again:
  	dprintf(1, (ddt, "req: nlookup(%s) id %d type=%d class=%d\n",
! 		    dname, ntohs((u_short)hp->id), type, class));
  	htp = hashtab;		/* lookup relative to root */
  	if ((anp = np = nlookup(dname, &htp, &fname, 0)) == NULL)
  		fname = "";
***************
*** 694,700 ****
  	*cpp += n;
  	*buflenp -= n;
  	*msglenp += n;
! 	hp->ancount = htons(ntohs(hp->ancount) + (u_int16_t)count);
  	if (fname != dname && type != T_CNAME && type != T_ANY) {
  		if (cname++ >= MAXCNAMES) {
  			dprintf(3, (ddt,
--- 722,728 ----
  	*cpp += n;
  	*buflenp -= n;
  	*msglenp += n;
! 	hp->ancount = htons((u_short)(ntohs((u_short)hp->ancount) + (u_int16_t)count));
  	if (fname != dname && type != T_CNAME && type != T_ANY) {
  		if (cname++ >= MAXCNAMES) {
  			dprintf(3, (ddt,
***************
*** 738,744 ****
--- 766,774 ----
  #endif /*BIND_NOTIFY*/
  	if (type == T_AXFR) {
  		startxfr(qsp, np, msg, *cpp - msg, class, dname);
+ #ifndef WINNT
  		sqrm(qsp);
+ #endif
  		return (Return);
  	}
  
***************
*** 785,791 ****
  				*cpp += n;
  				*buflenp -= n;
  #ifdef ADDAUTH
! 			} else if (ntohs(hp->ancount) != 0) {
  				/* don't add NS records for NOERROR NODATA
  				   as some servers can get confused */
  #ifdef DATUMREFCNT
--- 815,821 ----
  				*cpp += n;
  				*buflenp -= n;
  #ifdef ADDAUTH
! 			} else if (ntohs((u_short)hp->ancount) != 0) {
  				/* don't add NS records for NOERROR NODATA
  				   as some servers can get confused */
  #ifdef DATUMREFCNT
***************
*** 984,998 ****
  
  	nameserIncr(from->sin_addr, nssRcvdIQ);
  
! 	if (ntohs(hp->ancount) != 1
! 	    || ntohs(hp->qdcount) != 0
! 	    || ntohs(hp->nscount) != 0
! 	    || ntohs(hp->arcount) != 0) {
  		dprintf(1, (ddt, "FORMERR IQuery header counts wrong\n"));
! 		hp->qdcount = htons(0);
! 		hp->ancount = htons(0);
! 		hp->nscount = htons(0);
! 		hp->arcount = htons(0);
  		hp->rcode = FORMERR;
  		return (Finish);
  	}
--- 1014,1028 ----
  
  	nameserIncr(from->sin_addr, nssRcvdIQ);
  
! 	if (ntohs((u_short) hp->ancount) != 1
! 	    || ntohs((u_short) hp->qdcount) != 0
! 	    || ntohs((u_short) hp->nscount) != 0
! 	    || ntohs((u_short) hp->arcount) != 0) {
  		dprintf(1, (ddt, "FORMERR IQuery header counts wrong\n"));
!  		hp->qdcount = htons(0);
!  		hp->ancount = htons(0);
!  		hp->nscount = htons(0);
!  		hp->arcount = htons(0);
  		hp->rcode = FORMERR;
  		return (Finish);
  	}
***************
*** 1127,1142 ****
--- 1157,1184 ----
  }
  
  static void
+ #ifndef WINNT
  fwritemsg(rfp, msg, msglen)
  	FILE *rfp;
  	u_char *msg;
  	int msglen;
+ #else
+ fwritemsg(rfd, msg, msglen)
+ 	SOCKET rfd;
+ 	u_char *msg;
+ 	int msglen;
+ #endif
  {
  	u_char len[INT16SZ];
  
  	__putshort(msglen, len);
+ #ifndef WINNT
  	if (fwrite((char *)len, INT16SZ, 1, rfp) != 1 ||
  	    fwrite((char *)msg, msglen, 1, rfp) != 1) {
+ #else
+ 	if (send(rfd, len, INT16SZ, 0) != INT16SZ ||
+ 		send(rfd, msg, msglen, 0) != msglen) {
+ #endif
  		syslog(LOG_ERR, "fwritemsg: %m");
  		_exit(1);
  	}
***************
*** 1587,1593 ****
  		}
  		return (0);
  	}
! 	hp->nscount = htons(ntohs(hp->nscount) + 1);
  	return (n);
  }
  
--- 1629,1635 ----
  		}
  		return (0);
  	}
! 	hp->nscount = htons((u_short)(ntohs((u_short)hp->nscount) + 1));
  	return (n);
  }
  
***************
*** 1602,1612 ****
--- 1644,1662 ----
   * rfp is a stdio file to which output is sent.
   */
  static void
+ #ifndef WINNT
  doaxfr(np, rfp, top, class)
  	register struct namebuf *np;
  	FILE *rfp;
  	struct namebuf *top;
  	int class;		/* Class to transfer */
+ #else
+ doaxfr(np, rfd, top, class)
+ 	register struct namebuf *np;
+ 	SOCKET rfd;
+ 	struct namebuf *top;
+ 	int class;		/* Class to transfer */
+ #endif
  {
  	register struct databuf *dp;
  	register int n;
***************
*** 1650,1656 ****
--- 1700,1710 ----
  		n = make_rr(dname, dp, cp, sizeof(msg)-HFIXEDSZ, 0);
  		if (n < 0)
  			continue;
+ #ifndef WINNT
  		fwritemsg(rfp, msg, n + HFIXEDSZ);
+ #else
+ 		fwritemsg(rfd, msg, n + HFIXEDSZ);
+ #endif
  #ifdef NO_GLUE
  		if ((np != top) || (top->n_dname[0] == '\0')) {
  #endif /*NO_GLUE*/
***************
*** 1708,1714 ****
--- 1762,1772 ----
   			n = make_rr(fname, gdp, cp, sizeof(msg)-HFIXEDSZ, 0);
  			if (n < 0)
  			    continue;
+ #ifndef WINNT
   			fwritemsg(rfp, msg, n + HFIXEDSZ);
+ #else
+  			fwritemsg(rfd, msg, n + HFIXEDSZ);
+ #endif
   		    }
  #ifdef NO_GLUE
  		}
***************
*** 1740,1746 ****
--- 1798,1808 ----
  #endif
  		if ((n = make_rr(dname, dp, cp, sizeof(msg)-HFIXEDSZ, 0)) < 0)
  			continue;
+ #ifndef WINNT
  		fwritemsg(rfp, msg, n + HFIXEDSZ);
+ #else
+ 		fwritemsg(rfd, msg, n + HFIXEDSZ);
+ #endif
  	}
  
  	/* Finally do non-delegated subdomains.  Delegated subdomains
***************
*** 1785,1791 ****
--- 1847,1857 ----
  	while (npp < nppend) {
  		for (np = *npp++; np != NULL; np = np->n_next) {
  		    if (np->n_dname[0] != '\0') { /* don't redo root domain */
+ #ifndef WINNT
  			doaxfr(np, rfp, top, class);
+ #else
+ 			doaxfr(np, rfd, top, class);
+ #endif
  		    }
  		}
  	}
***************
*** 2024,2029 ****
--- 2090,2096 ----
  	int		class;
  	const char	*dname;
  {
+ #ifndef WINNT
  	FILE *rfp;
  	int fdstat;
  	pid_t pid;
***************
*** 2036,2044 ****
--- 2103,2118 ----
  #ifdef SO_LINGER
  	static const struct linger ll = { 1, 120 };
  #endif
+ #else /* WINNT */
+ 	HANDLE xfr_thread_handle;
+ 	struct ntxfr *xfr_child;
+ 	char *xfrbuf;
+ 	DWORD id;	
+ #endif /* WINNT */
  
  	dprintf(5, (ddt, "startxfr()\n"));
  
+ #ifndef WINNT
  	/*
  	 * child does the work while
  	 * the parent continues
***************
*** 2057,2062 ****
--- 2131,2193 ----
  		       dname, sin_ntoa(&qsp->s_from), pid);
  		return;
  	}
+ #else
+ 	if ((xfr_child = (struct ntxfr *)malloc(sizeof(struct ntxfr))) == NULL) {
+ 		syslog(LOG_ERR, "startxfr: malloc: %m");
+ 		return;
+ 	}
+ 	if ((xfrbuf = (u_char *)malloc(BUFSIZ)) == NULL) {
+ 		syslog(LOG_ERR, "startxfr: malloc: %m");
+ 		return;
+ 	}
+ 	xfr_child->qsp = qsp;
+ 	xfr_child->np = np;
+ 	bcopy(soa, xfrbuf, soalen);
+ 	soa[soalen+1] = '\0';
+ 	xfr_child->soa = xfrbuf;
+ 	xfr_child->soalen = soalen;
+ 	xfr_child->class = class;
+ 
+ 	xfr_thread_handle = CreateThread(NULL, 0,
+ 									(LPTHREAD_START_ROUTINE)startxfr_child,
+ 									(LPVOID)xfr_child, 0, &id);
+ 	if(xfr_thread_handle == NULL)
+ 		syslog(LOG_NOTICE, "startxfr(%s -> %s) failing; CreateThread(): %m",
+ 		       dname, sin_ntoa(&qsp->s_from));
+ 	else
+ 		/* probably should store the thread handle and/or thread id
+ 		 * and identify and kill a hung outgoing zone transfer thread
+ 		 */
+ 		syslog(LOG_DEBUG, "zone transfer of \"%s\" to %s (threadId %d)",
+ 		       dname, sin_ntoa(&qsp->s_from), id);
+         /* lgk close errant handle here so we don't get too many */
+         CloseHandle(xfr_thread_handle);
+ 	return;
+ }
+ 
+ static void
+ startxfr_child(pxfr_child)
+ 	struct ntxfr *pxfr_child;
+ {
+ 	DWORD pid;
+ #if defined(HAVE_SETVBUF) && !defined(WINNT)
+ 	char *buf;
+ #endif
+ #ifdef SO_SNDBUF
+ 	static const int sndbuf = XFER_BUFSIZE * 2;
+ #endif
+ #ifdef SO_LINGER
+ 	static const struct linger ll = { 1, 120 };
+ #endif
+ 	struct qstream	*qsp = pxfr_child->qsp;
+ 	struct namebuf	*np = pxfr_child->np;
+ 	u_char		*soa = pxfr_child->soa;
+ 	int		soalen = pxfr_child->soalen;
+ 	int		class = pxfr_child->class;
+ 	int off = 0;
+ 
+ 	pid = GetCurrentThreadId();
+ #endif /* WINNT */
  
  	/*
  	 * Child.
***************
*** 2064,2089 ****
  	 * XXX:	this should be a vfork/exec since on non-copy-on-write
  	 *	systems with huge nameserver images, this is very expensive.
  	 */
  	close(vs);
  	sqflush(/*allbut*/ qsp);
  	dqflush((time_t)0);
  
  #ifdef RENICE
  	nice(-40);  nice(20);  nice(0);		/* back to "normal" */
  #endif
  	dprintf(5, (ddt, "startxfr: child pid %lu\n", (u_long)pid));
  
  	if (!(rfp = fdopen(qsp->s_rfd, "w"))) {
  		syslog(LOG_ERR, "fdopen: %m");
  		_exit(1);
  	}
  	ns_setproctitle("zone XFR to", qsp->s_rfd);
  	if (-1 == (fdstat = fcntl(qsp->s_rfd, F_GETFL, 0))) {
  		syslog(LOG_ERR, "fcntl(F_GETFL): %m");
  		_exit(1);
  	}
  	(void) fcntl(qsp->s_rfd, F_SETFL, fdstat & ~PORT_NONBLOCK);
! #ifdef HAVE_SETVBUF
  	/* some systems (DEC OSF/1, SunOS) don't initialize the stdio buffer
  	 * if all you do between fdopen() and fclose() are fwrite()'s.  even
  	 * on systems where the buffer is correctly set, it is too small.
--- 2195,2235 ----
  	 * XXX:	this should be a vfork/exec since on non-copy-on-write
  	 *	systems with huge nameserver images, this is very expensive.
  	 */
+ #ifndef WINNT
  	close(vs);
  	sqflush(/*allbut*/ qsp);
  	dqflush((time_t)0);
+ #endif
  
  #ifdef RENICE
  	nice(-40);  nice(20);  nice(0);		/* back to "normal" */
  #endif
+ #ifdef WINNT
+ 	(void) SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
+ #endif
  	dprintf(5, (ddt, "startxfr: child pid %lu\n", (u_long)pid));
  
+ #ifndef WINNT
  	if (!(rfp = fdopen(qsp->s_rfd, "w"))) {
  		syslog(LOG_ERR, "fdopen: %m");
  		_exit(1);
  	}
+ #endif
  	ns_setproctitle("zone XFR to", qsp->s_rfd);
+ #ifndef WINNT
  	if (-1 == (fdstat = fcntl(qsp->s_rfd, F_GETFL, 0))) {
  		syslog(LOG_ERR, "fcntl(F_GETFL): %m");
  		_exit(1);
  	}
  	(void) fcntl(qsp->s_rfd, F_SETFL, fdstat & ~PORT_NONBLOCK);
! #else
! 	/* set the socket to be blocking again */
! 	if(ioctlsocket(qsp->s_rfd, FIONBIO, (u_long *)&off) == SOCKET_ERROR) {
! 		syslog(LOG_INFO, "ioctlsocket(rfd, BLOCK): %m");
! 		exit(1);
! 	}
! #endif /* WINNT */
! #if defined(HAVE_SETVBUF) && !defined(WINNT)
  	/* some systems (DEC OSF/1, SunOS) don't initialize the stdio buffer
  	 * if all you do between fdopen() and fclose() are fwrite()'s.  even
  	 * on systems where the buffer is correctly set, it is too small.
***************
*** 2103,2112 ****
--- 2249,2270 ----
  	 *	when we fill a 64K DNS/AXFR "message" rather than on each RR.
  	 *	(PVM@ISI gets credit for this idea.)
  	 */
+ #ifndef WINNT
  	fwritemsg(rfp, soa, soalen);
+ #else
+ 	fwritemsg(qsp->s_rfd, soa, soalen);
+ #endif
+ #ifndef WINNT
  	doaxfr(np, rfp, np, class);
+ #else
+ 	doaxfr(np, qsp->s_rfd, np, class);
+ #endif
+ #ifndef WINNT
  	fwritemsg(rfp, soa, soalen);
  	(void) fflush(rfp);
+ #else
+ 	fwritemsg(qsp->s_rfd, soa, soalen);
+ #endif
  #ifdef SO_LINGER
  	/* kernels that map pages for IO end up failing if the pipe is full
  	 * at exit and we take away the final buffer.  this is really a kernel
***************
*** 2114,2122 ****
--- 2272,2291 ----
  	 */
  	setsockopt(qsp->s_rfd, SOL_SOCKET, SO_LINGER,
  		   (char *)&ll, sizeof ll);
+ #ifndef WINNT
  	close(qsp->s_rfd);
+ #else
+ 	sqrm(qsp);
+ #endif /* WINNT */
+ #endif /* SO_LINGER */
+ #ifdef WINNT
+ 	/* endxfer(GetCurrentThread());	*/
  #endif
+ #ifndef WINNT
  	_exit(0);
+ #else
+ 	ExitThread(0);
+ #endif
  	/* NOTREACHED */
  }
  
diff --context --recurs m:\bindb32/named/ns_resp.c m:\bind/named/ns_resp.c
*** m:\bindb32/named/ns_resp.c	Mon Dec 25 21:59:12 1995
--- m:\bind/named/ns_resp.c	Mon Dec 25 22:05:18 1995
***************
*** 58,73 ****
   * --Copyright--
   */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <sys/file.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <syslog.h>
! #include <errno.h>
! #include <stdio.h>
! #include <resolv.h>
  
  #include "named.h"
  
--- 58,77 ----
   * --Copyright--
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <sys/file.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #ifndef WINNT
! #include <syslog.h>
! #endif
! #include <errno.h>
! #include <stdio.h>
! #include <resolv.h>
  
  #include "named.h"
  
***************
*** 186,192 ****
  	struct databuf *nsp[NSMAX];
  	int i, c, n, qdcount, ancount, aucount, nscount, arcount;
  	int qtype, qclass, dbflags;
! 	int restart;	/* flag for processing cname response */
  	int validanswer;
  	int cname;
  	int count, founddata, foundname;
--- 190,196 ----
  	struct databuf *nsp[NSMAX];
  	int i, c, n, qdcount, ancount, aucount, nscount, arcount;
  	int qtype, qclass, dbflags;
! 	int restart; /* flag for processing cname response */
  	int validanswer;
  	int cname;
  	int count, founddata, foundname;
***************
*** 210,216 ****
  #endif
  	hp = (HEADER *) msg;
  	if ((qp = qfindid(hp->id)) == NULL ) {
! 		dprintf(1, (ddt, "DUP? dropped (id %d)\n", ntohs(hp->id)));
  		nameserIncr(from_addr.sin_addr, nssRcvdDupR);
  		return;
  	}
--- 214,220 ----
  #endif
  	hp = (HEADER *) msg;
  	if ((qp = qfindid(hp->id)) == NULL ) {
! 		dprintf(1, (ddt, "DUP? dropped (id %d)\n", ntohs( (u_short) hp->id)));
  		nameserIncr(from_addr.sin_addr, nssRcvdDupR);
  		return;
  	}
***************
*** 224,233 ****
  	/*
  	 * Here we handle high level formatting problems by parsing the header.
  	 */
! 	qdcount = ntohs(hp->qdcount);
! 	ancount = ntohs(hp->ancount);
! 	aucount = ntohs(hp->nscount);	/* !!! */
! 	arcount = ntohs(hp->arcount);
  	free_addinfo();		/* sets addcount to zero */
  	cp = msg + HFIXEDSZ;
  	dpp = dnptrs;
--- 228,237 ----
  	/*
  	 * Here we handle high level formatting problems by parsing the header.
  	 */
! 	qdcount = ntohs( (u_short) hp->qdcount);
! 	ancount = ntohs( (u_short) hp->ancount);
! 	aucount = ntohs( (u_short) hp->nscount);	/* !!! */
! 	arcount = ntohs( (u_short) hp->arcount);
  	free_addinfo();		/* sets addcount to zero */
  	cp = msg + HFIXEDSZ;
  	dpp = dnptrs;
***************
*** 501,506 ****
--- 505,511 ----
  	}
  #endif
  
+ 
  #ifdef LAME_DELEGATION
  	/*
  	 *  Non-authoritative, no answer, no error
***************
*** 688,695 ****
  	restart = 0;
  	validanswer = 0;
  	nscount = 0;
! 	cname = 0;
! 
  	for (i = 0; i < count; i++) {
  		struct databuf *ns3 = NULL;
  		u_char cred;
--- 693,700 ----
  	restart = 0;
  	validanswer = 0;
  	nscount = 0;
!         cname = 0;
! 	
  	for (i = 0; i < count; i++) {
  		struct databuf *ns3 = NULL;
  		u_char cred;
***************
*** 776,782 ****
  				restart = 1;
  		} else {
  #endif
! 		if (i < ancount) {
  			/*
  			 * If there are any non-CNAME RRs (or
  			 * CNAME RRs if they are an acceptable)
--- 781,787 ----
  				restart = 1;
  		} else {
  #endif
! 		if ( i < ancount ) {
  			/*
  			 * If there are any non-CNAME RRs (or
  			 * CNAME RRs if they are an acceptable)
***************
*** 787,794 ****
  			if (type != T_CNAME || qtype == T_CNAME ||
  			    qtype == T_ANY)
  				validanswer = 1;
! 			else
! 				cname = 1;
  		}
  		n = doupdate(msg, msglen, cp, 0, &ns3, dbflags, cred);
  #ifdef VALIDATE
--- 792,799 ----
  			if (type != T_CNAME || qtype == T_CNAME ||
  			    qtype == T_ANY)
  				validanswer = 1;
!   			else
!   				cname = 1;
  		}
  		n = doupdate(msg, msglen, cp, 0, &ns3, dbflags, cred);
  #ifdef VALIDATE
***************
*** 865,871 ****
  	 * An answer to a T_ANY query or a successful answer to a
  	 * regular query with no indirection, then just return answer.
  	 */
! 	if (!restart && ancount && (qtype == T_ANY || !qp->q_cmsglen)) {
  		dprintf(3, (ddt, "resp: got as much answer as there is\n"));
  		goto return_msg;
  	}
--- 870,876 ----
  	 * An answer to a T_ANY query or a successful answer to a
  	 * regular query with no indirection, then just return answer.
  	 */
!    	if (!restart && ancount && (qtype == T_ANY || !qp->q_cmsglen)) {
  		dprintf(3, (ddt, "resp: got as much answer as there is\n"));
  		goto return_msg;
  	}
***************
*** 912,921 ****
  	 * is not cacheable (TTL==0 or unknown RR type), since all of the
  	 * answer must pass through the cache and be re-assembled.
  	 */
! 	if ((!restart || !cname) && qp->q_cmsglen && ancount) {
  		dprintf(1, (ddt, "Cname second pass\n"));
  		newmsglen = qp->q_cmsglen;
! 		bcopy(qp->q_cmsg, newmsg, newmsglen);
  	} else {
  		newmsglen = msglen;
  		bcopy(msg, newmsg, newmsglen);
--- 917,926 ----
  	 * is not cacheable (TTL==0 or unknown RR type), since all of the
  	 * answer must pass through the cache and be re-assembled.
  	 */
!   	if ((!restart || !cname) && qp->q_cmsglen && ancount) {
  		dprintf(1, (ddt, "Cname second pass\n"));
  		newmsglen = qp->q_cmsglen;
!  		bcopy(qp->q_cmsg, newmsg, newmsglen);
  	} else {
  		newmsglen = msglen;
  		bcopy(msg, newmsg, newmsglen);
***************
*** 945,952 ****
  	}
  	cp += n + QFIXEDSZ;
  	buflen = sizeof(newmsg) - (cp - newmsg);
- 
  	cname = 0;
   try_again:
  	dprintf(1, (ddt, "resp: nlookup(%s) qtype=%d\n", dname, qtype));
  	fname = "";
--- 950,957 ----
  	}
  	cp += n + QFIXEDSZ;
  	buflen = sizeof(newmsg) - (cp - newmsg);
  	cname = 0;
+ 
   try_again:
  	dprintf(1, (ddt, "resp: nlookup(%s) qtype=%d\n", dname, qtype));
  	fname = "";
***************
*** 964,970 ****
  		goto fetch_ns;		/* NO data available */
  	cp += n;
  	buflen -= n;
! 	hp->ancount = htons(ntohs(hp->ancount) + (u_int16_t)count);
  	if (fname != dname && qtype != T_CNAME && qtype != T_ANY) {
  		cname++;
  		goto try_again;
--- 969,975 ----
  		goto fetch_ns;		/* NO data available */
  	cp += n;
  	buflen -= n;
!   	hp->ancount = htons((u_short)(ntohs((u_short)hp->ancount) + (u_int16_t)count));
  	if (fname != dname && qtype != T_CNAME && qtype != T_ANY) {
  		cname++;
  		goto try_again;
***************
*** 1041,1046 ****
--- 1046,1052 ----
  		static const char freed[] = "freed", busy[] = "busy";
  		const char *result;
  
+ 
  		if (qp->q_addr[i].ns != NULL) {
  			if ((--(qp->q_addr[i].ns->d_rcnt)))
  				result = busy;
***************
*** 2336,2343 ****
  			 * used often.
  			 */
  			dp->d_ttl = tt.tv_sec
! 					+
! 				0.95 * (int) (dp->d_ttl - tt.tv_sec);
  		}
  #ifdef NCACHE
  		/* -ve $ing stuff, anant@isi.edu
--- 2342,2349 ----
  			 * used often.
  			 */
  			dp->d_ttl = tt.tv_sec
! 					+ (int) (
! 				0.95 * (int) (dp->d_ttl - tt.tv_sec));
  		}
  #ifdef NCACHE
  		/* -ve $ing stuff, anant@isi.edu
***************
*** 2553,2555 ****
--- 2559,2562 ----
  		dp = dp->d_next;
  	}
  }
+ 
diff --context --recurs m:\bindb32/named/ns_sort.c m:\bind/named/ns_sort.c
*** m:\bindb32/named/ns_sort.c	Mon Dec 25 21:59:13 1995
--- m:\bind/named/ns_sort.c	Mon Dec 25 22:05:18 1995
***************
*** 58,72 ****
   * --Copyright--
   */
  
! #include <sys/param.h>
! #include <sys/types.h>
! #include <sys/socket.h>
! #include <sys/file.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <stdio.h>
! #include <syslog.h>
  #include <resolv.h>
  
  #include "named.h"
--- 58,76 ----
   * --Copyright--
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/types.h>
! #include <sys/socket.h>
! #include <sys/file.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <stdio.h>
! #ifndef WINNT
! #include <syslog.h>
! #endif
  #include <resolv.h>
  
  #include "named.h"
diff --context --recurs m:\bindb32/named/ns_stats.c m:\bind/named/ns_stats.c
*** m:\bindb32/named/ns_stats.c	Mon Dec 25 21:59:13 1995
--- m:\bind/named/ns_stats.c	Mon Dec 25 22:05:19 1995
***************
*** 63,78 ****
  /*            dumps a bunch of values into a well-known file              */
  /**************************************************************************/
  
! #include <sys/param.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <stdio.h>
! #include <syslog.h>
! #include <errno.h>
  
! #include "named.h"
! #include "tree.h"
  
  static u_long typestats[T_ANY+1];
  static const char *typenames[T_ANY+1] = {
--- 63,82 ----
  /*            dumps a bunch of values into a well-known file              */
  /**************************************************************************/
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <stdio.h>
! #ifndef WINNT
! #include <syslog.h>
! #endif
! #include <errno.h>
  
! #include "named.h"
! #include "tree.h"
  
  static u_long typestats[T_ANY+1];
  static const char *typenames[T_ANY+1] = {
***************
*** 247,253 ****
--- 251,261 ----
  		if (!tree_add(&nameserTree, nameserCompar, (tree_t)ns, NULL)) {
  			int save = errno;
  			free(ns);
+ #ifndef WINNT
  			errno = save;
+ #else
+ 			SetLastError(save);
+ #endif
  			goto nomem;
  		}
  	}
diff --context --recurs m:\bindb32/named/ns_validate.c m:\bind/named/ns_validate.c
*** m:\bindb32/named/ns_validate.c	Mon Dec 25 21:59:13 1995
--- m:\bind/named/ns_validate.c	Mon Dec 25 22:05:21 1995
***************
*** 7,21 ****
   * response to a query.
   */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <sys/file.h>
! 
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! 
! #include <syslog.h>
  #include <errno.h>
  #include <stdio.h>
  #include <resolv.h>
--- 7,23 ----
   * response to a query.
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <sys/file.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #ifndef WINNT
! #include <arpa/inet.h>
! #include <syslog.h>
! #endif
  #include <errno.h>
  #include <stdio.h>
  #include <resolv.h>
Only in m:\bind/named: ntif.h
diff --context --recurs m:\bindb32/named/pathnames.h m:\bind/named/pathnames.h
*** m:\bindb32/named/pathnames.h	Mon Dec 25 21:59:13 1995
--- m:\bind/named/pathnames.h	Mon Dec 25 22:05:22 1995
***************
*** 58,71 ****
   * --Copyright--
   */
  
! #ifdef _PATH_XFER
! # define _PATH_XFER_PREDEFINED	/* probably from Makefile */
  #endif
  
! #if defined (__sgi) && !defined(_SYSTYPE_SVR4) && !defined(__SYSTYPE_SVR4)
! #define	_PATH_BOOT	"/usr/etc/named.d/named.boot"
  #else
! #define	_PATH_BOOT	"/etc/named.boot"
  #endif
  
  #if defined(BSD) && BSD >= 198810
--- 58,90 ----
   * --Copyright--
   */
  
! 
! #ifdef _PATH_XFER
! # define _PATH_XFER_PREDEFINED	/* probably from Makefile */
  #endif
  
! #ifdef WINNT
! #define	_PATH_BOOT	"%windir%\\NAMED.BOOT"
! #define	_ALT_PATH_BOOT	"%windir%\\NAMED.INI"
! #ifndef _PATH_XFER
! # define _PATH_XFER	"%windir%\\SYSTEM32\\XFER.EXE"
! #endif
! #ifndef _PATH_PIDFILE
! # define _PATH_PIDFILE	"%windir%\\NAMED.PID"
! #endif
! /* following paths prepended with GetTempPath() */
! #define	_PATH_DEBUG		"NAMED.RUN" 
! #define	_PATH_DUMPFILE	"NAMDUMP.DB"
! #define	_PATH_STATS		"NAMED.STS"
! #define	_PATH_XFERTRACE	"XFER.TRC"
! #define _PATH_XFERDDT	"XFER.DDT"
! #define	_PATH_TMPXFER	"XFER.DDT.XXXXXX"
  #else
! 
! #if defined (__sgi) && !defined(_SYSTYPE_SVR4) && !defined(__SYSTYPE_SVR4)
! #define	_PATH_BOOT	"/usr/etc/named.d/named.boot"
! #else
! #define	_PATH_BOOT	"/etc/named.boot"
  #endif
  
  #if defined(BSD) && BSD >= 198810
***************
*** 120,122 ****
--- 139,143 ----
  #else
  # undef _PATH_XFER_PREDEFINED
  #endif /*_PATH_XFER_PREDEFINED*/
+ 
+ #endif /* WINNT */
diff --context --recurs m:\bindb32/named/storage.c m:\bind/named/storage.c
*** m:\bindb32/named/storage.c	Mon Dec 25 21:59:13 1995
--- m:\bind/named/storage.c	Mon Dec 25 22:05:22 1995
***************
*** 53,60 ****
   * --Copyright--
   */
  
! #include <sys/param.h>
! #include <syslog.h>
  
  #include "../conf/portability.h"
  #include "../conf/options.h"
--- 53,62 ----
   * --Copyright--
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <syslog.h>
! #endif
  
  #include "../conf/portability.h"
  #include "../conf/options.h"
Only in m:\bind/named: xfer.mak
Only in m:\bind/named: xfer.mdp
Only in m:\bind/named: xfer.ncb
Only in m:\bind/named: xfer.vcp
Only in m:\bind: ntbind49324.zip
Only in m:\bind: ntbind49326_vc22.zip
Only in m:\bind: ntbind49326_vc40.zip
Only in m:\bind: ntbind49327.zip
Only in m:\bind: ntbind49331.zip
Only in m:\bind: ntdns49326bin_vc22.zip
Only in m:\bind: ntdns49326bin_vc40.zip
Only in m:\bind: ntdns49327bin.zip
Only in m:\bind: ntdns49331bin.zip
Only in m:\bind: ntdns49332bin.zip
Only in m:\bind: readme.nt
Only in m:\bind/res: WinRel
diff --context --recurs m:\bindb32/res/gethnamaddr.c m:\bind/res/gethnamaddr.c
*** m:\bindb32/res/gethnamaddr.c	Mon Dec 25 21:59:14 1995
--- m:\bind/res/gethnamaddr.c	Mon Dec 25 22:05:23 1995
***************
*** 58,75 ****
  static char rcsid[] = "$Id: gethnamaddr.c,v 8.7 1995/08/22 05:01:47 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
! 
! #include <stdio.h>
! #include <netdb.h>
! #include <resolv.h>
! #include <ctype.h>
  #include <errno.h>
  #include <syslog.h>
  
  #ifndef LOG_AUTH
  # define LOG_AUTH 0
--- 58,79 ----
  static char rcsid[] = "$Id: gethnamaddr.c,v 8.7 1995/08/22 05:01:47 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
! 
! #include <stdio.h>
! #include <netdb.h>
! #include <resolv.h>
! #include <ctype.h>	 
  #include <errno.h>
+ #ifndef WINNT
  #include <syslog.h>
+ #endif
  
  #ifndef LOG_AUTH
  # define LOG_AUTH 0
***************
*** 86,91 ****
--- 90,101 ----
  # include <../conf/options.h>
  #endif
  
+ #ifdef WINNT
+ extern char *pathhosts;
+ extern int res_paths_initialized;
+ extern init_res_paths();
+ #endif
+ 
  #define	MAXALIASES	35
  #define	MAXADDRS	35
  
***************
*** 122,128 ****
--- 132,140 ----
      char ac;
  } align;
  
+ #ifndef WINNT
  extern int h_errno;
+ #endif
  
  #ifdef DEBUG
  static void
***************
*** 134,140 ****
--- 146,156 ----
  		int save = errno;
  
  		printf(msg, num);
+ #ifndef WINNT
  		errno = save;
+ #else
+ 		WSASetLastError(save);
+ #endif
  	}
  }
  #else
***************
*** 166,182 ****
  	 * find first satisfactory answer
  	 */
  	hp = &answer->hdr;
! 	ancount = ntohs(hp->ancount);
! 	qdcount = ntohs(hp->qdcount);
  	bp = hostbuf;
  	buflen = sizeof hostbuf;
  	cp = answer->buf + HFIXEDSZ;
  	if (qdcount != 1) {
  		h_errno = NO_RECOVERY;
  		return (NULL);
  	}
  	if ((n = dn_expand(answer->buf, eom, cp, bp, buflen)) < 0) {
  		h_errno = NO_RECOVERY;
  		return (NULL);
  	}
  	cp += n + QFIXEDSZ;
--- 182,206 ----
  	 * find first satisfactory answer
  	 */
  	hp = &answer->hdr;
! 	ancount = ntohs( (u_short) hp->ancount);
! 	qdcount = ntohs( (u_short) hp->qdcount);
  	bp = hostbuf;
  	buflen = sizeof hostbuf;
  	cp = answer->buf + HFIXEDSZ;
  	if (qdcount != 1) {
+ #ifndef WINNT
  		h_errno = NO_RECOVERY;
+ #else
+ 		WSASetLastError(NO_RECOVERY);
+ #endif
  		return (NULL);
  	}
  	if ((n = dn_expand(answer->buf, eom, cp, bp, buflen)) < 0) {
+ #ifndef WINNT
  		h_errno = NO_RECOVERY;
+ #else
+ 		WSASetLastError(NO_RECOVERY);
+ #endif
  		return (NULL);
  	}
  	cp += n + QFIXEDSZ;
***************
*** 283,289 ****
  		case T_PTR:
  			if (strcasecmp(tname, bp) != 0) {
  				syslog(LOG_NOTICE|LOG_AUTH,
! 				       AskedForGot, qname, bp);
  				cp += n;
  				continue;	/* XXX - had_error++ ? */
  			}
--- 307,313 ----
  		case T_PTR:
  			if (strcasecmp(tname, bp) != 0) {
  				syslog(LOG_NOTICE|LOG_AUTH,
! 				       (char *) AskedForGot, qname, bp);
  				cp += n;
  				continue;	/* XXX - had_error++ ? */
  			}
***************
*** 314,320 ****
  		case T_A:
  			if (strcasecmp(host.h_name, bp) != 0) {
  				syslog(LOG_NOTICE|LOG_AUTH,
! 				       AskedForGot, host.h_name, bp);
  				cp += n;
  				continue;	/* XXX - had_error++ ? */
  			}
--- 338,344 ----
  		case T_A:
  			if (strcasecmp(host.h_name, bp) != 0) {
  				syslog(LOG_NOTICE|LOG_AUTH,
! 				       (char *)AskedForGot, host.h_name, bp);
  				cp += n;
  				continue;	/* XXX - had_error++ ? */
  			}
***************
*** 356,362 ****
--- 380,390 ----
  			break;
  		default:
  			dprintf("Impossible condition (type=%d)\n", type);
+ #ifndef WINNT
  			h_errno = NO_RECOVERY;
+ #else
+ 			WSASetLastError(NO_RECOVERY);
+ #endif
  			return (NULL);
  		} /*switch*/
  		if (!had_error)
***************
*** 385,398 ****
--- 413,435 ----
  			strcpy(bp, qname);
  			host.h_name = bp;
  		}
+ #ifndef WINNT
  		h_errno = NETDB_SUCCESS;
+ #else
+ 		WSASetLastError(NETDB_SUCCESS);
+ #endif
  		return (&host);
  	} else {
+ #ifndef WINNT
  		h_errno = TRY_AGAIN;
+ #else
+ 		WSASetLastError(TRY_AGAIN);
+ #endif
  		return (NULL);
  	}
  }
  
+ #ifndef WINNT
  struct hostent *
  gethostbyname(name)
  	const char *name;
***************
*** 426,431 ****
--- 463,471 ----
  static struct hostent *
  gethostbyname_ipv4(name)
  	const char *name;
+ #else
+ struct hostent FAR * PASCAL FAR gethostbyname(const char FAR * name)
+ #endif
  {
  	querybuf buf;
  	register const char *cp;
***************
*** 433,439 ****
--- 473,483 ----
  	extern struct hostent *_gethtbyname();
  
  	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ #ifndef WINNT
  		h_errno = NETDB_INTERNAL;
+ #else
+ 		WSASetLastError(NETDB_INTERNAL);
+ #endif
  		return (NULL);
  	}
  
***************
*** 460,466 ****
--- 504,514 ----
  				 * done a lookup.
  				 */
  				if (!inet_aton(name, &host_addr)) {
+ #ifndef WINNT
  					h_errno = HOST_NOT_FOUND;
+ #else
+ 					WSASetLastError(HOST_NOT_FOUND);
+ #endif
  					return (NULL);
  				}
  				strncpy(hostbuf, name, MAXDNAME);
***************
*** 477,483 ****
--- 525,535 ----
  #else
  				host.h_addr = h_addr_ptrs[0];
  #endif
+ #ifndef WINNT
  				h_errno = NETDB_SUCCESS;
+ #else
+ 				WSASetLastError(NETDB_SUCCESS);
+ #endif
  				return (&host);
  			}
  			if (!isdigit(*cp) && *cp != '.') 
***************
*** 493,502 ****
--- 545,558 ----
  	return (getanswer(&buf, n, name, C_IN, T_A));
  }
  
+ #ifndef WINNT
  struct hostent *
  gethostbyaddr(addr, len, type)
  	const char *addr;
  	int len, type;
+ #else
+ struct hostent FAR * PASCAL FAR gethostbyaddr(const char FAR * addr, int len, int type)
+ #endif
  {
  	int n;
  	querybuf buf;
***************
*** 511,522 ****
--- 567,587 ----
  	extern struct hostent *_gethtbyaddr();
  	
  	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ #ifndef WINNT
  		h_errno = NETDB_INTERNAL;
+ #else
+ 		WSASetLastError(NETDB_INTERNAL);
+ #endif
  		return (NULL);
  	}
  	if (type != AF_INET) {
+ #ifndef WINNT
  		errno = EAFNOSUPPORT;
  		h_errno = NETDB_INTERNAL;
+ #else
+ 		SetLastError(WSAEAFNOSUPPORT);
+ 		WSASetLastError(NETDB_INTERNAL);
+ #endif
  		return (NULL);
  	}
  	(void)sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",
***************
*** 568,574 ****
--- 633,643 ----
  	h_addr_ptrs[0] = (char *)&host_addr;
  	h_addr_ptrs[1] = NULL;
  	host_addr = *(struct in_addr *)addr;
+ #ifndef WINNT
  	h_errno = NETDB_SUCCESS;
+ #else
+ 	WSASetLastError(NETDB_SUCCESS);
+ #endif
  	return (hp);
  }
  
***************
*** 576,583 ****
--- 645,662 ----
  _sethtent(f)
  	int f;
  {
+     
+ #ifndef WINNT
  	if (!hostf)
  		hostf = fopen(_PATH_HOSTS, "r" );
+ #else
+         if (!res_paths_initialized)
+           init_res_paths();
+ 
+ 	if (!hostf)
+ 		hostf = fopen(pathhosts, "r" );
+ #endif
+ 
  	else
  		rewind(hostf);
  	stayopen = f;
***************
*** 598,610 ****
--- 677,706 ----
  	char *p;
  	register char *cp, **q;
  
+ #ifndef WINNT
  	if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) {
+ #else
+         if (!res_paths_initialized)
+           init_res_paths();
+ 
+ 	if (!hostf && !(hostf = fopen(pathhosts, "r" ))) {
+ #endif
+ 
+ 	
+ #ifndef WINNT
  		h_errno = NETDB_INTERNAL;
+ #else
+ 		WSASetLastError(NETDB_INTERNAL);
+ #endif
  		return (NULL);
  	}
  again:
  	if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) {
+ #ifndef WINNT
  		h_errno = HOST_NOT_FOUND;
+ #else
+ 		WSASetLastError(HOST_NOT_FOUND);
+ #endif
  		return (NULL);
  	}
  	if (*p == '#')
***************
*** 644,650 ****
--- 740,750 ----
  			*cp++ = '\0';
  	}
  	*q = NULL;
+ #ifndef WINNT
  	h_errno = NETDB_SUCCESS;
+ #else
+ 	WSASetLastError(NETDB_SUCCESS);
+ #endif
  	return (&host);
  }
  
diff --context --recurs m:\bindb32/res/getnetbyaddr.c m:\bind/res/getnetbyaddr.c
*** m:\bindb32/res/getnetbyaddr.c	Mon Dec 25 21:59:14 1995
--- m:\bind/res/getnetbyaddr.c	Mon Dec 25 22:05:23 1995
***************
*** 37,48 ****
  #endif /* LIBC_SCCS and not lint */
  
  #include <netdb.h>
! 
! extern int _net_stayopen;
! 
! struct netent *
! _getnetbyaddr(net, type)
! 	register long net;
  	register int type;
  {
  	register struct netent *p;
--- 37,51 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <netdb.h>
! #ifdef WINNT
! #include "../conf/portability.h"
! #endif
! 
! extern int _net_stayopen;
! 
! struct netent *
! _getnetbyaddr(net, type)
! 	register u_long net;
  	register int type;
  {
  	register struct netent *p;
diff --context --recurs m:\bindb32/res/getnetbyname.c m:\bind/res/getnetbyname.c
*** m:\bindb32/res/getnetbyname.c	Mon Dec 25 21:59:14 1995
--- m:\bind/res/getnetbyname.c	Mon Dec 25 22:05:24 1995
***************
*** 39,44 ****
--- 39,47 ----
  
  #include <netdb.h>
  #include <string.h>
+ #ifdef WINNT
+ #include "../conf/portability.h"
+ #endif
  
  extern int _net_stayopen;
  
diff --context --recurs m:\bindb32/res/getnetent.c m:\bind/res/getnetent.c
*** m:\bindb32/res/getnetent.c	Mon Dec 25 21:59:14 1995
--- m:\bind/res/getnetent.c	Mon Dec 25 22:05:24 1995
***************
*** 46,66 ****
  static char rcsid[] = "$Id: getnetent.c,v 8.1 1994/12/15 06:24:24 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
  
! #include <stdio.h>
! #include <resolv.h>
! #include <netdb.h>
! #include <string.h>
  
  #ifndef _PATH_NETWORKS 
  #define _PATH_NETWORKS  "/etc/networks"
  #endif
  
  #define	MAXALIASES	35
  
  static FILE *netf;
--- 46,76 ----
  static char rcsid[] = "$Id: getnetent.c,v 8.1 1994/12/15 06:24:24 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
  
! #include <stdio.h>
! #include <resolv.h>
! #include <netdb.h>
! #include <string.h>
! #ifdef WINNT
! #include "../conf/portability.h"
! extern char *pathnetworks;
! extern int res_paths_initialized;
! extern init_res_paths();
! #endif
  
  #ifndef _PATH_NETWORKS 
  #define _PATH_NETWORKS  "/etc/networks"
  #endif
  
+ 
+ 
  #define	MAXALIASES	35
  
  static FILE *netf;
***************
*** 94,101 ****
--- 104,119 ----
  	int f;
  {
  
+ #ifndef WINNT
  	if (netf == NULL)
  		netf = fopen(_PATH_NETWORKS, "r" );
+ #else
+        if (!res_paths_initialized)
+          init_res_paths();
+ 
+ 	if (netf == NULL)
+ 		netf = fopen(pathnetworks, "r" );
+ #endif
  	else
  		rewind(netf);
  	_net_stayopen |= f;
***************
*** 118,124 ****
--- 136,150 ----
  	char *p;
  	register char *cp, **q;
  
+ #ifndef WINNT
  	if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
+ #else
+        if (!res_paths_initialized)
+          init_res_paths();
+ 
+ 	if (netf == NULL && (netf = fopen(pathnetworks, "r" )) == NULL)
+ #endif
+ 
  		return (NULL);
  again:
  	p = fgets(line, BUFSIZ, netf);
diff --context --recurs m:\bindb32/res/getnetnamadr.c m:\bind/res/getnetnamadr.c
*** m:\bindb32/res/getnetnamadr.c	Mon Dec 25 21:59:14 1995
--- m:\bind/res/getnetnamadr.c	Mon Dec 25 22:05:24 1995
***************
*** 44,69 ****
  static char rcsid[] = "$Id: getnetnamadr.c,v 8.4 1995/06/29 09:26:28 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
  
! #include <stdio.h>
! #include <netdb.h>
! #include <resolv.h>
! #include <ctype.h>
  #include <errno.h>
  #include <string.h>
  
  extern int h_errno;
  
  #if defined(mips) && defined(SYSTYPE_BSD43)
  extern int errno;
  #endif
  
! struct netent *_getnetbyaddr __P((long net, int type));
  struct netent *_getnetbyname __P((const char *name));
  
  #define BYADDR 0
--- 44,75 ----
  static char rcsid[] = "$Id: getnetnamadr.c,v 8.4 1995/06/29 09:26:28 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
  
! #include <stdio.h>
! #include <netdb.h>
! #include <resolv.h>
! #include <ctype.h>
  #include <errno.h>
  #include <string.h>
  
+ #ifndef WINNT
  extern int h_errno;
+ #else
+ #include "../conf/portability.h"
+ #endif
  
  #if defined(mips) && defined(SYSTYPE_BSD43)
  extern int errno;
  #endif
  
! struct netent *_getnetbyaddr __P((u_long net, int type));
  struct netent *_getnetbyname __P((const char *name));
  
  #define BYADDR 0
***************
*** 119,134 ****
  	 */
  	eom = answer->buf + anslen;
  	hp = &answer->hdr;
! 	ancount = ntohs(hp->ancount); /* #/records in the answer section */
! 	qdcount = ntohs(hp->qdcount); /* #/entries in the question section */
  	bp = netbuf;
  	buflen = sizeof(netbuf);
  	cp = answer->buf + HFIXEDSZ;
  	if (!qdcount) {
  		if (hp->aa)
  			h_errno = HOST_NOT_FOUND;
  		else
  			h_errno = TRY_AGAIN;
  		return (NULL);
  	}
  	while (qdcount-- > 0)
--- 125,148 ----
  	 */
  	eom = answer->buf + anslen;
  	hp = &answer->hdr;
! 	ancount = ntohs( (u_short) hp->ancount); /* #/records in the answer section */
! 	qdcount = ntohs( (u_short) hp->qdcount); /* #/entries in the question section */
  	bp = netbuf;
  	buflen = sizeof(netbuf);
  	cp = answer->buf + HFIXEDSZ;
  	if (!qdcount) {
  		if (hp->aa)
+ #ifndef WINNT
  			h_errno = HOST_NOT_FOUND;
+ #else
+ 			WSASetLastError(HOST_NOT_FOUND);
+ #endif
  		else
+ #ifndef WINNT
  			h_errno = TRY_AGAIN;
+ #else
+ 			WSASetLastError(HOST_NOT_FOUND);
+ #endif
  		return (NULL);
  	}
  	while (qdcount-- > 0)
***************
*** 196,208 ****
  		net_entry.n_aliases++;
  		return (&net_entry);
  	}
  	h_errno = TRY_AGAIN;
  	return (NULL);
  }
  
  struct netent *
  getnetbyaddr(net, net_type)
! 	register long net;
  	register int net_type;
  {
  	unsigned int netbr[4];
--- 210,226 ----
  		net_entry.n_aliases++;
  		return (&net_entry);
  	}
+ #ifndef WINNT
  	h_errno = TRY_AGAIN;
+ #else
+ 	WSASetLastError(TRY_AGAIN);
+ #endif
  	return (NULL);
  }
  
  struct netent *
  getnetbyaddr(net, net_type)
! 	register u_long net;
  	register int net_type;
  {
  	unsigned int netbr[4];
***************
*** 266,272 ****
--- 284,294 ----
  	struct netent *net_entry;
  
  	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ #ifndef WINNT
  		h_errno = NETDB_INTERNAL;
+ #else
+ 		WSASetLastError(NETDB_INTERNAL);
+ #endif
  		return (NULL);
  	}
  	strcpy(&qbuf[0], net);
diff --context --recurs m:\bindb32/res/herror.c m:\bind/res/herror.c
*** m:\bindb32/res/herror.c	Mon Dec 25 21:59:14 1995
--- m:\bind/res/herror.c	Mon Dec 25 22:05:25 1995
***************
*** 58,72 ****
  static char rcsid[] = "$Id: herror.c,v 8.2 1995/06/19 08:35:01 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <sys/uio.h>
! #include <netdb.h>
! #if defined(BSD) && (BSD >= 199103)
! # include <unistd.h>
! # include <string.h>
! #else
! # include "../conf/portability.h"
! #endif
  
  const char *h_errlist[] = {
  	"Resolver Error 0 (no error)",
--- 58,74 ----
  static char rcsid[] = "$Id: herror.c,v 8.2 1995/06/19 08:35:01 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/uio.h>
! #endif
! #include <netdb.h>
! #if defined(BSD) && (BSD >= 199103)
! # include <unistd.h>
! # include <string.h>
! #else
! # include "../conf/portability.h"
! #endif
  
  const char *h_errlist[] = {
  	"Resolver Error 0 (no error)",
***************
*** 77,83 ****
--- 79,87 ----
  };
  int	h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
  
+ #ifndef WINNT
  extern int	h_errno;
+ #endif
  
  /*
   * herror --
***************
*** 89,94 ****
--- 93,101 ----
  {
  	struct iovec iov[4];
  	register struct iovec *v = iov;
+ #ifdef WINNT
+ 	char err[50];
+ #endif
  
  	if (s && *s) {
  		v->iov_base = (char *)s;
***************
*** 98,104 ****
--- 105,117 ----
  		v->iov_len = 2;
  		v++;
  	}
+ #ifndef WINNT
  	v->iov_base = (char *)hstrerror(h_errno);
+ #else
+ 	/* XXX - map the error number to the corresponding message here */
+ 	sprintf(err, "%d", h_errno);
+ 	v->iov_base = err;
+ #endif
  	v->iov_len = strlen(v->iov_base);
  	v++;
  	v->iov_base = "\n";
***************
*** 106,111 ****
--- 119,125 ----
  	writev(STDERR_FILENO, iov, (v - iov) + 1);
  }
  
+ #ifndef WINNT
  const char *
  hstrerror(err)
  	int err;
***************
*** 116,118 ****
--- 130,133 ----
  		return (h_errlist[err]);
  	return ("Unknown resolver error");
  }
+ #endif
diff --context --recurs m:\bindb32/res/inet_addr.c m:\bind/res/inet_addr.c
*** m:\bindb32/res/inet_addr.c	Mon Dec 25 21:59:14 1995
--- m:\bind/res/inet_addr.c	Mon Dec 25 22:05:25 1995
***************
*** 58,73 ****
  static char rcsid[] = "$Id: inet_addr.c,v 8.4 1995/08/21 01:27:23 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <ctype.h>
! #include "../conf/portability.h"
  
- /* these are compatibility routines, not needed on recent BSD releases */
  
! /*
!  * Ascii internet address interpretation routine.
   * The value returned is in network order.
   */
  u_long
--- 58,79 ----
  static char rcsid[] = "$Id: inet_addr.c,v 8.4 1995/08/21 01:27:23 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/inet.h>
! #include <ctype.h>
! #include "../conf/portability.h"
  
  
! #ifndef NEED_INETADDR
! int __inet_addr_unneeded__;
! #else
! /* these are compatibility routines, not needed on recent BSD releases */
! 
! /*
!  * Ascii internet address interpretation routine.
   * The value returned is in network order.
   */
  u_long
***************
*** 80,85 ****
--- 86,92 ----
  		return (val.s_addr);
  	return (INADDR_NONE);
  }
+ #endif  /* NEED_INETADDR */
  
  /* 
   * Check whether "cp" is a valid ascii representation
diff --context --recurs m:\bindb32/res/nsap_addr.c m:\bind/res/nsap_addr.c
*** m:\bindb32/res/nsap_addr.c	Mon Dec 25 21:59:15 1995
--- m:\bind/res/nsap_addr.c	Mon Dec 25 22:05:26 1995
***************
*** 2,17 ****
  static char rcsid[] = "$Id: nsap_addr.c,v 8.2 1995/06/29 09:26:28 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <ctype.h>
! #include <resolv.h>
  
! #include "../conf/portability.h"
  
! #if !defined(isxdigit)	/* XXX - could be a function */
  static int
  isxdigit(c)
  	register int c;
--- 2,19 ----
  static char rcsid[] = "$Id: nsap_addr.c,v 8.2 1995/06/29 09:26:28 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <ctype.h>
! #include <resolv.h>
  
! #include "../conf/portability.h"
  
! #if !defined(isxdigit)	/* XXX - could be a function */
  static int
  isxdigit(c)
  	register int c;
***************
*** 31,37 ****
  inet_nsap_addr(ascii, binary, maxlen)
  	const char *ascii;
  	u_char *binary;
! 	int maxlen;
  {
  	register u_char c, nib;
  	u_int len = 0;
--- 33,39 ----
  inet_nsap_addr(ascii, binary, maxlen)
  	const char *ascii;
  	u_char *binary;
! 	u_int maxlen;
  {
  	register u_char c, nib;
  	u_int len = 0;
diff --context --recurs m:\bindb32/res/res_comp.c m:\bind/res/res_comp.c
*** m:\bindb32/res/res_comp.c	Mon Dec 25 21:59:14 1995
--- m:\bind/res/res_comp.c	Mon Dec 25 22:05:26 1995
***************
*** 58,65 ****
  static char rcsid[] = "$Id: res_comp.c,v 8.3 1995/12/06 20:34:50 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <netinet/in.h>
  #include <arpa/nameser.h>
  
  #include <stdio.h>
--- 58,67 ----
  static char rcsid[] = "$Id: res_comp.c,v 8.3 1995/12/06 20:34:50 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <netinet/in.h>
! #endif
  #include <arpa/nameser.h>
  
  #include <stdio.h>
diff --context --recurs m:\bindb32/res/res_data.c m:\bind/res/res_data.c
*** m:\bindb32/res/res_data.c	Mon Dec 25 21:59:15 1995
--- m:\bind/res/res_data.c	Mon Dec 25 22:05:26 1995
***************
*** 57,66 ****
  static char rcsid[] = "$Id: res_data.c,v 8.1 1995/12/22 10:21:29 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <sys/time.h>
! #include <netinet/in.h>
  #include <arpa/inet.h>
  #include <arpa/nameser.h>
  
--- 57,68 ----
  static char rcsid[] = "$Id: res_data.c,v 8.1 1995/12/22 10:21:29 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <sys/time.h>
! #include <netinet/in.h>
! #endif /* WINNT */
  #include <arpa/inet.h>
  #include <arpa/nameser.h>
  
diff --context --recurs m:\bindb32/res/res_debug.c m:\bind/res/res_debug.c
*** m:\bindb32/res/res_debug.c	Mon Dec 25 21:59:14 1995
--- m:\bind/res/res_debug.c	Mon Dec 25 22:05:27 1995
***************
*** 58,73 ****
  static char rcsid[] = "$Id: res_debug.c,v 8.7 1995/12/22 10:20:39 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
  
! #include <stdio.h>
! #include <netdb.h>
! #include <resolv.h>
! #if defined(BSD) && (BSD >= 199103)
! # include <string.h>
  #else
  # include "../conf/portability.h"
  #endif
--- 58,75 ----
  static char rcsid[] = "$Id: res_debug.c,v 8.7 1995/12/22 10:20:39 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
  
! #include <stdio.h>
! #include <netdb.h>
! #include <resolv.h>
! #if defined(BSD) && (BSD >= 199103)
! # include <string.h>
  #else
  # include "../conf/portability.h"
  #endif
***************
*** 175,181 ****
  	 * Print answer records.
  	 */
  	sflag = (_res.pfcode & pflag);
! 	if (n = ntohs(cnt)) {
  		if ((!_res.pfcode) ||
  		    ((sflag) && (_res.pfcode & RES_PRF_HEAD1)))
  			fprintf(file, hs);
--- 177,183 ----
  	 * Print answer records.
  	 */
  	sflag = (_res.pfcode & pflag);
! 	if (n = ntohs( (u_short) cnt)) {
  		if ((!_res.pfcode) ||
  		    ((sflag) && (_res.pfcode & RES_PRF_HEAD1)))
  			fprintf(file, hs);
***************
*** 271,277 ****
  		fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d",
  			_res_opcodes[hp->opcode],
  			_res_resultcodes[hp->rcode],
! 			ntohs(hp->id));
  		putc('\n', file);
  	}
  	if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX))
--- 273,279 ----
  		fprintf(file, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d",
  			_res_opcodes[hp->opcode],
  			_res_resultcodes[hp->rcode],
! 			ntohs( (u_short) hp->id));
  		putc('\n', file);
  	}
  	if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX))
***************
*** 290,299 ****
  			fprintf(file, " ra");
  	}
  	if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) {
! 		fprintf(file, "; Ques: %d", ntohs(hp->qdcount));
! 		fprintf(file, ", Ans: %d", ntohs(hp->ancount));
! 		fprintf(file, ", Auth: %d", ntohs(hp->nscount));
! 		fprintf(file, ", Addit: %d", ntohs(hp->arcount));
  	}
  	if ((!_res.pfcode) || (_res.pfcode & 
  		(RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
--- 292,301 ----
  			fprintf(file, " ra");
  	}
  	if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) {
! 		fprintf(file, "; Ques: %d", ntohs( (u_short) hp->qdcount));
! 		fprintf(file, ", Ans: %d", ntohs( (u_short) hp->ancount));
! 		fprintf(file, ", Auth: %d", ntohs( (u_short) hp->nscount));
! 		fprintf(file, ", Addit: %d", ntohs( (u_short) hp->arcount));
  	}
  	if ((!_res.pfcode) || (_res.pfcode & 
  		(RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
***************
*** 302,308 ****
  	/*
  	 * Print question records.
  	 */
! 	if (n = ntohs(hp->qdcount)) {
  		if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
  			fprintf(file, ";; QUESTIONS:\n");
  		while (--n >= 0) {
--- 304,310 ----
  	/*
  	 * Print question records.
  	 */
! 	if (n = ntohs( (u_short) hp->qdcount)) {
  		if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
  			fprintf(file, ";; QUESTIONS:\n");
  		while (--n >= 0) {
***************
*** 439,445 ****
--- 441,451 ----
  	int lcnt;
  
  	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ #ifndef WINNT
  		h_errno = NETDB_INTERNAL;
+ #else
+ 		WSASetLastError(NETDB_INTERNAL);
+ #endif
  		return (NULL);
  	}
  	if ((cp = p_fqname(cp, msg, file)) == NULL)
diff --context --recurs m:\bindb32/res/res_init.c m:\bind/res/res_init.c
*** m:\bindb32/res/res_init.c	Mon Dec 25 21:59:14 1995
--- m:\bind/res/res_init.c	Mon Dec 25 22:05:27 1995
***************
*** 58,81 ****
  static char rcsid[] = "$Id: res_init.c,v 8.3 1995/06/29 09:26:28 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <sys/time.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
! 
! #include <stdio.h>
! #include <ctype.h>
! #include <resolv.h>
  #if defined(BSD) && (BSD >= 199103)
  # include <unistd.h>
  # include <stdlib.h>
  # include <string.h>
  #else
! # include "../conf/portability.h"
  #endif
  
  /*-------------------------------------- info about "sortlist" --------------
   * Marc Majka		1994/04/16
   * Allan Nathanson	1994/10/29 (BIND 4.9.3.x)
--- 58,91 ----
  static char rcsid[] = "$Id: res_init.c,v 8.3 1995/06/29 09:26:28 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <sys/time.h>
! #include <netinet/in.h>
! #endif /* WINNT */
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
! 
! #include <stdio.h>
! #include <ctype.h>
! #include <resolv.h>
  #if defined(BSD) && (BSD >= 199103)
  # include <unistd.h>
  # include <stdlib.h>
  # include <string.h>
  #else
! #include "../conf/portability.h"
  #endif
  
+ #ifdef WINNT
+ #include <netdb.h>
+ #include "../conf/portability.h"
+ extern char *pathresconf;
+ extern int res_paths_initialized;
+ extern init_res_paths();
+ #endif
+ 
  /*-------------------------------------- info about "sortlist" --------------
   * Marc Majka		1994/04/16
   * Allan Nathanson	1994/10/29 (BIND 4.9.3.x)
***************
*** 166,171 ****
--- 176,193 ----
  	int dots;
  #endif
  
+ 
+ #ifdef WINNT
+  	WORD wVersionRequested;
+ 	WSADATA wsaData;
+ 
+ 	wVersionRequested = MAKEWORD(1,1);
+ 	if (WSAStartup(wVersionRequested, &wsaData)) {
+ 		syslog(LOG_ERR, "No useable winsock.dll: %m");
+ 		return (-1);
+ 	}
+ #endif /* WINNT */
+ 
  	/*
  	 * These three fields used to be statically initialized.  This made
  	 * it hard to use this code in a shared library.  It is necessary,
***************
*** 252,258 ****
--- 274,288 ----
  #ifdef	NeXT
  	if (netinfo_res_init(&haveenv, &havesearch) == 0)
  #endif
+ #ifndef WINNT
  	if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
+ #else
+        if (!res_paths_initialized)
+          init_res_paths();
+ 
+ 	if ((fp = fopen(pathresconf, "r")) != NULL) {
+ 
+ #endif
  	    /* read the config file */
  	    while (fgets(buf, sizeof(buf), fp) != NULL) {
  		/* skip comments */
diff --context --recurs m:\bindb32/res/res_mkquery.c m:\bind/res/res_mkquery.c
*** m:\bindb32/res/res_mkquery.c	Mon Dec 25 21:59:14 1995
--- m:\bind/res/res_mkquery.c	Mon Dec 25 22:05:27 1995
***************
*** 58,73 ****
  static char rcsid[] = "$Id: res_mkquery.c,v 8.3 1995/06/29 09:26:28 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
  
! #include <stdio.h>
! #include <netdb.h>
! #include <resolv.h>
! #if defined(BSD) && (BSD >= 199103)
! # include <string.h>
! #else
  # include "../conf/portability.h"
  #endif
  
--- 58,75 ----
  static char rcsid[] = "$Id: res_mkquery.c,v 8.3 1995/06/29 09:26:28 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
  
! #include <stdio.h>
! #include <netdb.h>
! #include <resolv.h>
! #if defined(BSD) && (BSD >= 199103)
! # include <string.h>
! #else
  # include "../conf/portability.h"
  #endif
  
***************
*** 99,105 ****
--- 101,111 ----
  	u_char *dnptrs[20], **dpp, **lastdnptr;
  
  	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ #ifndef WINNT
  		h_errno = NETDB_INTERNAL;
+ #else
+ 		WSASetLastError(NETDB_INTERNAL);
+ #endif
  		return (-1);
  	}
  #ifdef DEBUG
Only in m:\bind/res: res_nt_misc.c
diff --context --recurs m:\bindb32/res/res_query.c m:\bind/res/res_query.c
*** m:\bindb32/res/res_query.c	Mon Dec 25 21:59:15 1995
--- m:\bind/res/res_query.c	Mon Dec 25 22:05:28 1995
***************
*** 58,73 ****
  static char rcsid[] = "$Id: res_query.c,v 8.6 1995/06/29 09:26:28 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
  
! #include <stdio.h>
! #include <netdb.h>
! #include <resolv.h>
! #include <ctype.h>
! #include <errno.h>
  #if defined(BSD) && (BSD >= 199306)
  # include <stdlib.h>
  # include <string.h>
--- 58,75 ----
  static char rcsid[] = "$Id: res_query.c,v 8.6 1995/06/29 09:26:28 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
  
! #include <stdio.h>
! #include <netdb.h>
! #include <resolv.h>
! #include <ctype.h>
! #include <errno.h>
  #if defined(BSD) && (BSD >= 199306)
  # include <stdlib.h>
  # include <string.h>
***************
*** 86,92 ****
--- 88,96 ----
  #endif
  
  char *__hostalias __P((const char *));
+ #ifndef WINNT
  int h_errno;
+ #endif
  
  /*
   * Formulate a normal query, send, and await answer.
***************
*** 112,118 ****
--- 116,126 ----
  	hp->rcode = NOERROR;	/* default */
  
  	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ #ifndef WINNT
  		h_errno = NETDB_INTERNAL;
+ #else
+ 		WSASetLastError(NETDB_INTERNAL);
+ #endif
  		return (-1);
  	}
  #ifdef DEBUG
***************
*** 127,133 ****
--- 135,145 ----
  		if (_res.options & RES_DEBUG)
  			printf(";; res_query: mkquery failed\n");
  #endif
+ #ifndef WINNT
  		h_errno = NO_RECOVERY;
+ #else
+ 		WSASetLastError(NO_RECOVERY);
+ #endif
  		return (n);
  	}
  	n = res_send(buf, n, answer, anslen);
***************
*** 136,166 ****
  		if (_res.options & RES_DEBUG)
  			printf(";; res_query: send error\n");
  #endif
  		h_errno = TRY_AGAIN;
  		return (n);
  	}
  
! 	if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
  #ifdef DEBUG
  		if (_res.options & RES_DEBUG)
  			printf(";; rcode = %d, ancount=%d\n", hp->rcode,
! 			    ntohs(hp->ancount));
  #endif
  		switch (hp->rcode) {
  		case NXDOMAIN:
  			h_errno = HOST_NOT_FOUND;
  			break;
  		case SERVFAIL:
  			h_errno = TRY_AGAIN;
  			break;
  		case NOERROR:
  			h_errno = NO_DATA;
  			break;
  		case FORMERR:
  		case NOTIMP:
  		case REFUSED:
  		default:
  			h_errno = NO_RECOVERY;
  			break;
  		}
  		return (-1);
--- 148,198 ----
  		if (_res.options & RES_DEBUG)
  			printf(";; res_query: send error\n");
  #endif
+ #ifndef WINNT
  		h_errno = TRY_AGAIN;
+ #else
+ 		WSASetLastError(TRY_AGAIN);
+ #endif
  		return (n);
  	}
  
! 	if (hp->rcode != NOERROR || ntohs( (u_short) hp->ancount) == 0) {
  #ifdef DEBUG
  		if (_res.options & RES_DEBUG)
  			printf(";; rcode = %d, ancount=%d\n", hp->rcode,
! 			    ntohs( (u_short) hp->ancount));
  #endif
  		switch (hp->rcode) {
  		case NXDOMAIN:
+ #ifndef WINNT
  			h_errno = HOST_NOT_FOUND;
+ #else
+ 			WSASetLastError(HOST_NOT_FOUND);
+ #endif
  			break;
  		case SERVFAIL:
+ #ifndef WINNT
  			h_errno = TRY_AGAIN;
+ #else
+ 			WSASetLastError(TRY_AGAIN);
+ #endif
  			break;
  		case NOERROR:
+ #ifndef WINNT
  			h_errno = NO_DATA;
+ #else
+ 			WSASetLastError(NO_DATA);
+ #endif
  			break;
  		case FORMERR:
  		case NOTIMP:
  		case REFUSED:
  		default:
+ #ifndef WINNT
  			h_errno = NO_RECOVERY;
+ #else
+ 			WSASetLastError(NO_RECOVERY);
+ #endif
  			break;
  		}
  		return (-1);
***************
*** 188,198 ****
--- 220,238 ----
  	int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
  
  	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ #ifndef WINNT
  		h_errno = NETDB_INTERNAL;
+ #else
+ 		WSASetLastError(NETDB_INTERNAL);
+ #endif
  		return (-1);
  	}
+ #ifndef WINNT
  	errno = 0;
  	h_errno = HOST_NOT_FOUND;	/* default, if we never query */
+ #else
+ 	WSASetLastError(HOST_NOT_FOUND);
+ #endif
  	dots = 0;
  	for (cp = name; *cp; cp++)
  		dots += (*cp == '.');
***************
*** 252,258 ****
--- 292,302 ----
  			 * fully-qualified.
  			 */
  			if (errno == ECONNREFUSED) {
+ #ifndef WINNT
  				h_errno = TRY_AGAIN;
+ #else
+ 				WSASetLastError(TRY_AGAIN);
+ #endif
  				return (-1);
  			}
  
***************
*** 300,311 ****
--- 344,364 ----
  	 * else send back meaningless h_errno, that being the one from
  	 * the last DNSRCH we did.
  	 */
+ #ifndef WINNT
  	if (saved_herrno != -1)
  		h_errno = saved_herrno;
  	else if (got_nodata)
  		h_errno = NO_DATA;
  	else if (got_servfail)
  		h_errno = TRY_AGAIN;
+ #else
+ 	if (saved_herrno != -1)
+ 		WSASetLastError(saved_herrno);
+ 	else if (got_nodata)
+ 		WSASetLastError(NO_DATA);
+ 	else if (got_servfail)
+ 		WSASetLastError(TRY_AGAIN);
+ #endif
  	return (-1);
  }
  
***************
*** 325,331 ****
--- 378,388 ----
  	int n;
  
  	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ #ifndef WINNT
  		h_errno = NETDB_INTERNAL;
+ #else
+ 		WSASetLastError(NETDB_INTERNAL);
+ #endif
  		return (-1);
  	}
  #ifdef DEBUG
diff --context --recurs m:\bindb32/res/res_send.c m:\bind/res/res_send.c
*** m:\bindb32/res/res_send.c	Mon Dec 25 21:59:15 1995
--- m:\bind/res/res_send.c	Mon Dec 25 22:05:28 1995
***************
*** 69,84 ****
   * Send query to name server and wait for reply.
   */
  
! #include <sys/param.h>
! #include <sys/time.h>
! #include <sys/socket.h>
! #include <sys/uio.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
  
! #include <stdio.h>
! #include <netdb.h>
  #include <errno.h>
  #include <resolv.h>
  #if defined(BSD) && (BSD >= 199306)
--- 69,86 ----
   * Send query to name server and wait for reply.
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/time.h>
! #include <sys/socket.h>
! #include <sys/uio.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
  
! #include <stdio.h>
! #include <netdb.h>
  #include <errno.h>
  #include <resolv.h>
  #if defined(BSD) && (BSD >= 199306)
***************
*** 95,101 ****
--- 97,108 ----
  
  void _res_close __P((void));
  
+ #ifndef WINNT
  static int s = -1;	/* socket used for communications */
+ #else
+ static SOCKET s = INVALID_SOCKET;
+ typedef char * caddr_t;
+ #endif
  static int connected = 0;	/* is the socket connected */
  static int vc = 0;	/* is the socket a virtual ciruit? */
  
***************
*** 143,149 ****
--- 150,160 ----
  			ntohs(address.sin_port),
  			strerror(error));
  	}
+ #ifndef WINNT
  	errno = save;
+ #else
+ 	WSASetLastError(save);
+ #endif
      }
      static void
      Perror(file, string, error)
***************
*** 157,163 ****
--- 168,178 ----
  		fprintf(file, "res_send: %s: %s\n",
  			string, strerror(error));
  	}
+ #ifndef WINNT
  	errno = save;
+ #else
+ 	WSASetLastError(save);
+ #endif
      }
  #endif
  
***************
*** 229,235 ****
  	const u_char *buf, *eom;
  {
  	register const u_char *cp = buf + HFIXEDSZ;
! 	int qdcount = ntohs(((HEADER*)buf)->qdcount);
  
  	while (qdcount-- > 0) {
  		char tname[MAXDNAME+1];
--- 244,250 ----
  	const u_char *buf, *eom;
  {
  	register const u_char *cp = buf + HFIXEDSZ;
! 	int qdcount = ntohs( (u_short) ((HEADER*)buf)->qdcount);
  
  	while (qdcount-- > 0) {
  		char tname[MAXDNAME+1];
***************
*** 266,274 ****
  	const u_char *buf2, *eom2;
  {
  	register const u_char *cp = buf1 + HFIXEDSZ;
! 	int qdcount = ntohs(((HEADER*)buf1)->qdcount);
  
! 	if (qdcount != ntohs(((HEADER*)buf2)->qdcount))
  		return (0);
  	while (qdcount-- > 0) {
  		char tname[MAXDNAME+1];
--- 281,289 ----
  	const u_char *buf2, *eom2;
  {
  	register const u_char *cp = buf1 + HFIXEDSZ;
! 	int qdcount = ntohs( (u_short) ((HEADER*)buf1)->qdcount);
  
! 	if (qdcount != ntohs( (u_short) ((HEADER*)buf2)->qdcount))
  		return (0);
  	while (qdcount-- > 0) {
  		char tname[MAXDNAME+1];
***************
*** 298,303 ****
--- 313,322 ----
  	int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns;
  	register int n;
  	u_int badns;	/* XXX NSMAX can't exceed #/bits in this var */
+ #ifdef WINNT
+ 	int optionValue = SO_SYNCHRONOUS_NONALERT;
+ 	DWORD BytesRead;
+ #endif
  
  	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
  		/* errno should have been set by res_init() in this case. */
***************
*** 362,368 ****
  			struct iovec iov[2];
  			u_short len;
  			u_char *cp;
! 
  			/*
  			 * Use virtual circuit;
  			 * at most one attempt per server.
--- 381,396 ----
  			struct iovec iov[2];
  			u_short len;
  			u_char *cp;
! #ifdef WINNT
! 			/* set up things so that subsequent socket()
! 			   calls will open blocking sockets */
! 			if (setsockopt(INVALID_SOCKET, SOL_SOCKET,
! 				  	SO_OPENTYPE, (char *)&optionValue,
! 					sizeof(optionValue)) != NO_ERROR) {
! 						Perror(stderr, "cannot open nonoverlapped socket", errno);
! 						return (-1);
! 			}
! #endif
  			/*
  			 * Use virtual circuit;
  			 * at most one attempt per server.
***************
*** 374,385 ****
--- 402,421 ----
  					_res_close();
  
  				s = socket(PF_INET, SOCK_STREAM, 0);
+ #ifndef WINNT
  				if (s < 0) {
+ #else
+ 				if (s == INVALID_SOCKET) {
+ #endif
  					terrno = errno;
  					Perror(stderr, "socket(vc)", errno);
  					return (-1);
  				}
+ #ifndef WINNT
  				errno = 0;
+ #else
+ 				WSASetLastError(0);
+ #endif
  				if (connect(s, (struct sockaddr *)nsap,
  					    sizeof(struct sockaddr)) < 0) {
  					terrno = errno;
***************
*** 411,417 ****
--- 447,459 ----
  			 */
  			cp = ans;
  			len = INT16SZ;
+ #ifndef WINNT
  			while ((n = read(s, (char *)cp, (int)len)) > 0) {
+ #else
+ 			while (ReadFile((HANDLE)s, (char *)cp, (DWORD)len,
+ 				             &BytesRead, NULL) &&
+ 				   (n = (int)BytesRead) > 0) {
+ #endif
  				cp += n;
  				if ((len -= n) <= 0)
  					break;
***************
*** 448,454 ****
--- 490,502 ----
  				len = resplen;
  			cp = ans;
  			while (len != 0 &&
+ #ifndef WINNT
  			       (n = read(s, (char *)cp, (int)len)) > 0) {
+ #else
+ 					ReadFile((HANDLE)s, (char *)cp, (DWORD)len,
+ 				             &BytesRead, NULL) &&
+ 				    (n = (int)BytesRead) > 0) {
+ #endif
  				cp += n;
  				len -= n;
  			}
***************
*** 471,477 ****
--- 519,531 ----
  					n = (len > sizeof(junk)
  					     ? sizeof(junk)
  					     : len);
+ #ifndef WINNT
  					if ((n = read(s, junk, n)) > 0)
+ #else
+ 					if (ReadFile((HANDLE)s, (char *)junk, (DWORD)n,
+ 				             &BytesRead, NULL) &&
+ 				        (n = (int)BytesRead) > 0)
+ #endif
  						len -= n;
  					else
  						break;
***************
*** 485,496 ****
  			fd_set dsmask;
  			struct sockaddr_in from;
  			int fromlen;
! 
  			if ((s < 0) || vc) {
  				if (vc)
  					_res_close();
  				s = socket(PF_INET, SOCK_DGRAM, 0);
  				if (s < 0) {
  #if !CAN_RECONNECT
   bad_dg_sock:
  #endif
--- 539,557 ----
  			fd_set dsmask;
  			struct sockaddr_in from;
  			int fromlen;
! #ifndef WINNT
  			if ((s < 0) || vc) {
+ #else
+ 			if ((s == INVALID_SOCKET) || vc) {
+ #endif
  				if (vc)
  					_res_close();
  				s = socket(PF_INET, SOCK_DGRAM, 0);
+ #ifndef WINNT
  				if (s < 0) {
+ #else
+ 				if (s == INVALID_SOCKET) {
+ #endif
  #if !CAN_RECONNECT
   bad_dg_sock:
  #endif
***************
*** 515,520 ****
--- 576,582 ----
  			 * as we wish to receive answers from the first
  			 * server to respond.
  			 */
+ #ifndef WINNT
  			if (_res.nscount == 1 || (try == 0 && ns == 0)) {
  				/*
  				 * Connect only if we are sure we won't
***************
*** 540,545 ****
--- 602,608 ----
  					goto next_ns;
  				}
  			} else {
+ #endif /* WINNT */
  				/*
  				 * Disconnect if we want to listen
  				 * for responses from more than one server.
***************
*** 557,563 ****
--- 620,630 ----
  						       sizeof(no_addr));
  #else
  					int s1 = socket(PF_INET, SOCK_DGRAM,0);
+ #ifndef WINNT
  					if (s1 < 0)
+ #else
+ 					if (s1 == INVALID_SOCKET)
+ #endif
  						goto bad_dg_sock;
  					(void) dup2(s1, s);
  					(void) close(s1);
***************
*** 565,571 ****
--- 632,642 ----
  					       (stdout, ";; new DG socket\n"))
  #endif
  					connected = 0;
+ #ifndef WINNT
  					errno = 0;
+ #else
+ 					WSASetLastError(0);
+ #endif
  				}
  				if (sendto(s, (char*)buf, buflen, 0,
  					   (struct sockaddr *)nsap,
***************
*** 576,582 ****
--- 647,655 ----
  					_res_close();
  					goto next_ns;
  				}
+ #ifndef WINNT
  			}
+ #endif
  
  			/*
  			 * Wait for reply
***************
*** 607,618 ****
--- 680,699 ----
  				_res_close();
  				goto next_ns;
  			}
+ #ifndef WINNT
  			errno = 0;
+ #else
+ 			WSASetLastError(0);
+ #endif
  			fromlen = sizeof(struct sockaddr_in);
  			resplen = recvfrom(s, (char*)ans, anssiz, 0,
  					   (struct sockaddr *)&from, &fromlen);
  			if (resplen <= 0) {
+ #ifndef WINNT
  				Perror(stderr, "recvfrom", errno);
+ #else
+ 				Perror(stderr, "recvfrom", WSAGetLastError());
+ #endif
  				_res_close();
  				goto next_ns;
  			}
***************
*** 738,748 ****
--- 819,841 ----
  	_res_close();
  	if (!v_circuit)
  		if (!gotsomewhere)
+ #ifndef WINNT
  			errno = ECONNREFUSED;	/* no nameservers found */
+ #else
+ 			WSASetLastError(ECONNREFUSED);
+ #endif
  		else
+ #ifndef WINNT
  			errno = ETIMEDOUT;	/* no answer obtained */
+ #else
+ 			WSASetLastError(ETIMEDOUT);
+ #endif
  	else
+ #ifndef WINNT
  		errno = terrno;
+ #else
+ 		WSASetLastError(terrno);
+ #endif
  	return (-1);
  }
  
***************
*** 758,764 ****
--- 851,861 ----
  {
  	if (s >= 0) {
  		(void) close(s);
+ #ifndef WINNT
  		s = -1;
+ #else
+ 		s = INVALID_SOCKET;
+ #endif
  		connected = 0;
  		vc = 0;
  	}
Only in m:\bind/res: resolv.mak
Only in m:\bind/res: resolv.mdp
Only in m:\bind/res: resolv.ncb
Only in m:\bind/res: resolv.vcp
diff --context --recurs m:\bindb32/res/sethostent.c m:\bind/res/sethostent.c
*** m:\bindb32/res/sethostent.c	Mon Dec 25 21:59:15 1995
--- m:\bind/res/sethostent.c	Mon Dec 25 22:05:29 1995
***************
*** 36,43 ****
  static char rcsid[] = "$Id: sethostent.c,v 8.3 1995/06/29 09:26:28 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <netinet/in.h>
  #include <arpa/nameser.h>
  #include <netdb.h>
  #include <resolv.h>
--- 36,45 ----
  static char rcsid[] = "$Id: sethostent.c,v 8.3 1995/06/29 09:26:28 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <netinet/in.h>
! #endif
  #include <arpa/nameser.h>
  #include <netdb.h>
  #include <resolv.h>
Only in m:\bind/shres/netbsd: .cvsignore
Only in m:\bind/shres/netbsd: Letter
Only in m:\bind/tools: WinRel
Only in m:\bind/tools: instsrv.c
Only in m:\bind/tools: instsrv.exe
Only in m:\bind/tools: instsrv.mak
Only in m:\bind/tools: instsrv.mdp
Only in m:\bind/tools: instsrv.ncb
Only in m:\bind/tools: instsrv.vcp
Only in m:\bind/tools/nslookup: BOG.WRI
Only in m:\bind/tools/nslookup: WINNTPORT
Only in m:\bind/tools/nslookup: WinRel
diff --context --recurs m:\bindb32/tools/nslookup/commands.l m:\bind/tools/nslookup/commands.l
*** m:\bindb32/tools/nslookup/commands.l	Mon Dec 25 21:59:15 1995
--- m:\bind/tools/nslookup/commands.l	Mon Dec 25 22:05:29 1995
***************
*** 207,219 ****
  					    LookupHostWithServer(yytext, 0);
  					    return(1);
  					}
! ^{WS}*\n				{
! 					    return(1);
! 					}
! ^.*\n					{
! 					    printf("Unrecognized command: %s",
! 							yytext);
! 					    return(1);
! 					}
! \n					{ ; }
! %%
--- 207,219 ----
  					    LookupHostWithServer(yytext, 0);
  					    return(1);
  					}
! ^{WS}*\n   				{
! 					    return(1);
! 					}
! ^.*\n					{
! 					    printf("Unrecognized command: %s",
! 							yytext);
! 					    return(1);
! 					}
! \n					{ ; }
! %%                                      
diff --context --recurs m:\bindb32/tools/nslookup/debug.c m:\bind/tools/nslookup/debug.c
*** m:\bindb32/tools/nslookup/debug.c	Mon Dec 25 21:59:15 1995
--- m:\bind/tools/nslookup/debug.c	Mon Dec 25 22:05:30 1995
***************
*** 70,84 ****
   *******************************************************************************
   */
  
! #include <sys/param.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <resolv.h>
! #include <netdb.h>
! #include <stdio.h>
! #include "res.h"
! #include "../../conf/portability.h"
  
  /*
   *  Imported from res_debug.c
--- 70,86 ----
   *******************************************************************************
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <resolv.h>
! #include <netdb.h>
! #include <stdio.h>
! #include "res.h"
! #include "../../conf/portability.h"
  
  /*
   *  Imported from res_debug.c
***************
*** 87,92 ****
--- 89,101 ----
  extern char *_res_opcodes[];
  
  /*
+  *  Forward references
+  */
+ 
+ void Fprint_query(u_char *msg, u_char *eom, int printHeader, FILE *file);
+ 
+ 
+ /*
   *  Used to highlight the start of a record when printing it.
   */
  #define INDENT "    ->  "
***************
*** 98,103 ****
--- 107,113 ----
   * This is intended to be primarily a debugging routine.
   */
  
+ void
  Print_query(msg, eom, printHeader)
  	char *msg, *eom;
  	int printHeader;
***************
*** 105,110 ****
--- 115,121 ----
  	Fprint_query(msg, eom, printHeader,stdout);
  }
  
+ void
  Fprint_query(msg, eom, printHeader,file)
  	u_char *msg, *eom;
  	int printHeader;
***************
*** 124,130 ****
  	if (printHeader || (_res.options & RES_DEBUG2)) {
  	    fprintf(file,"    HEADER:\n");
  	    fprintf(file,"\topcode = %s", _res_opcodes[hp->opcode]);
! 	    fprintf(file,", id = %d", ntohs(hp->id));
  	    fprintf(file,", rcode = %s\n", _res_resultcodes[hp->rcode]);
  	    fprintf(file,"\theader flags: ");
  	    if (hp->qr) {
--- 135,141 ----
  	if (printHeader || (_res.options & RES_DEBUG2)) {
  	    fprintf(file,"    HEADER:\n");
  	    fprintf(file,"\topcode = %s", _res_opcodes[hp->opcode]);
! 	    fprintf(file,", id = %d", ntohs( (u_short) hp->id));
  	    fprintf(file,", rcode = %s\n", _res_resultcodes[hp->rcode]);
  	    fprintf(file,"\theader flags: ");
  	    if (hp->qr) {
***************
*** 140,155 ****
  		    fprintf(file,", want recursion");
  	    if (hp->ra)
  		    fprintf(file,", recursion avail.");
! 	    fprintf(file,"\n\tquestions = %d", ntohs(hp->qdcount));
! 	    fprintf(file,",  answers = %d", ntohs(hp->ancount));
! 	    fprintf(file,",  authority records = %d", ntohs(hp->nscount));
! 	    fprintf(file,",  additional = %d\n\n", ntohs(hp->arcount));
  	}
  
  	/*
  	 * Print question records.
  	 */
! 	if (n = ntohs(hp->qdcount)) {
  		fprintf(file,"    QUESTIONS:\n");
  		while (--n >= 0) {
  			fprintf(file,"\t");
--- 151,166 ----
  		    fprintf(file,", want recursion");
  	    if (hp->ra)
  		    fprintf(file,", recursion avail.");
! 	    fprintf(file,"\n\tquestions = %d", ntohs( (u_short) hp->qdcount));
! 	    fprintf(file,",  answers = %d", ntohs( (u_short) hp->ancount));
! 	    fprintf(file,",  authority records = %d", ntohs( (u_short) hp->nscount));
! 	    fprintf(file,",  additional = %d\n\n", ntohs( (u_short) hp->arcount));
  	}
  
  	/*
  	 * Print question records.
  	 */
! 	if (n = ntohs( (u_short) hp->qdcount)) {
  		fprintf(file,"    QUESTIONS:\n");
  		while (--n >= 0) {
  			fprintf(file,"\t");
***************
*** 167,173 ****
  	/*
  	 * Print authoritative answer records
  	 */
! 	if (n = ntohs(hp->ancount)) {
  		fprintf(file,"    ANSWERS:\n");
  		while (--n >= 0) {
  			fprintf(file, INDENT);
--- 178,184 ----
  	/*
  	 * Print authoritative answer records
  	 */
! 	if (n = ntohs( (u_short) hp->ancount)) {
  		fprintf(file,"    ANSWERS:\n");
  		while (--n >= 0) {
  			fprintf(file, INDENT);
***************
*** 179,185 ****
  	/*
  	 * print name server records
  	 */
! 	if (n = ntohs(hp->nscount)) {
  		fprintf(file,"    AUTHORITY RECORDS:\n");
  		while (--n >= 0) {
  			fprintf(file, INDENT);
--- 190,196 ----
  	/*
  	 * print name server records
  	 */
! 	if (n = ntohs( (u_short) hp->nscount)) {
  		fprintf(file,"    AUTHORITY RECORDS:\n");
  		while (--n >= 0) {
  			fprintf(file, INDENT);
***************
*** 191,197 ****
  	/*
  	 * print additional records
  	 */
! 	if (n = ntohs(hp->arcount)) {
  		fprintf(file,"    ADDITIONAL RECORDS:\n");
  		while (--n >= 0) {
  			fprintf(file, INDENT);
--- 202,208 ----
  	/*
  	 * print additional records
  	 */
! 	if (n = ntohs( (u_short) hp->arcount)) {
  		fprintf(file,"    ADDITIONAL RECORDS:\n");
  		while (--n >= 0) {
  			fprintf(file, INDENT);
***************
*** 508,514 ****
  				struct servent *s;
  
   				if (c & 0200) {
! 					s = getservbyport((int)htons(n),
  					    protoPtr ? protoPtr->p_name : NULL);
  					if (s != NULL) {
  					    fprintf(file,"  %s", s->s_name);
--- 519,525 ----
  				struct servent *s;
  
   				if (c & 0200) {
! 					s = getservbyport((int)htons( (u_short) n),
  					    protoPtr ? protoPtr->p_name : NULL);
  					if (s != NULL) {
  					    fprintf(file,"  %s", s->s_name);
diff --context --recurs m:\bindb32/tools/nslookup/getinfo.c m:\bind/tools/nslookup/getinfo.c
*** m:\bindb32/tools/nslookup/getinfo.c	Mon Dec 25 21:59:15 1995
--- m:\bind/tools/nslookup/getinfo.c	Mon Dec 25 22:05:30 1995
***************
*** 71,87 ****
   ******************************************************************************
   */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <resolv.h>
! #include <stdio.h>
! #include <ctype.h>
! #include "res.h"
! #include "../../conf/portability.h"
  
  extern char *_res_resultcodes[];
  extern char *res_skip();
  
--- 71,90 ----
   ******************************************************************************
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif 
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <resolv.h>
! #include <stdio.h>
! #include <ctype.h>
! #include "res.h"
! #include "../../conf/portability.h"
  
+ 
  extern char *_res_resultcodes[];
  extern char *res_skip();
  
***************
*** 118,123 ****
--- 121,135 ----
  
  #define GetShort(cp)	_getshort(cp); cp += INT16SZ;
  
+ /*
+  * Forward references
+  */
+ 
+ int GetHostDomain(struct in_addr *nsAddrPtr, int queryClass, int queryType, char *name, 
+               char *domain, HostInfo *hostPtr, Boolean isServer);
+ static int GetAnswer(struct in_addr	*nsAddrPtr, int queryType, char *msg, int msglen, Boolean iquery, 
+                      register HostInfo	*hostPtr, Boolean isServer);
+ 
  
  /*
   ******************************************************************************
***************
*** 190,199 ****
  	return (headerPtr->rcode);
      }
  
!     qdcount = ntohs(headerPtr->qdcount);
!     ancount = ntohs(headerPtr->ancount);
!     arcount = ntohs(headerPtr->arcount);
!     nscount = ntohs(headerPtr->nscount);
  
      /*
       * If there are no answer, n.s. or additional records
--- 202,211 ----
  	return (headerPtr->rcode);
      }
  
!     qdcount = ntohs( (u_short) headerPtr->qdcount);
!     ancount = ntohs( (u_short) headerPtr->ancount);
!     arcount = ntohs( (u_short) headerPtr->arcount);
!     nscount = ntohs( (u_short) headerPtr->nscount);
  
      /*
       * If there are no answer, n.s. or additional records
***************
*** 599,619 ****
  	    return (GetHostDomain(nsAddrPtr, queryClass, queryType,
  		    cp, (char *)NULL, hostPtr, isServer));
      }
! 
!     /*
!      * If there are dots in the name already, let's just give it a try
!      * 'as is'.  The threshold can be set with the "ndots" option.
!      */
!     if (n >= _res.ndots) {
! 	    result = GetHostDomain(nsAddrPtr, queryClass, queryType,
! 				   name, (char *)NULL, hostPtr, isServer);
!             if (result == SUCCESS)
! 	        return (result);
! 	    if (result == NO_INFO)
! 		got_nodata++;
!             tried_as_is++;
!     }
! 
      /*
       * We do at least one level of search if
       *	- there is no dot and RES_DEFNAME is set, or
--- 611,631 ----
  	    return (GetHostDomain(nsAddrPtr, queryClass, queryType,
  		    cp, (char *)NULL, hostPtr, isServer));
      }
!     
!         /*
!        * If there are dots in the name already, let's just give it a try
!        * 'as is'.  The threshold can be set with the "ndots" option.
!        */
!         if (n >= (int)_res.ndots) {
!     	    result = GetHostDomain(nsAddrPtr, queryClass, queryType,
!     				   name, (char *)NULL, hostPtr, isServer);
!                 if (result == SUCCESS)
!     	        return (result);
!     	    if (result == NO_INFO)
!     		got_nodata++;
!                 tried_as_is++;
!         }
!     
      /*
       * We do at least one level of search if
       *	- there is no dot and RES_DEFNAME is set, or
***************
*** 644,650 ****
  	    if ((result != NXDOMAIN && result != NO_INFO) ||
  		(_res.options & RES_DNSRCH) == 0)
  		    break;
! 	}
      /* if we have not already tried the name "as is", do that now.
       * note that we do this regardless of how many dots were in the
       * name or whether it ends with a dot.
--- 656,662 ----
  	    if ((result != NXDOMAIN && result != NO_INFO) ||
  		(_res.options & RES_DNSRCH) == 0)
  		    break;
!     }
      /* if we have not already tried the name "as is", do that now.
       * note that we do this regardless of how many dots were in the
       * name or whether it ends with a dot.
***************
*** 663,668 ****
--- 675,681 ----
   * Perform a query on the concatenation of name and domain,
   * removing a trailing dot from name if domain is NULL.
   */
+ int
  GetHostDomain(nsAddrPtr, queryClass, queryType, name, domain, hostPtr, isServer)
      struct in_addr	*nsAddrPtr;
      int			queryClass;
diff --context --recurs m:\bindb32/tools/nslookup/list.c m:\bind/tools/nslookup/list.c
*** m:\bindb32/tools/nslookup/list.c	Mon Dec 25 21:59:15 1995
--- m:\bind/tools/nslookup/list.c	Mon Dec 25 22:05:31 1995
***************
*** 70,85 ****
   *******************************************************************************
   */
  
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <resolv.h>
! #include <netdb.h>
! #include <stdio.h>
! #include <limits.h>
! #include <ctype.h>
  #include <errno.h>
  #include "res.h"
  #include "../../conf/portability.h"
--- 70,87 ----
   *******************************************************************************
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <resolv.h>
! #include <netdb.h>
! #include <stdio.h>
! #include <limits.h>
! #include <ctype.h>
  #include <errno.h>
  #include "res.h"
  #include "../../conf/portability.h"
***************
*** 98,103 ****
--- 100,114 ----
  extern int	queryType;
  extern int	queryClass;
  
+ 
+ /*
+  * Forward references
+  */
+ 
+ int
+ PrintListInfo(FILE *file, u_char *msg, u_char *eom, int qtype, char *domain);
+ 
+ 
  static int sockFD = -1;
  int ListSubr();
  
***************
*** 308,316 ****
  	 */
  
  	__putshort(msglen, (u_char *)&len);
! 
          if (write(sockFD, (char *)&len, INT16SZ) != INT16SZ ||
              write(sockFD, (char *) &buf, msglen) != msglen) {
  		perror("ls: write");
  		(void) close(sockFD);
  		sockFD = -1;
--- 319,334 ----
  	 */
  
  	__putshort(msglen, (u_char *)&len);
!     
!   #ifndef WINNT
          if (write(sockFD, (char *)&len, INT16SZ) != INT16SZ ||
              write(sockFD, (char *) &buf, msglen) != msglen) {
+   #else
+ 
+         if (send(sockFD,(const char *)&len,INT16SZ,0) != INT16SZ  ||
+             send(sockFD,(const char *)&buf,msglen,0) != msglen) {
+   #endif
+ 
  		perror("ls: write");
  		(void) close(sockFD);
  		sockFD = -1;
***************
*** 324,330 ****
  	if (cmd == NULL) {
  	    filePtr = stdout;
  	} else {
! 	    filePtr = OpenFile(cmd, file);
              if (filePtr == NULL) {
                  fprintf(stderr, "*** Can't open %s for writing\n", file);
  		(void) close(sockFD);
--- 342,348 ----
  	if (cmd == NULL) {
  	    filePtr = stdout;
  	} else {
! 	    filePtr = AppOpenFile(cmd, file);
              if (filePtr == NULL) {
                  fprintf(stderr, "*** Can't open %s for writing\n", file);
  		(void) close(sockFD);
***************
*** 435,441 ****
--- 453,463 ----
  
  	    cp = (u_char *)&tmp;
  	    amtToRead = INT16SZ;
+ #ifndef WINNT
  	    while ((numRead = read(sockFD, cp, amtToRead)) > 0) {
+ #else
+ 	    while ((numRead = recv(sockFD, cp, amtToRead,0)) > 0) {
+ #endif
  		cp += numRead;
  		if ((amtToRead -= numRead) <= 0)
  			break;
***************
*** 467,473 ****
--- 489,500 ----
  
  	    amtToRead = len;
  	    cp = answer;
+         #ifndef WINNT
  	    while (amtToRead > 0 && (numRead=read(sockFD, cp, amtToRead)) > 0) {
+ #else
+ 	    while (amtToRead > 0 && (numRead=recv(sockFD, cp, amtToRead,0)) > 0) {
+ 
+ #endif
  		cp += numRead;
  		amtToRead -= numRead;
  	    }
***************
*** 488,494 ****
  		fflush(stdout);
  	    }
  	    cp = answer + HFIXEDSZ;
! 	    if (ntohs(((HEADER* )answer)->qdcount) > 0)
  		cp += dn_skipname((u_char *)cp,
  		    (u_char *)answer + len) + QFIXEDSZ;
  	    nmp = cp;
--- 515,521 ----
  		fflush(stdout);
  	    }
  	    cp = answer + HFIXEDSZ;
! 	    if (ntohs( (u_short) ((HEADER* )answer)->qdcount) > 0)
  		cp += dn_skipname((u_char *)cp,
  		    (u_char *)answer + len) + QFIXEDSZ;
  	    nmp = cp;
***************
*** 534,541 ****
  		fprintf(stderr,
  	       "  result: %s, answers = %d, authority = %d, additional = %d\n",
  			_res_resultcodes[headerPtr->rcode],
! 			ntohs(headerPtr->ancount), ntohs(headerPtr->nscount),
! 			ntohs(headerPtr->arcount));
  		return(ERROR);
  	    default:
  		return(ERROR);
--- 561,568 ----
  		fprintf(stderr,
  	       "  result: %s, answers = %d, authority = %d, additional = %d\n",
  			_res_resultcodes[headerPtr->rcode],
! 			ntohs( (u_short) headerPtr->ancount), ntohs( (u_short) headerPtr->nscount),
! 			ntohs( (u_short) headerPtr->arcount));
  		return(ERROR);
  	    default:
  		return(ERROR);
***************
*** 582,587 ****
--- 609,615 ----
  }
  
  
+ int
  PrintListInfo(file, msg, eom, qtype, domain)
      FILE	*file;
      u_char	*msg, *eom;
***************
*** 613,622 ****
       *  there aren't any question records.
       */
  
!     if (ntohs(headerPtr->ancount) == 0) {
  	return(NO_INFO);
      } else {
! 	if (ntohs(headerPtr->qdcount) > 0) {
  	    nameLen = dn_skipname(cp, eom);
  	    if (nameLen < 0)
  		return (ERROR);
--- 641,650 ----
       *  there aren't any question records.
       */
  
!     if (ntohs( (u_short) headerPtr->ancount) == 0) {
  	return(NO_INFO);
      } else {
! 	if (ntohs( (u_short) headerPtr->qdcount) > 0) {
  	    nameLen = dn_skipname(cp, eom);
  	    if (nameLen < 0)
  		return (ERROR);
***************
*** 877,882 ****
--- 905,911 ----
   *******************************************************************************
   */
  
+ void
  ViewList(string)
      char *string;
  {
***************
*** 912,918 ****
--- 941,953 ----
  {
  	struct servent		*sp;
  	struct sockaddr_in	sin;
+     #ifndef WINNT
  	register FILE		*f;
+     #else
+     char f[5000];
+     int numread = 0;
+     int i;
+     #endif
  	register int		c;
  	register int		lastc;
  	char			name[NAME_LEN];
***************
*** 968,974 ****
  	if (!putToFile) {
  	    filePtr = stdout;
  	} else {
! 	    filePtr = OpenFile(string, file);
  	    if (filePtr == NULL) {
  		fprintf(stderr, "*** Can't open %s for writing\n", file);
  		close(sockFD);
--- 1003,1009 ----
  	if (!putToFile) {
  	    filePtr = stdout;
  	} else {
! 	    filePtr = AppOpenFile(string, file);
  	    if (filePtr == NULL) {
  		fprintf(stderr, "*** Can't open %s for writing\n", file);
  		close(sockFD);
***************
*** 980,990 ****
  	fprintf(filePtr, "[%s]\n", curHostInfo.name);
  
  	if (name[0] != '\0') {
  	    write(sockFD, "/W ", 3);
! 	}
  	write(sockFD, name, strlen(name));
  	write(sockFD, "\r\n", 2);
! 	f = fdopen(sockFD, "r");
  	lastc = '\n';
  	while ((c = getc(f)) != EOF) {
  	    switch (c) {
--- 1015,1033 ----
  	fprintf(filePtr, "[%s]\n", curHostInfo.name);
  
  	if (name[0] != '\0') {
+ #ifndef WINNT
  	    write(sockFD, "/W ", 3);
!         	}
  	write(sockFD, name, strlen(name));
  	write(sockFD, "\r\n", 2);
! #else
!    /* send(sockFD,"/W",3,0); */
!          }
! 	send(sockFD, name, strlen(name),0);
! 	send(sockFD, "\r\n", 2,0);
! 	#endif
! #ifndef WINNT	
! 	f = fdopen(sockFD, "r"); 
  	lastc = '\n';
  	while ((c = getc(f)) != EOF) {
  	    switch (c) {
***************
*** 1000,1009 ****
  	    }
  	    putc(lastc = c, filePtr);
  	}
! 	if (lastc != '\n') {
  	    putc('\n', filePtr);
! 	}
! 	putc('\n', filePtr);
  
  	close(sockFD);
  	sockFD = -1;
--- 1043,1076 ----
  	    }
  	    putc(lastc = c, filePtr);
  	}
! #else
!     while ((numread = recv(sockFD,(char *)f,4999,0)) != 0)
!       {
! 
! 	   for (i=0; i<=numread; i++)
!         {
!           c = f[i];
!           switch (c) 
!           {
! 		    case 0210:
! 		    case 0211:
! 		    case 0212:
! 		    case 0214:
! 	  		      c -= 0200;
! 			      break;
! 		    case 0215:
! 			     c = '\n';
! 			     break;
! 	       }
! 	        putc(lastc = c, filePtr);
!       }       
!       }
!  #endif
! 	if (lastc != '\n') 
! 	  {
  	    putc('\n', filePtr);
! 	  }
! 	  putc('\n', filePtr);
  
  	close(sockFD);
  	sockFD = -1;
***************
*** 1015,1020 ****
--- 1082,1088 ----
  	return (SUCCESS);
  }
  
+ void
  ListHost_close()
  {
      if (sockFD != -1) {
diff --context --recurs m:\bindb32/tools/nslookup/main.c m:\bind/tools/nslookup/main.c
*** m:\bindb32/tools/nslookup/main.c	Mon Dec 25 21:59:15 1995
--- m:\bind/tools/nslookup/main.c	Mon Dec 25 22:05:31 1995
***************
*** 79,94 ****
   ******************************************************************************
   */
  
! #include <sys/param.h>
! #include <netdb.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <resolv.h>
! #include <signal.h>
! #include <setjmp.h>
! #include <ctype.h>
  #include <stdio.h>
  #include <errno.h>
  #include <limits.h>
--- 79,98 ----
   ******************************************************************************
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <netinet/in.h>
! #include <setjmp.h>
! #endif
! #include <netdb.h>
! #ifndef WINNT
! #include <sys/socket.h>
! #endif
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <resolv.h>
! #include <signal.h>
! #include <ctype.h>
  #include <stdio.h>
  #include <errno.h>
  #include <limits.h>
***************
*** 96,102 ****
  #include "pathnames.h"
  #include "../../conf/portability.h"
  
! 
  /*
   * Name of a top-level name server. Can be changed with 
   * the "set root" command.
--- 100,115 ----
  #include "pathnames.h"
  #include "../../conf/portability.h"
  
!   /* 
!    * Forward references
!    */
!   void Usage();
!   void LocalServer(HostInfo *defaultPtr);
!   int  LookupHost(char *string, Boolean putToFile);
!   void res_re_init();
!   void res_dnsrch(register char *cp);
!   int  SetOption(register char *option);
!   
  /*
   * Name of a top-level name server. Can be changed with 
   * the "set root" command.
***************
*** 107,112 ****
--- 120,128 ----
  #endif
  char		rootServerName[NAME_LEN] = ROOT_SERVER;
  
+   #ifdef WINNT
+   HANDLE hReadWriteEvent = NULL;
+   #endif
  
  /*
   *  Import the state information from the resolver library.
***************
*** 140,152 ****
  int		queryClass = C_IN;
  
  /*
!  * Stuff for Interrupt (control-C) signal handler.
   */
  
  extern SIG_FN	IntrHandler();
- FILE		*filePtr;
  jmp_buf		env;
! 
  
  /*
   * Browser command for help and view.
--- 156,171 ----
  int		queryClass = C_IN;
  
  /*
!  * Stuff for Interrupt (control-C) signal handler.                    
   */
  
+ #ifndef WINNT
  extern SIG_FN	IntrHandler();
  jmp_buf		env;
! #else
! 	char *pathnslookuprc, *pathpagercmd, *pathhelpfile;
! #endif
! FILE		*filePtr;
  
  /*
   * Browser command for help and view.
***************
*** 156,161 ****
--- 175,206 ----
  static void CvtAddrToPtr();
  static void ReadRC();
  
+ #ifdef WINNT
+ /* Expand environmental variables in file pathnames */
+ /* XXX - Would it be better to store/retrieve pathnames from the registry? */
+ void
+ expand_paths(void)
+ {
+ 
+ 	pathnslookuprc = (char *)malloc(MAX_PATH);
+ 	if (!ExpandEnvironmentStrings(_PATH_NSLOOKUPRC, pathnslookuprc, MAX_PATH)) {
+ 		syslog(LOG_ERR, "ExpandEnvironmentStrings(_PATH_NSLOOKUPRC) failed: %m\n");
+ 	} else
+ 
+ 	pathpagercmd = (char *)malloc(MAX_PATH);
+ 	if (!ExpandEnvironmentStrings(_PATH_PAGERCMD, pathpagercmd, MAX_PATH)) {
+ 		syslog(LOG_ERR, "ExpandEnvironmentStrings(_PATH_PAGERCMD) failed: %m\n");
+ 	} else
+ 		 
+ 	pathhelpfile = (char *)malloc(MAX_PATH);
+ 	if (!ExpandEnvironmentStrings(_PATH_HELPFILE, pathhelpfile, MAX_PATH)) {
+ 		syslog(LOG_ERR, "ExpandEnvironmentStrings(_PATH_HELPFILE) failed: %m\n");
+ 	}
+ 
+ }
+ #endif /* WINNT */
+ 
+ 
  
  /*
   ******************************************************************************
***************
*** 182,187 ****
--- 227,253 ----
      /*
       *  Initialize the resolver library routines.
       */
+      
+ #ifdef WINNT
+ /* lgk moved startup to beginning.. */
+ 
+ 
+ 
+ 
+ 	hReadWriteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+    {
+  	WORD wVersionRequested;
+ 	WSADATA wsaData;
+ 
+         expand_paths();
+ 	wVersionRequested = MAKEWORD(1,1);
+ 	if (WSAStartup(wVersionRequested, &wsaData)) {
+ 		syslog(LOG_ERR, "No useable winsock.dll: %m");
+ 		return (-1);
+ 	}
+ 
+    }
+ #endif /* WINNT */
  
      if (res_init() == -1) {
  	fprintf(stderr,"*** Can't initialize resolver.\n");
***************
*** 320,332 ****
  
  	pager = getenv("PAGER");
  	if (pager == NULL) {
  	    pager = _PATH_PAGERCMD;
  	}
- 
  	/*
  	 * Setup the environment to allow the interrupt handler to return here.
  	 */
! 
  	(void) setjmp(env);
  
  	/* 
--- 386,401 ----
  
  	pager = getenv("PAGER");
  	if (pager == NULL) {
+ #ifndef WINNT 
  	    pager = _PATH_PAGERCMD;
+ #else
+             pager = pathpagercmd;
+ #endif
  	}
  	/*
  	 * Setup the environment to allow the interrupt handler to return here.
  	 */
! #ifndef WINNT
  	(void) setjmp(env);
  
  	/* 
***************
*** 335,341 ****
  
  	signal(SIGINT, IntrHandler);
  	signal(SIGPIPE, SIG_IGN);
! 
  	/*
  	 * Read and evaluate commands. The commands are described in commands.l
  	 * Yylex returns 0 when ^D or 'exit' is typed. 
--- 404,410 ----
  
  	signal(SIGINT, IntrHandler);
  	signal(SIGPIPE, SIG_IGN);
! #endif
  	/*
  	 * Read and evaluate commands. The commands are described in commands.l
  	 * Yylex returns 0 when ^D or 'exit' is typed. 
***************
*** 343,348 ****
--- 412,418 ----
  
  	printf("> ");
  	fflush(stdout);
+ 
  	while(yylex()) {
  	    printf("> ");
  	    fflush(stdout);
***************
*** 352,357 ****
--- 422,428 ----
  }
  
  
+ void
  LocalServer(defaultPtr)
      HostInfo *defaultPtr;
  {
***************
*** 359,367 ****
  
      (void) gethostname(hostName, sizeof(hostName));
  
!     defaultAddr.s_addr = htonl(INADDR_ANY);
!     (void) GetHostInfoByName(&defaultAddr, C_IN, T_A,
  			     "0.0.0.0", defaultPtr, 1);
      free(defaultPtr->name);
      defaultPtr->name = Calloc(1, sizeof(hostName)+1);
      strcpy(defaultPtr->name, hostName);
--- 430,446 ----
  
      (void) gethostname(hostName, sizeof(hostName));
  
! #ifndef WINNT
!     defaultAddr.s_addr = htonl(INADDR_ANY); 
!       (void) GetHostInfoByName(&defaultAddr, C_IN, T_A,
  			     "0.0.0.0", defaultPtr, 1);
+ #else /* lgk the 0.0.0.0 doesn't work for nt so set to loopback */
+     defaultAddr.s_addr = htonl(INADDR_LOOPBACK);
+           (void) GetHostInfoByName(&defaultAddr, C_IN, T_A,
+ 			     "127.0.0.1", defaultPtr, 1);
+ 
+ #endif
+   
      free(defaultPtr->name);
      defaultPtr->name = Calloc(1, sizeof(hostName)+1);
      strcpy(defaultPtr->name, hostName);
***************
*** 378,383 ****
--- 457,463 ----
   ******************************************************************************
   */
  
+ void 
  Usage()
  {
      fprintf(stderr, "Usage:\n");
***************
*** 675,681 ****
      if (!putToFile) {
  	filePtr = stdout;
      } else {
! 	filePtr = OpenFile(string, file);
  	if (filePtr == NULL) {
  	    fprintf(stderr, "*** Can't open %s for writing\n", file);
  	    return(ERROR);
--- 755,761 ----
      if (!putToFile) {
  	filePtr = stdout;
      } else {
! 	filePtr = AppOpenFile(string, file);
  	if (filePtr == NULL) {
  	    fprintf(stderr, "*** Can't open %s for writing\n", file);
  	    return(ERROR);
***************
*** 736,742 ****
      if (!putToFile) {
  	filePtr = stdout;
      } else {
! 	filePtr = OpenFile(string, file);
  	if (filePtr == NULL) {
  	    fprintf(stderr, "*** Can't open %s for writing\n", file);
  	    return(ERROR);
--- 816,822 ----
      if (!putToFile) {
  	filePtr = stdout;
      } else {
! 	filePtr = AppOpenFile(string, file);
  	if (filePtr == NULL) {
  	    fprintf(stderr, "*** Can't open %s for writing\n", file);
  	    return(ERROR);
***************
*** 925,930 ****
--- 1005,1011 ----
  /*
   * Fake a reinitialization when the domain is changed.
   */
+ void
  res_re_init()
  {
      register char *cp, **pp;
***************
*** 947,952 ****
--- 1028,1034 ----
  
  #define SRCHLIST_SEP '/'
  
+ void
  res_dnsrch(cp)
      register char *cp;
  {
***************
*** 1043,1050 ****
  PrintHelp()
  {
  	char cmd[PATH_MAX];
! 
  	sprintf(cmd, "%s %s", pager, _PATH_HELPFILE);
  	system(cmd);
  }
  
--- 1125,1137 ----
  PrintHelp()
  {
  	char cmd[PATH_MAX];
! #ifndef WINNT
  	sprintf(cmd, "%s %s", pager, _PATH_HELPFILE);
+ #else
+ 	sprintf(cmd, "%s < %s", pager, pathhelpfile);
+ #endif
+ 
+         /* printf("path helpfile = %s ",pathhelpfile); */
  	system(cmd);
  }
  
***************
*** 1097,1103 ****
--- 1184,1194 ----
  
      if ((cp = getenv("HOME")) != NULL) {
  	(void) strcpy(buf, cp);
+ #ifndef WINNT
  	(void) strcat(buf, _PATH_NSLOOKUPRC);
+ #else
+ 	(void) strcat(buf, pathnslookuprc);
+ #endif
  
  	if ((fp = fopen(buf, "r")) != NULL) {
  	    while (fgets(buf, sizeof(buf), fp) != NULL) {
Only in m:\bind/tools/nslookup: nslookup.exe
Only in m:\bind/tools/nslookup: nslookup.mak
Only in m:\bind/tools/nslookup: nslookup.mdp
Only in m:\bind/tools/nslookup: nslookup.ncb
Only in m:\bind/tools/nslookup: nslookup.vcp
Only in m:\bind/tools/nslookup: nslookupnt.zip
diff --context --recurs m:\bindb32/tools/nslookup/pathnames.h m:\bind/tools/nslookup/pathnames.h
*** m:\bindb32/tools/nslookup/pathnames.h	Mon Dec 25 21:59:15 1995
--- m:\bind/tools/nslookup/pathnames.h	Mon Dec 25 22:05:31 1995
***************
*** 59,71 ****
   */
  
  #define	_PATH_NSLOOKUPRC	"/.nslookuprc"
! #define _PATH_PAGERCMD		"more"
! 
! #ifndef _PATH_HELPFILE
! #if defined(BSD) && BSD >= 198810
! #define	_PATH_HELPFILE		"/usr/share/misc/nslookup.help"
! #else
! #define _PATH_HELPFILE		"/usr/lib/nslookup.help"
  #endif
  #endif
  
--- 59,80 ----
   */
  
  #define	_PATH_NSLOOKUPRC	"/.nslookuprc"
! 
! #ifndef WINNT
! #define _PATH_PAGERCMD		"more"
! #else
! #define _PATH_PAGERCMD		"more"
! #endif
! 
! #ifndef _PATH_HELPFILE
! #if defined(BSD) && BSD >= 198810
! #define	_PATH_HELPFILE		"/usr/share/misc/nslookup.help"
! #else
! #ifdef WINNT
! #define _PATH_HELPFILE		"%windir%\\system32\\nslookup.help"
! #else
! #define _PATH_HELPFILE		"/usr/lib/nslookup.help"
! #endif
  #endif
  #endif
  
Only in m:\bind/tools/nslookup: readme.nt
diff --context --recurs m:\bindb32/tools/nslookup/res.h m:\bind/tools/nslookup/res.h
*** m:\bindb32/tools/nslookup/res.h	Mon Dec 25 21:59:15 1995
--- m:\bind/tools/nslookup/res.h	Mon Dec 25 22:05:32 1995
***************
*** 73,88 ****
   *******************************************************************************
   */
  
! #define TRUE	1
! #define FALSE	0
! typedef int Boolean;
  
  /*
!  *  Define return statuses in addtion to the ones defined in namserv.h
!  *   let SUCCESS be a synonym for NOERROR
   *
!  *	TIME_OUT	- a socket connection timed out.
!  *	NO_INFO		- the server didn't find any info about the host.
   *	ERROR		- one of the following types of errors:
   *			   dn_expand, res_mkquery failed
   *			   bad command line, socket operation failed, etc.
--- 73,97 ----
   *******************************************************************************
   */
  
! #ifndef _RES_H_
! #define _RES_H_
! 
! #ifdef WINNT
! #include <winsock.h>
! #include "../../conf/portability.h"
! #include <stdio.h>
! #endif
! 
! #define TRUE	1
! #define FALSE	0
! typedef int Boolean;
  
  /*
!  *  Define return statuses in addtion to the ones defined in namserv.h
!  *   let SUCCESS be a synonym for NOERROR
   *
!  *	TIME_OUT	- a socket connection timed out.
!  *	NO_INFO		- the server didn't find any info about the host.
   *	ERROR		- one of the following types of errors:
   *			   dn_expand, res_mkquery failed
   *			   bad command line, socket operation failed, etc.
***************
*** 155,172 ****
   */
  
  extern Boolean IsAddr();
! extern int  Print_query();
  extern unsigned char *Print_cdname();
  extern unsigned char *Print_cdname2();	/* fixed width */
  extern unsigned char *Print_rr();
  extern char *DecodeType();	/* descriptive version of p_type */
- extern char *DecodeError();
  extern char *Calloc();
! extern char *Malloc();
  extern void NsError();
  extern void PrintServer();
! extern void PrintHostInfo();
  extern void ShowOptions();
- extern void FreeHostInfoPtr();
- extern FILE *OpenFile();
  extern char *res_skip();
--- 164,230 ----
   */
  
  extern Boolean IsAddr();
! 
! /*
!  * debug.c definitions
!  */
! 
! void Print_query(char *msg, char *eom, int printHeader);
! 
  extern unsigned char *Print_cdname();
  extern unsigned char *Print_cdname2();	/* fixed width */
  extern unsigned char *Print_rr();
  extern char *DecodeType();	/* descriptive version of p_type */
  extern char *Calloc();
! 
  extern void NsError();
  extern void PrintServer();
! 
  extern void ShowOptions();
  extern char *res_skip();
+ 
+ /*
+  * subr.c definitions
+  */
+ 
+ char * Malloc(int size);
+ void PrintHostInfo(FILE	*file, char	*title, register HostInfo *hp);
+ FILE * AppOpenFile(char *string, char *file);
+ char * DecodeError(int result);
+ int StringToType(char *type, int dflt, FILE *errorfile);
+ int StringToClass(char *class, int dflt, FILE *errorfile);
+ char * DecodeType(int type);
+ 
+ 
+ /*
+  * getinfo.c definitions
+  */
+ 
+ static int GetAnswer(struct in_addr *nsAddrPtr, int queryType, char *msg, int msglen,
+                      Boolean iquery, register HostInfo *hostPtr, Boolean isServer);
+ int GetHostInfoByName(struct in_addr	*nsAddrPtr, int queryClass, int queryType,
+                       char *name, HostInfo *hostPtr, Boolean isServer);
+ int GetHostInfoByAddr(struct in_addr *nsAddrPtr, struct in_addr	*address, HostInfo *hostPtr);
+ void FreeHostInfoPtr( register HostInfo *hostPtr);
+ 
+ 
+ /*
+  * send.c definitions
+  */
+ 
+ int SendRequest(struct in_addr	*nsAddrPtr, char *buf, int buflen,
+ 	            char *answer, u_int anslen, int *trueLenPtr);
+ 
+ 
+ /* lgk new definitions */
+ extern int SetDefaultServer();
+ extern int Finger();
+ extern void ViewList();
+ extern void ListHosts();
+ extern void ListHostsByType();
+ extern int SetOption();
+ extern int LookupHost();
+ extern int LookupHostWithServer();
+ extern int yylex();
+ 
+ #endif /* _RES_H_ */
diff --context --recurs m:\bindb32/tools/nslookup/send.c m:\bind/tools/nslookup/send.c
*** m:\bindb32/tools/nslookup/send.c	Mon Dec 25 21:59:15 1995
--- m:\bind/tools/nslookup/send.c	Mon Dec 25 22:05:32 1995
***************
*** 74,92 ****
  /*
   * Send query to name server and wait for reply.
   */
! 
! #include <sys/param.h>
! #include <sys/time.h>
! #include <sys/socket.h>
! #include <sys/uio.h>
! #include <netinet/in.h>
! #include <stdio.h>
! #include <errno.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
  #include <resolv.h>
- #include "res.h"
  #include "../../conf/portability.h"
  
  static int s = -1;	/* socket used for communications */
  
--- 74,94 ----
  /*
   * Send query to name server and wait for reply.
   */
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/time.h>
! #include <sys/socket.h>
! #include <sys/uio.h>
! #include <netinet/in.h>
! #endif 
! #include <stdio.h>
! #include <errno.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
  #include <resolv.h>
  #include "../../conf/portability.h"
+ #include "res.h"
+ 
  
  static int s = -1;	/* socket used for communications */
  
***************
*** 236,242 ****
  				continue;
  			}
  			cp = answer;
! 			if ((resplen = _getshort((u_char*)cp)) > anslen) {
  				if (_res.options & RES_DEBUG)
  					fprintf(stderr, "response truncated\n");
  				len = anslen;
--- 238,244 ----
  				continue;
  			}
  			cp = answer;
! 			if ( (u_int)(resplen = _getshort((u_char*)cp)) > anslen) {
  				if (_res.options & RES_DEBUG)
  					fprintf(stderr, "response truncated\n");
  				len = anslen;
***************
*** 403,408 ****
--- 405,411 ----
   *
   * Called from the interrupt handler.
   */
+ void
  SendRequest_close()
  {
  	if (s != -1) {
diff --context --recurs m:\bindb32/tools/nslookup/skip.c m:\bind/tools/nslookup/skip.c
*** m:\bindb32/tools/nslookup/skip.c	Mon Dec 25 21:59:15 1995
--- m:\bind/tools/nslookup/skip.c	Mon Dec 25 22:05:33 1995
***************
*** 75,90 ****
   *******************************************************************************
   */
  
! #include <sys/param.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <resolv.h>
! #include <stdio.h>
! #include "../../conf/portability.h"
  
! char *res_skip_rr();
  
! 
  /*
   *******************************************************************************
   *
--- 75,92 ----
   *******************************************************************************
   */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <resolv.h>
! #include <stdio.h>
! #include "../../conf/portability.h"
  
! char *res_skip_rr();
  
! 
  /*
   *******************************************************************************
   *
***************
*** 126,132 ****
  	/*
  	 * skip question records.
  	 */
! 	if (n = ntohs(hp->qdcount) ) {
  		while (--n >= 0 && cp < eom) {
  			tmp = dn_skipname((u_char *)cp, (u_char *)eom);
  			if (tmp == -1) return(NULL);
--- 128,134 ----
  	/*
  	 * skip question records.
  	 */
! 	if (n = ntohs( (u_short) hp->qdcount) ) {
  		while (--n >= 0 && cp < eom) {
  			tmp = dn_skipname((u_char *)cp, (u_char *)eom);
  			if (tmp == -1) return(NULL);
***************
*** 140,146 ****
  	/*
  	 * skip authoritative answer records
  	 */
! 	if (n = ntohs(hp->ancount)) {
  		while (--n >= 0 && cp < eom) {
  			cp = res_skip_rr(cp, eom);
  			if (cp == NULL) return(NULL);
--- 142,148 ----
  	/*
  	 * skip authoritative answer records
  	 */
! 	if (n = ntohs( (u_short) hp->ancount)) {
  		while (--n >= 0 && cp < eom) {
  			cp = res_skip_rr(cp, eom);
  			if (cp == NULL) return(NULL);
***************
*** 151,157 ****
  	/*
  	 * skip name server records
  	 */
! 	if (n = ntohs(hp->nscount)) {
  		while (--n >= 0 && cp < eom) {
  			cp = res_skip_rr(cp, eom);
  			if (cp == NULL) return(NULL);
--- 153,159 ----
  	/*
  	 * skip name server records
  	 */
! 	if (n = ntohs( (u_short) hp->nscount)) {
  		while (--n >= 0 && cp < eom) {
  			cp = res_skip_rr(cp, eom);
  			if (cp == NULL) return(NULL);
***************
*** 162,168 ****
  	/*
  	 * skip additional records
  	 */
! 	if (n = ntohs(hp->arcount)) {
  		while (--n >= 0 && cp < eom) {
  			cp = res_skip_rr(cp, eom);
  			if (cp == NULL) return(NULL);
--- 164,170 ----
  	/*
  	 * skip additional records
  	 */
! 	if (n = ntohs( (u_short) hp->arcount)) {
  		while (--n >= 0 && cp < eom) {
  			cp = res_skip_rr(cp, eom);
  			if (cp == NULL) return(NULL);
diff --context --recurs m:\bindb32/tools/nslookup/subr.c m:\bind/tools/nslookup/subr.c
*** m:\bindb32/tools/nslookup/subr.c	Mon Dec 25 21:59:15 1995
--- m:\bind/tools/nslookup/subr.c	Mon Dec 25 22:05:33 1995
***************
*** 74,89 ****
   *******************************************************************************
   */
  
! #include <sys/types.h>
! #include <sys/param.h>
! #include <netdb.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <signal.h>
! #include <setjmp.h>
! #include <stdio.h>
  #include "res.h"
  #include "../../conf/portability.h"
  
--- 74,95 ----
   *******************************************************************************
   */
  
! #ifndef WINNT
! #include <sys/types.h>
! #include <sys/param.h>
! #endif
! #include <netdb.h>
! #ifndef WINNT
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! #include <signal.h>
! #ifndef WINNT
! #include <setjmp.h>
! #endif
! #include <stdio.h>
  #include "res.h"
  #include "../../conf/portability.h"
  
***************
*** 112,117 ****
--- 118,124 ----
   *
   *******************************************************************************
   */
+  #ifndef WINNT
  
  SIG_FN
  IntrHandler()
***************
*** 135,141 ****
      longjmp(env, 1);
  }
  
! 
  /*
   *******************************************************************************
   *
--- 142,148 ----
      longjmp(env, 1);
  }
  
!  #endif
  /*
   *******************************************************************************
   *
***************
*** 186,195 ****
        sigprocmask(SIG_UNBLOCK,&sset,NULL);
      }
  #else
!     { int saveMask;
        saveMask = sigblock(sigmask(SIGINT));
        ptr = malloc((unsigned) size);
        (void) sigsetmask(saveMask);
      }
  #endif
  #endif
--- 193,207 ----
        sigprocmask(SIG_UNBLOCK,&sset,NULL);
      }
  #else
!     { 
!       #ifndef WINNT
! 	  int saveMask;
        saveMask = sigblock(sigmask(SIGINT));
+       #endif
        ptr = malloc((unsigned) size);
+      #ifndef WINNT
        (void) sigsetmask(saveMask);
+      #endif
      }
  #endif
  #endif
***************
*** 316,322 ****
  /*
   *******************************************************************************
   *
!  *  OpenFile --
   *
   *	Parses a command string for a file name and opens
   *	the file.
--- 328,334 ----
  /*
   *******************************************************************************
   *
!  *  AppOpenFile --
   *
   *	Parses a command string for a file name and opens
   *	the file.
***************
*** 330,336 ****
   */
  
  FILE *
! OpenFile(string, file)
      char *string;
      char *file;
  {
--- 342,348 ----
   */
  
  FILE *
! AppOpenFile(string, file)
      char *string;
      char *file;
  {
Only in m:\bind/tools/nslookup: winntport.txt
Only in m:\bind/tools/nslookup: yylex.c
Only in m:\bind: winntport.txt
