Only in m:\bind: 494p1
Only in m:\bind: 495_to_495p1
Only in m:\bind: 495relpatch.log
Only in m:\bind: 495t6bpatch.log
Only in m:\bind: IBM
Only in m:\bind495p1: INSTALL
Only in m:\bind: INSTALL.txt
Only in m:\bind: MIRRORS
Only in m:\bind: bind-4.9.3-BETA26.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: bind-4.9.3-REL.tar.gz
Only in m:\bind: bind-4.9.4-P1.tar.gz
Only in m:\bind: bind-4.9.4-REL.tar.gz
Only in m:\bind: bind-4.9.4-T3B.tar.gz
Only in m:\bind: bind-4.9.4-T4B.tar.gz
Only in m:\bind: bind-4.9.4-T5B.tar.gz
Only in m:\bind495p1: bind-4.9.5-P1.tar
Only in m:\bind: bind-4.9.5-P1.tar.gz
Only in m:\bind: bind-4.9.5-REL.tar.gz
Only in m:\bind: bind-4.9.5-T1A.tar.gz
Only in m:\bind: bind-4.9.5-T3A.tar.gz
Only in m:\bind: bind-4.9.5-T5B.tar.gz
Only in m:\bind: bind-4.9.5-T6B.tar
Only in m:\bind: bind-4.9.5-T6B.tar.gz
Only in m:\bind: bind-4_9_5-T4B_tar.gz
Only in m:\bind: bindtestbin.zip
Only in m:\bind: bs1
Only in m:\bind: buildallnt.bat
diff --context --recurs m:\bind495p1/compat/include/sys/cdefs.h m:\bind/compat/include/sys/cdefs.h
*** m:\bind495p1/compat/include/sys/cdefs.h	Thu Dec 19 02:24:26 1996
--- m:\bind/compat/include/sys/cdefs.h	Tue Oct 08 13:11:58 1996
***************
*** 84,108 ****
  #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) */
  
--- 84,110 ----
  #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:\bind495p1/compat/lib/ftruncate.c m:\bind/compat/lib/ftruncate.c
*** m:\bind495p1/compat/lib/ftruncate.c	Thu Dec 19 02:24:26 1996
--- m:\bind/compat/lib/ftruncate.c	Tue Oct 08 13:12:44 1996
***************
*** 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:\bind495p1/compat/lib/gettimeofday.c m:\bind/compat/lib/gettimeofday.c
*** m:\bind495p1/compat/lib/gettimeofday.c	Thu Dec 19 02:24:26 1996
--- m:\bind/compat/lib/gettimeofday.c	Tue Oct 08 13:12:44 1996
***************
*** 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: lib44bsd95.mak
Only in m:\bind/compat/lib: lib44bsd95.mdp
Only in m:\bind/compat/lib: lib44bsd95.ncb
Only in m:\bind/compat/lib: lib44bsd_vc22.mak
Only in m:\bind/compat/lib: lib44bsd_vc22.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:\bind495p1/compat/lib/mktemp.c m:\bind/compat/lib/mktemp.c
*** m:\bind495p1/compat/lib/mktemp.c	Thu Dec 19 02:24:26 1996
--- m:\bind/compat/lib/mktemp.c	Tue Oct 08 13:12:44 1996
***************
*** 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:\bind495p1/compat/lib/strcasecmp.c m:\bind/compat/lib/strcasecmp.c
*** m:\bind495p1/compat/lib/strcasecmp.c	Thu Dec 19 02:24:26 1996
--- m:\bind/compat/lib/strcasecmp.c	Tue Oct 08 13:12:44 1996
***************
*** 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:\bind495p1/compat/lib/strerror.c m:\bind/compat/lib/strerror.c
*** m:\bind495p1/compat/lib/strerror.c	Thu Dec 19 02:24:26 1996
--- m:\bind/compat/lib/strerror.c	Tue Oct 08 13:12:44 1996
***************
*** 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
Only in m:\bind/compat/lib: strip.bat
diff --context --recurs m:\bind495p1/compat/lib/strpbrk.c m:\bind/compat/lib/strpbrk.c
*** m:\bind495p1/compat/lib/strpbrk.c	Thu Dec 19 02:24:26 1996
--- m:\bind/compat/lib/strpbrk.c	Tue Oct 08 13:12:44 1996
***************
*** 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:\bind495p1/compat/lib/strtoul.c m:\bind/compat/lib/strtoul.c
*** m:\bind495p1/compat/lib/strtoul.c	Thu Dec 19 02:24:26 1996
--- m:\bind/compat/lib/strtoul.c	Tue Oct 08 13:12:44 1996
***************
*** 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:\bind495p1/compat/lib/writev.c m:\bind/compat/lib/writev.c
*** m:\bind495p1/compat/lib/writev.c	Thu Dec 19 02:24:26 1996
--- m:\bind/compat/lib/writev.c	Tue Oct 08 13:12:44 1996
***************
*** 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)
***************
*** 82,87 ****
--- 83,163 ----
  	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.
+  */	
+ /* lgk win95 does not support overlapped/async file operations so change it to
+    synchronous */
+ #ifndef WIN95
+  
+ 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);
+ }
+ 
+ #else // is win95 ... no async overlapped io
+  
+ int
+ writev(fd, iov, iovcnt)
+ 	int fd;
+ 	struct iovec *iov;
+ 	int iovcnt;
+ {
+ 	int i;
+ 	char *base;
+ 	DWORD BytesWritten, TotalBytesWritten = 0, len, dwWait;
+ 	BOOL ret; 
+ 
+ 	for (i=0; i<iovcnt; i++) {
+ 		base = iov[i].iov_base;
+ 		len = (DWORD)iov[i].iov_len;
+ 		ret = WriteFile((HANDLE)fd, (char *)base, len,
+ 		              (LPDWORD)&BytesWritten, NULL);
+ 		if (ret == FALSE)
+ 		   return (-1);
+ 		TotalBytesWritten += BytesWritten;
+ 	}
+ 	return((int)TotalBytesWritten);
+ }
+ 
+ #endif // win95 or not
+ #endif // winnt
  
  #ifndef OWN_WRITEV
  int __bindcompat_writev;
diff --context --recurs m:\bind495p1/conf/options.h m:\bind/conf/options.h
*** m:\bind495p1/conf/options.h	Thu Dec 19 02:24:24 1996
--- m:\bind/conf/options.h	Mon Nov 11 16:00:10 1996
***************
*** 114,120 ****
  #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 LOC record parsing (ckd/vix) */
--- 114,122 ----
  #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 LOC record parsing (ckd/vix) */
diff --context --recurs m:\bind495p1/conf/portability.h m:\bind/conf/portability.h
*** m:\bind495p1/conf/portability.h	Thu Dec 19 02:24:24 1996
--- m:\bind/conf/portability.h	Thu Dec 19 02:34:10 1996
***************
*** 78,93 ****
  #define __BIND_PORTABILITY_H
  
  #include <sys/types.h>
! #include <sys/param.h>
! #include <signal.h>
! #include <string.h>
! #ifndef TIME_H_INCLUDED
  # include <sys/time.h>
! # define TIME_H_INCLUDED
  #endif
  
! /* (ISC = INTERACTIVE Systems Corporation in the next #ifdef, btw.) */
! #ifdef ISC
  # ifndef _POSIX_SOURCE
  #  define _POSIX_SOURCE
  # endif
--- 78,181 ----
  #define __BIND_PORTABILITY_H
  
  #include <sys/types.h>
! #ifndef WINNT
! #include <sys/param.h>
! #endif
! #include <string.h>
! #include <signal.h>
! #ifndef WINNT
! #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>
! #include <limits.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)
! #ifdef errno
! #undef errno
! #endif
! #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 */
! 
! /* (ISC = INTERACTIVE Systems Corporation in the next #ifdef, btw.) */
! #ifdef ISC
  # ifndef _POSIX_SOURCE
  #  define _POSIX_SOURCE
  # endif
***************
*** 220,226 ****
  #endif
  
  #if !defined(BSD) || (BSD <= 199006)
! # if !defined(NeXT)
  #  define NEED_INETADDR
  # endif
  # define NEED_INETATON
--- 308,314 ----
  #endif
  
  #if !defined(BSD) || (BSD <= 199006)
! # if !defined(NeXT)	&& !defined(WINNT)
  #  define NEED_INETADDR
  # endif
  # define NEED_INETATON
***************
*** 284,296 ****
  #  define NEED_STRTOUL
  # endif
  
! # ifndef NeXT
  extern char *getenv __P((char *));
  # else
  extern char *getenv __P((const char *));
  # endif
  
! # if !defined(DMALLOC) && !defined(NeXT)
  extern char *malloc(), *realloc(), *calloc();
  extern void free();
  # endif
--- 372,384 ----
  #  define NEED_STRTOUL
  # endif
  
! # if !defined(NeXT) && !defined(WINNT)
  extern char *getenv __P((char *));
  # else
  extern char *getenv __P((const char *));
  # endif
  
! # if !defined(DMALLOC) && !defined(NeXT) && !defined(WINNT)
  extern char *malloc(), *realloc(), *calloc();
  extern void free();
  # endif
***************
*** 306,312 ****
--- 394,402 ----
  # define STDIN_FILENO	0
  # define STDOUT_FILENO	1
  # define STDERR_FILENO	2
+ #ifndef WINNT
  extern int errno;
+ #endif
  
  extern int getdtablesize __P((void));
  # ifdef SHORT_FNAMES
***************
*** 345,351 ****
  #undef IP_OPTIONS
  #endif
  
! #if !defined(__STDC__) && !defined(const)
  # define const /*constant*/
  #endif
  
--- 435,441 ----
  #undef IP_OPTIONS
  #endif
  
! #if !defined(__STDC__) && !defined(const) && !defined(WINNT)
  # define const /*constant*/
  #endif
  
***************
*** 356,361 ****
--- 446,452 ----
  /* 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)
***************
*** 369,376 ****
  # endif
  #endif
  
! #if !defined(bcopy)	/* some machines have their own macros for this */
! # if (defined(USE_POSIX) && !defined(SUNOS4)) || \
  	 (defined(__STDC__) && !defined(sun) && !defined(sequent) \
  	  && !defined(M_UNIX))
  /* use ANSI C3.159-1989 (``ANSI C'') functions if possible;
--- 460,467 ----
  # endif
  #endif
  
! #if !defined(bcopy) /* some machines have their own macros for this */
! #if (defined(USE_POSIX) && !defined(SUNOS4)) || defined(WINNT) ||\
  	 (defined(__STDC__) && !defined(sun) && !defined(sequent) \
  	  && !defined(M_UNIX))
  /* use ANSI C3.159-1989 (``ANSI C'') functions if possible;
***************
*** 394,400 ****
  
  #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
--- 485,491 ----
  
  #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
***************
*** 411,417 ****
  
  #if (!defined(BSD) || (BSD < 43)) && !defined(__hpux)
  # define NEED_MKSTEMP
! # if !defined(__ultrix) && !defined(apollo)
  #  if !defined(_SCO_DS)
  #   define NEED_STRCASECMP
  #   define NEED_MKTEMP
--- 502,508 ----
  
  #if (!defined(BSD) || (BSD < 43)) && !defined(__hpux)
  # define NEED_MKSTEMP
! # if !defined(__ultrix) && !defined(apollo) && !defined(WINNT)
  #  if !defined(_SCO_DS)
  #   define NEED_STRCASECMP
  #   define NEED_MKTEMP
***************
*** 463,471 ****
--- 554,564 ----
  # 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
***************
*** 475,481 ****
  #define USE_WAITPID
  #endif
  
! #if !defined(USE_POSIX)
  #define waitpid(x,y,z) (wait3(y,z,(struct rusage *)NULL))
  #endif
  
--- 568,574 ----
  #define USE_WAITPID
  #endif
  
! #if !defined(USE_POSIX) && !defined(WINNT)
  #define waitpid(x,y,z) (wait3(y,z,(struct rusage *)NULL))
  #endif
  
***************
*** 491,496 ****
--- 584,590 ----
  #define WTERMSIG(x)	((x).w_termsig)
  #endif /* sequent */
  
+ #ifndef WINNT
  #if !defined(WIFEXITED)
  # define WIFEXITED(x) (!(x & 0177))
  #endif
***************
*** 503,508 ****
--- 597,603 ----
  #if !defined(WTERMSIG)
  # define WTERMSIG(x) (x & 0177)
  #endif
+ #endif
  
  #ifndef S_ISDIR
  # ifndef S_IFMT
***************
*** 535,541 ****
  #endif
  
  #if defined(NEED_STRTOUL) && \
! 	(defined(__ultrix) || defined(__osf__) || defined(NeXT))
  # undef NEED_STRTOUL
  #endif
  
--- 630,636 ----
  #endif
  
  #if defined(NEED_STRTOUL) && \
! 	(defined(__ultrix) || defined(__osf__) || defined(NeXT) || defined(WINNT))
  # undef NEED_STRTOUL
  #endif
  
***************
*** 594,600 ****
  /*
   * Assume that a system has fchmod() unless something above says otherwise.
   */
! #if !defined(HAVE_FCHMOD)
  # define HAVE_FCHMOD 1
  #endif
  
--- 689,695 ----
  /*
   * Assume that a system has fchmod() unless something above says otherwise.
   */
! #if !defined(HAVE_FCHMOD) && !defined(WINNT)
  # define HAVE_FCHMOD 1
  #endif
  
***************
*** 637,639 ****
--- 732,741 ----
  #endif
  
  #endif /*__BIND_PORTABILITY_H*/
+ 
+ #ifdef WINNT /* l kahn new definitions needed for vc++4.0 */
+ #define fstat _fstat
+ #define stat _stat
+ #define fileno _fileno
+ extern BOOL OnWinnt();
+ #endif
Only in m:\bind/contrib/decwrl: gethost.o
Only in m:\bind/contrib: host.tar.Z
Only in m:\bind/contrib/nutshell: ch09.check_del.c~
Only in m:\bind/contrib: winnt-dist
Only in m:\bind: cpl
Only in m:\bind: creadme.bat
Only in m:\bind: csums.bat
Only in m:\bind: d1.bat
Only in m:\bind: diffs.ksh
Only in m:\bind: diffs493relP1tont_context.txt
Only in m:\bind: diffs493relP1tont_nocontext.txt
Only in m:\bind: diffs493reltont_nocontext.txt
Only in m:\bind: diffs494p1tont_context.txt
Only in m:\bind: diffs494p1tont_nocontext.txt
Only in m:\bind: diffs494reltont_context.txt
Only in m:\bind: diffs494reltont_nocontext.txt
Only in m:\bind: diffs494t4atot4b_context.txt
Only in m:\bind: diffs494t4atot4b_nocontext.txt
Only in m:\bind: diffs494t5b_to_494rel_context.txt
Only in m:\bind: diffs495_t5b_to_t6b_context.txt
Only in m:\bind: diffs495p1c2_to_495p1rel_context.txt
Only in m:\bind: diffs495p1tont_context.txt
Only in m:\bind: diffs495p1tont_nocontext.txt
Only in m:\bind: diffs495relmsntont_context.txt
Only in m:\bind: diffs495relmsntont_nocontext.txt
Only in m:\bind: diffs495reltont_context.txt
Only in m:\bind: diffs495reltont_nocontext.txt
Only in m:\bind: diffs495t6btont_context.txt
Only in m:\bind: diffs495t6btont_contexto.txt
Only in m:\bind: diffs495t6btont_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:\bind495p1/doc/info: Linux-elf
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
Only in m:\bind: getfiles.bat
diff --context --recurs m:\bind495p1/include/arpa/inet.h m:\bind/include/arpa/inet.h
*** m:\bind495p1/include/arpa/inet.h	Thu Dec 19 02:24:23 1996
--- m:\bind/include/arpa/inet.h	Tue Oct 08 13:11:40 1996
***************
*** 63,78 ****
  
  /* 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));
--- 63,87 ----
  
  /* 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));
***************
*** 81,87 ****
--- 90,98 ----
  unsigned long	 inet_network __P((const char *));
  char		*inet_net_ntop __P((int, const void *, int, char *, size_t));
  int		 inet_net_pton __P((int, const char *, void *, size_t));
+ #ifndef WINNT
  char		*inet_ntoa __P((struct in_addr));
+ #endif
  int		 inet_pton __P((int, const char *, void *));
  const char	*inet_ntop __P((int, const void *, char *, size_t));
  u_int		 inet_nsap_addr __P((const char *, u_char *, int));
diff --context --recurs m:\bind495p1/include/arpa/nameser.h m:\bind/include/arpa/nameser.h
*** m:\bind495p1/include/arpa/nameser.h	Thu Dec 19 02:24:23 1996
--- m:\bind/include/arpa/nameser.h	Tue Oct 08 13:11:42 1996
***************
*** 83,98 ****
  #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>
  #endif
  
  /*
--- 83,100 ----
  #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>
  #endif
  
  /*
***************
*** 136,142 ****
--- 138,146 ----
  /*
   * 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 */
***************
*** 374,381 ****
  #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; \
  }
  
--- 378,385 ----
  #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:\bind495p1/include/netdb.h m:\bind/include/netdb.h
*** m:\bind495p1/include/netdb.h	Thu Dec 19 02:24:23 1996
--- m:\bind/include/netdb.h	Tue Oct 08 13:11:20 1996
***************
*** 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((unsigned long, int));
  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,175 ----
  
  #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((unsigned long, int)); /* u_long? */
! struct netent	*getnetbyname __P((const char *));
! #else
! struct hostent	*gethostbyaddr_nt __P((const char *, int, int));
! struct hostent	*gethostbyname_nt __P((const char *));
! struct hostent	*gethostbyname2 __P((const char *, int));
! struct hostent	*gethostent __P((void));
! struct netent	*getnetbyaddr __P((unsigned 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:\bind495p1/include/resolv.h m:\bind/include/resolv.h
*** m:\bind495p1/include/resolv.h	Thu Dec 19 02:24:23 1996
--- m:\bind/include/resolv.h	Thu Dec 19 02:32:59 1996
***************
*** 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,81 ----
  #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>
! #include "..\conf\portability.h"
! #endif
  
  /*
   * Revision information.  This is the release date in YYYYMMDD format.
***************
*** 87,93 ****
--- 94,105 ----
   */
  
  #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
  
  /*
Only in m:\bind: install
Only in m:\bind: leon.zip
Only in m:\bind: lib44bsd_vc22.mak
Only in m:\bind: lint495patch.txt
Only in m:\bind: log
Only in m:\bind: mkbeta.bat
Only in m:\bind: mkdist.bat
Only in m:\bind: mkmsnsrc.bat
Only in m:\bind: mkmsntxt.bat
Only in m:\bind: mksrc.bat
Only in m:\bind: mktxt.bat
Only in m:\bind/named: TAGS
diff --context --recurs m:\bind495p1/named/Version.c m:\bind/named/Version.c
*** m:\bind495p1/named/Version.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/Version.c	Thu Dec 19 02:14:40 1996
***************
*** 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,18 ----
  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.5-P1-Wednesday-18-December-96\n\tGregSchueman-LarryKahn-VirajBais";
! #endif
  
  #ifdef COMMENT
  
Only in m:\bind/named: WinRel
Only in m:\bind/named: bindtray.ico
Only in m:\bind/named: cnamefix
diff --context --recurs m:\bind495p1/named/db_defs.h m:\bind/named/db_defs.h
*** m:\bind495p1/named/db_defs.h	Thu Dec 19 02:24:23 1996
--- m:\bind/named/db_defs.h	Tue Oct 08 13:07:02 1996
***************
*** 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:\bind495p1/named/db_dump.c m:\bind/named/db_dump.c
*** m:\bind495p1/named/db_dump.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/db_dump.c	Tue Oct 08 13:06:58 1996
***************
*** 81,96 ****
   */
  
  #include <sys/types.h>
! #include <sys/param.h>
! #include <sys/stat.h>
! #include <sys/socket.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"
--- 81,100 ----
   */
  
  #include <sys/types.h>
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/stat.h>
! #include <sys/socket.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"
***************
*** 102,107 ****
--- 106,114 ----
  static void		putbyte __P((int, char **));
  #endif
  
+ char * inet_nsap_ntoa();
+ const char * inet_ntop();
+ 
  /*
   * Dump current cache in a format similar to RFC 883.
   *
***************
*** 414,420 ****
  				    fprintf(fp, "%d\t",
  				        (int)(dp->d_ttl - tt.tv_sec));
  			} else if (dp->d_ttl != USE_MINIMUM &&
! 			    dp->d_ttl != zones[dp->d_zone].z_minimum)
  				fprintf(fp, "%d\t", (int)dp->d_ttl);
  			else if (tab)
  			    (void) putc('\t', fp);
--- 421,427 ----
  				    fprintf(fp, "%d\t",
  				        (int)(dp->d_ttl - tt.tv_sec));
  			} else if (dp->d_ttl != USE_MINIMUM &&
! 			    (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);
***************
*** 633,639 ****
  				if (dp->d_size == INT32SZ) {
  					GETLONG(n, cp);
  				} else {
! 					n = -2;		/* XXX - hack */
  				}
  				fprintf(fp, "%u", n);
  				break;
--- 640,646 ----
  				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:\bind495p1/named/db_func.h m:\bind/named/db_func.h
*** m:\bind495p1/named/db_func.h	Thu Dec 19 02:24:23 1996
--- m:\bind/named/db_func.h	Thu Oct 31 14:40:50 1996
***************
*** 61,66 ****
--- 61,70 ----
  #ifdef GEN_AXFR
  			get_class __P((char *)),
  #endif
+ 
+ #ifdef WINNT
+                writemsg_sock __P((SOCKET, u_char *, int)),
+ #endif
  			writemsg __P((int, u_char *, int)),
  			dhash __P((const u_char *, int)),
  			nhash __P((const char *)),
diff --context --recurs m:\bind495p1/named/db_glue.c m:\bind/named/db_glue.c
*** m:\bind495p1/named/db_glue.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/db_glue.c	Fri Nov 01 03:55:58 1996
***************
*** 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,402 ----
  	int s;
  
  	do {
+ #ifndef WINNT
  		errno = 0;
+ #else
+ 		WSASetLastError(0);
+ #endif
+ #ifndef WINNT
  		s = close(fd);
  	} while (s < 0 && errno == EINTR);
+ #else
+ 		s = closesocket(fd);
+ 	} while (s < 0 && errno == WSAEINTR);
+ #endif
  
+ #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));
***************
*** 459,464 ****
--- 483,507 ----
  	return (0);
  }
  
+ #ifdef WINNT
+ int writemsg_sock(rfd, msg, msglen)
+ 	SOCKET rfd;
+ 	u_char *msg;
+ 	int msglen;
+ {
+ 	u_char len[INT16SZ];
+ 	__putshort(msglen, len);
+ 
+ 	if (send(rfd, len, INT16SZ, 0) != INT16SZ ||
+ 		send(rfd, msg, msglen, 0) != msglen) {
+ 		dprintf(1,(ddt, "writemsg_sock failed: %d\n",errno));
+ 		return(-1);
+ 	}
+ 	return (0);
+ }
+ 
+ #endif
+ 
  /* rm_datum(dp, np, pdp)
   *	remove datum 'dp' from name 'np'.  pdp is previous data pointer.
   * return value:
***************
*** 848,853 ****
--- 891,897 ----
  }
  
  /* Signal abstraction. */
+ #ifndef WINNT
  
  void
  setsignal(catch, block, handler)
***************
*** 891,896 ****
--- 935,941 ----
  	setsignal(catch, block, handler);
  #endif
  }
+ #endif /* WINNT */
  
  void
  db_free(dp)
diff --context --recurs m:\bind495p1/named/db_load.c m:\bind/named/db_load.c
*** m:\bind495p1/named/db_load.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/db_load.c	Thu Dec 19 02:27:34 1996
***************
*** 85,105 ****
   */
  
  #include <sys/types.h>
! #include <sys/param.h>
! #include <sys/stat.h>
! #include <sys/socket.h>
  
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
  
! #include <ctype.h>
! #include <errno.h>
  #include <netdb.h>
  #include <resolv.h>
  #include <stdio.h>
! #include <syslog.h>
! #include <time.h>
  
  #include "named.h"
  
--- 85,112 ----
   */
  
  #include <sys/types.h>
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/stat.h>
! #include <sys/socket.h>
  
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
  
! #ifndef WINNT
! #include <syslog.h>
! #else
! #include <sys/types.h>
! #include <sys/stat.h>
! #endif
! #include <ctype.h>
  #include <netdb.h>
  #include <resolv.h>
  #include <stdio.h>
! #include <errno.h>
! #include <time.h>	/* for gmtime() */
  
  #include "named.h"
  
***************
*** 127,132 ****
--- 134,141 ----
  static int		getmlword_nesting = 0;
  
  int	getnum_error;
+ u_int inet_nsap_addr();
+ int inet_pton();
  
  /*
   * Parser token values
***************
*** 179,185 ****
--- 188,198 ----
  	FILE *fp;
  	int slineno, i, errs, didinclude;
  	register u_int32_t n;
+ #ifndef WINNT
  	struct stat sb;
+ #else
+ 	struct _stat sb;
+ #endif
  	struct in_addr ina;
  	int escape;
  	enum transport transport;
***************
*** 244,250 ****
--- 257,267 ----
  		dataflags = 0;
  	}
  	gettime(&tt);
+ #ifndef WINNT
  	if (fstat(fileno(fp), &sb) < 0) {
+ #else
+ 	if (_fstat(fileno(fp), &sb) < 0) {
+ #endif
  		syslog(LOG_WARNING, "%s: %m", filename);
  		sb.st_mtime = (int)tt.tv_sec;
  	}
***************
*** 313,319 ****
  			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);
--- 330,336 ----
  			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);
***************
*** 326,332 ****
  				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;
  				}
--- 343,349 ----
  				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;
  				}
***************
*** 351,357 ****
  			    dprintf(1, (ddt, "%s: Line %d: Unknown type: %s.\n",
  					    filename, lineno, buf));
  				errs++;
! 			    syslog(LOG_INFO, "%s: Line %d: Unknown type: %s.\n",
  					filename, lineno, buf);
  				break;
  			}
--- 368,374 ----
  			    dprintf(1, (ddt, "%s: Line %d: Unknown type: %s.\n",
  					    filename, lineno, buf));
  				errs++;
! 			    syslog(LOG_WARNING, "%s: Line %d: Unknown type: %s.\n",
  					filename, lineno, buf);
  				break;
  			}
***************
*** 360,366 ****
  			if (!ns_nameok(domain, class, transport, context,
  				       domain, inaddr_any)) {
  				errs++;
! 				syslog(LOG_NOTICE,
  				       "%s:%d: owner name error\n",
  				       filename, lineno);
  				break;
--- 377,383 ----
  			if (!ns_nameok(domain, class, transport, context,
  				       domain, inaddr_any)) {
  				errs++;
! 				syslog(LOG_WARNING,
  				       "%s:%d: owner name error\n",
  				       filename, lineno);
  				break;
***************
*** 441,447 ****
  				}
  				if (class != zp->z_class) {
  					errs++;
! 					syslog(LOG_INFO,
  					       "%s:%d: %s",
  					       filename, lineno,
  					       "SOA class not same as zone's");
--- 458,464 ----
  				}
  				if (class != zp->z_class) {
  					errs++;
! 					syslog(LOG_WARNING,
  					       "%s:%d: %s",
  					       filename, lineno,
  					       "SOA class not same as zone's");
***************
*** 471,477 ****
  				PUTLONG(n, cp);
  #ifdef DO_WARN_SERIAL
  				if (serial && SEQ_GT(serial, zp->z_serial)) {
! 					syslog(LOG_NOTICE,
  			"%s:%d: WARNING: new serial number < old (%lu < %lu)",
  						filename , lineno,
  						zp->z_serial, serial);
--- 488,494 ----
  				PUTLONG(n, cp);
  #ifdef DO_WARN_SERIAL
  				if (serial && SEQ_GT(serial, zp->z_serial)) {
! 					syslog(LOG_WARNING,
  			"%s:%d: WARNING: new serial number < old (%lu < %lu)",
  						filename , lineno,
  						zp->z_serial, serial);
***************
*** 531,563 ****
  				 * sanity: give enough time for the
  				 * zone to transfer (retry)
  				 */
! 				if (zp->z_expire < 
  					(zp->z_refresh+zp->z_retry)) {
! 				    syslog(LOG_NOTICE,
      "%s: WARNING SOA expire value is less then SOA refresh + retry (%lu < %lu + %lu)",
  				    filename, zp->z_expire, zp->z_refresh,
  				    zp->z_retry);
  				}
  				/* BIND specific */
  				if (zp->z_expire < maint_interval) {
! 				    syslog(LOG_NOTICE,
      "%s: WARNING SOA expire value is less then maintainance interval (%lu < %lu)",
  				    filename, zp->z_expire, maint_interval);
  				}
  				/* BIND Specific */
! 				if (zp->z_refresh < maint_interval) {
  				    syslog(LOG_WARNING,
      "%s: WARNING SOA refresh value is less then maintainance interval (%lu < %lu)",
  				    filename, zp->z_refresh, maint_interval);
  				}
  				/* BIND specific */
! 				if (zp->z_retry < maint_interval) {
  				    syslog(LOG_WARNING,
      "%s: WARNING SOA retry value is less then maintainance interval (%lu < %lu)",
  				    filename, zp->z_retry, maint_interval);
  				}
  				/* sanity */
! 				if (zp->z_expire < 
  					(zp->z_refresh  + 10 * zp->z_retry)) {
  				    syslog(LOG_WARNING,
      "%s: WARNING SOA expire value is less then refresh + 10 * retry (%lu < (%lu + 10 * %lu))",
--- 548,580 ----
  				 * sanity: give enough time for the
  				 * zone to transfer (retry)
  				 */
! 				if ((u_int32_t)zp->z_expire < 
  					(zp->z_refresh+zp->z_retry)) {
! 				    syslog(LOG_WARNING,
      "%s: WARNING SOA expire value is less then SOA refresh + retry (%lu < %lu + %lu)",
  				    filename, zp->z_expire, zp->z_refresh,
  				    zp->z_retry);
  				}
  				/* BIND specific */
  				if (zp->z_expire < maint_interval) {
! 				    syslog(LOG_WARNING,
      "%s: WARNING SOA expire value is less then maintainance interval (%lu < %lu)",
  				    filename, zp->z_expire, maint_interval);
  				}
  				/* BIND Specific */
! 				if (zp->z_refresh < (unsigned)maint_interval) {
  				    syslog(LOG_WARNING,
      "%s: WARNING SOA refresh value is less then maintainance interval (%lu < %lu)",
  				    filename, zp->z_refresh, maint_interval);
  				}
  				/* BIND specific */
!  				if ((u_int32_t)zp->z_retry < (unsigned)maint_interval) {
  				    syslog(LOG_WARNING,
      "%s: WARNING SOA retry value is less then maintainance interval (%lu < %lu)",
  				    filename, zp->z_retry, maint_interval);
  				}
  				/* sanity */
! 				if ((u_int32_t)zp->z_expire < 
  					(zp->z_refresh  + 10 * zp->z_retry)) {
  				    syslog(LOG_WARNING,
      "%s: WARNING SOA expire value is less then refresh + 10 * retry (%lu < (%lu + 10 * %lu))",
***************
*** 1208,1220 ****
  		}
  
  		/* Don't let bogus signers "sign" in the future.  */
! 		if (signtime > now) {
  			SETERR("signature time is in the future");
  			goto err;
  		}
  		
  		/* Ignore received SIG RR's that are already expired.  */
! 		if (exptime <= now) {
  			SETERR("expiration time is in the past");
  			goto err;
  		}
--- 1225,1237 ----
  		}
  
  		/* Don't let bogus signers "sign" in the future.  */
! 		if (signtime > (u_int32_t)now) {
  			SETERR("signature time is in the future");
  			goto err;
  		}
  		
  		/* Ignore received SIG RR's that are already expired.  */
! 		if (exptime <= (u_int32_t)now) {
  			SETERR("expiration time is in the past");
  			goto err;
  		}
***************
*** 1306,1316 ****
  						     &n)) {
  					if (rcode == CONV_OVERFLOW) {
  						errs++;
! 						syslog(LOG_INFO,
  				       "Load T_UNSPEC: input buffer overflow");
  					} else {
  						errs++;
! 						syslog(LOG_INFO,
  				     "Load T_UNSPEC: Data in bad atob format");
  					}
                                      }
--- 1323,1333 ----
  						     &n)) {
  					if (rcode == CONV_OVERFLOW) {
  						errs++;
! 						syslog(LOG_WARNING,
  				       "Load T_UNSPEC: input buffer overflow");
  					} else {
  						errs++;
! 						syslog(LOG_WARNING,
  				     "Load T_UNSPEC: Data in bad atob format");
  					}
                                      }
***************
*** 1334,1340 ****
  			if (zp->z_type != Z_CACHE &&
  			    !samedomain(domain, zp->z_origin))
  			{
! 				syslog(LOG_INFO,
  			    "%s:%d: data \"%s\" outside zone \"%s\" (ignored)",
  				       filename, lineno, domain, zp->z_origin);
  				continue;
--- 1351,1357 ----
  			if (zp->z_type != Z_CACHE &&
  			    !samedomain(domain, zp->z_origin))
  			{
! 				syslog(LOG_WARNING,
  			    "%s:%d: data \"%s\" outside zone \"%s\" (ignored)",
  				       filename, lineno, domain, zp->z_origin);
  				continue;
***************
*** 1367,1373 ****
  		}
   err:
  		errs++;
! 		syslog(LOG_NOTICE, "%s: line %d: database format error (%s)",
  			filename, empty_token ? (lineno - 1) : lineno, buf);
  		if (!empty_token)
  			endline(fp);
--- 1384,1390 ----
  		}
   err:
  		errs++;
! 		syslog(LOG_WARNING, "%s: line %d: database format error (%s)",
  			filename, empty_token ? (lineno - 1) : lineno, buf);
  		if (!empty_token)
  			endline(fp);
***************
*** 1447,1453 ****
  				if (!strcasecmp("origin", op))
  					return (ORIGIN);
  			}
! 			syslog(LOG_NOTICE,
  			       "%s: line %d: Unknown $ option: $%s\n", 
  			       src, lineno, op);
  			return (ERROR);
--- 1464,1470 ----
  				if (!strcasecmp("origin", op))
  					return (ORIGIN);
  			}
! 			syslog(LOG_WARNING,
  			       "%s: line %d: Unknown $ option: $%s\n", 
  			       src, lineno, op);
  			return (ERROR);
***************
*** 1746,1752 ****
  				break;
  			}
  			if (seendecimal || c != '.' || !allow_dots) {
! 				syslog(LOG_NOTICE, "%s:%d: expected a number",
  				       src, lineno);
  				getnum_error = 1;
  			} else {
--- 1763,1769 ----
  				break;
  			}
  			if (seendecimal || c != '.' || !allow_dots) {
! 				syslog(LOG_WARNING, "%s:%d: expected a number",
  				       src, lineno);
  				getnum_error = 1;
  			} else {
***************
*** 1775,1781 ****
  	if (getnum_error)
  		return (0);
  	if (m > 9999) {
! 		syslog(LOG_INFO, 
  		       "%s:%d: number after the decimal point exceeds 9999", 
  		       src, lineno);
  		getnum_error = 1;
--- 1792,1798 ----
  	if (getnum_error)
  		return (0);
  	if (m > 9999) {
! 		syslog(LOG_WARNING, 
  		       "%s:%d: number after the decimal point exceeds 9999", 
  		       src, lineno);
  		getnum_error = 1;
***************
*** 1811,1817 ****
  		}
  		return(c);
  	}
! 	syslog(LOG_INFO, "%s: line %d: unexpected EOF", src, lineno);
  	return (EOF);
  }
  
--- 1828,1834 ----
  		}
  		return(c);
  	}
! 	syslog(LOG_WARNING, "%s: line %d: unexpected EOF", src, lineno);
  	return (EOF);
  }
  
***************
*** 1867,1873 ****
  
  	makename(name, origin);
  	if (!ns_nameok(name, class, transport, context, owner, inaddr_any)) {
! 		syslog(LOG_INFO, "%s:%d: database naming error\n",
  		       filename, lineno);
  		ret = 0;
  	}
--- 1884,1890 ----
  
  	makename(name, origin);
  	if (!ns_nameok(name, class, transport, context, owner, inaddr_any)) {
! 		syslog(LOG_WARNING, "%s:%d: database naming error\n",
  		       filename, lineno);
  		ret = 0;
  	}
***************
*** 1905,1911 ****
  
  	k = protocolnumber(b);
  	if (k == -1)
! 		syslog(LOG_INFO, "%s: line %d: unknown protocol: %s.",
  		       src, lineno, b);
  	return(k);
  }
--- 1922,1928 ----
  
  	k = protocolnumber(b);
  	if (k == -1)
! 		syslog(LOG_WARNING, "%s: line %d: unknown protocol: %s.",
  		       src, lineno, b);
  	return(k);
  }
***************
*** 1947,1953 ****
  		}
  		k = servicenumber(b);
  		if (k == -1) {
! 			syslog(LOG_INFO,
  			       "%s: line %d: Unknown service '%s'",
  			       src, lineno, b);
  			continue;
--- 1964,1970 ----
  		}
  		k = servicenumber(b);
  		if (k == -1) {
! 			syslog(LOG_WARNING,
  			       "%s: line %d: Unknown service '%s'",
  			       src, lineno, b);
  			continue;
***************
*** 1958,1964 ****
  				maxl=k;
  		}
  		else {
! 			syslog(LOG_INFO,
  			       "%s: line %d: port no. (%d) too big",
  			       src, lineno, k);
  			dprintf(1, (ddt,
--- 1975,1981 ----
  				maxl=k;
  		}
  		else {
! 			syslog(LOG_WARNING,
  			       "%s: line %d: port no. (%d) too big",
  			       src, lineno, k);
  			dprintf(1, (ddt,
***************
*** 1967,1973 ****
  		}
  	}
  	if (bracket)
! 		syslog(LOG_INFO, "%s: line %d: missing close paren",
  		       src, lineno);
  	maxl = maxl/8+1;
  	bcopy(bm, data+n, maxl);
--- 1984,1990 ----
  		}
  	}
  	if (bracket)
! 		syslog(LOG_WARNING, "%s: line %d: missing close paren",
  		       src, lineno);
  	maxl = maxl/8+1;
  	bcopy(bm, data+n, maxl);
***************
*** 2007,2019 ****
  				panic(errno, "malloc(netinfo)");
  		}
  		if (!inet_aton(buf, &ntp->my_addr)) {
! 			syslog(LOG_INFO, "%s contains bogus element (%s)",
  			       print_tag, buf);
  			continue;
  		}
  		if (maskp) {
  			if (!inet_aton(maskp, &ina)) {
! 				syslog(LOG_INFO,
  				       "%s element %s has bad mask (%s)",
  				       print_tag, buf, maskp);
  				continue;
--- 2024,2036 ----
  				panic(errno, "malloc(netinfo)");
  		}
  		if (!inet_aton(buf, &ntp->my_addr)) {
! 			syslog(LOG_WARNING, "%s contains bogus element (%s)",
  			       print_tag, buf);
  			continue;
  		}
  		if (maskp) {
  			if (!inet_aton(maskp, &ina)) {
! 				syslog(LOG_WARNING,
  				       "%s element %s has bad mask (%s)",
  				       print_tag, buf, maskp);
  				continue;
***************
*** 2034,2040 ****
  
  		if (ntp->addr != ntp->my_addr.s_addr) {
  			ina.s_addr = ntp->addr;
! 			syslog(LOG_INFO,
  			       "%s element (%s) mask problem (%s)",
  				print_tag, buf, inet_ntoa(ina));
  		}
--- 2051,2057 ----
  
  		if (ntp->addr != ntp->my_addr.s_addr) {
  			ina.s_addr = ntp->addr;
! 			syslog(LOG_WARNING,
  			       "%s element (%s) mask problem (%s)",
  				print_tag, buf, inet_ntoa(ina));
  		}
***************
*** 2249,2255 ****
  		if (type == T_TXT || type == T_X25) {
  			while (i > MAXCHARSTRING
  			       && n + MAXCHARSTRING + 1 < MAXDATA) {
! 				data[n] = MAXCHARSTRING;
  				bcopy(b, data + n + 1, MAXCHARSTRING);
  				n += MAXCHARSTRING + 1;
  				b += MAXCHARSTRING;
--- 2266,2272 ----
  		if (type == T_TXT || type == T_X25) {
  			while (i > MAXCHARSTRING
  			       && n + MAXCHARSTRING + 1 < MAXDATA) {
! 				data[n] = (char)MAXCHARSTRING;
  				bcopy(b, data + n + 1, MAXCHARSTRING);
  				n += MAXCHARSTRING + 1;
  				b += MAXCHARSTRING;
***************
*** 2258,2270 ****
  		}
  #endif /* ALLOW_LONG_TXT_RDATA */
  		if (i > MAXCHARSTRING) {
! 			syslog(LOG_INFO,
  			       "%s: line %d: RDATA field %d too long",
  			       src, lineno, nfield);
  			return (0);
  		}
  		if (n + i + 1 > MAXDATA) {
! 			syslog(LOG_INFO,
  			       "%s: line %d: total RDATA too long",
  			       src, lineno);
  			return (0);
--- 2275,2287 ----
  		}
  #endif /* ALLOW_LONG_TXT_RDATA */
  		if (i > MAXCHARSTRING) {
! 			syslog(LOG_WARNING,
  			       "%s: line %d: RDATA field %d too long",
  			       src, lineno, nfield);
  			return (0);
  		}
  		if (n + i + 1 > MAXDATA) {
! 			syslog(LOG_WARNING,
  			       "%s: line %d: total RDATA too long",
  			       src, lineno);
  			return (0);
***************
*** 2276,2282 ****
  	} while (!done && getword(buf, MAXDATA, fp, 0));
  
  	if (nfield < minfields) {
! 		syslog(LOG_INFO,
  		       "%s: line %d: expected %d RDATA fields, only saw %d",
  		       src, lineno, minfields, nfield);
  		return (0);
--- 2293,2299 ----
  	} while (!done && getword(buf, MAXDATA, fp, 0));
  
  	if (nfield < minfields) {
! 		syslog(LOG_WARNING,
  		       "%s: line %d: expected %d RDATA fields, only saw %d",
  		       src, lineno, minfields, nfield);
  		return (0);
Only in m:\bind/named: db_load.sav
diff --context --recurs m:\bind495p1/named/db_lookup.c m:\bind/named/db_lookup.c
*** m:\bind495p1/named/db_lookup.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/db_lookup.c	Tue Oct 08 13:06:58 1996
***************
*** 62,77 ****
   * Table lookup routines.
   */
  
! #include <sys/types.h>
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <ctype.h>
! #include <stdio.h>
! #include <syslog.h>
  
! #include "named.h"
  
  /* 
   * Lookup 'name' and return a pointer to the namebuf;
--- 62,81 ----
   * Table lookup routines.
   */
  
! #ifndef WINNT
! #include <sys/types.h>
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/nameser.h>
! #include <ctype.h>
! #include <stdio.h>
! #ifndef WINNT
! #include <syslog.h>
! #endif
  
! #include "named.h"
  
  /* 
   * Lookup 'name' and return a pointer to the namebuf;
***************
*** 134,140 ****
  	     np != NULL;
  	     np = np->n_next) {
  		if (np->n_hashval == hval &&
! 		    ((size_t)NAMELEN(*np) == (cp - name)) && 
  		    (strncasecmp(name, NAME(*np), cp - name) == 0)) {
  			*fname = name;
  			return (np);
--- 138,144 ----
  	     np != NULL;
  	     np = np->n_next) {
  		if (np->n_hashval == hval &&
! 		    ((size_t)NAMELEN(*np) == (size_t)(cp - name)) && 
  		    (strncasecmp(name, NAME(*np), cp - name) == 0)) {
  			*fname = name;
  			return (np);
diff --context --recurs m:\bind495p1/named/db_reload.c m:\bind/named/db_reload.c
*** m:\bind495p1/named/db_reload.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/db_reload.c	Tue Oct 08 13:06:58 1996
***************
*** 59,70 ****
   */
  
  #include <sys/types.h>
! #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"
  
--- 59,74 ----
   */
  
  #include <sys/types.h>
! #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:\bind495p1/named/db_save.c m:\bind/named/db_save.c
*** m:\bind495p1/named/db_save.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/db_save.c	Tue Oct 08 13:06:58 1996
***************
*** 63,73 ****
   */
  
  #include <sys/types.h>
! #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>
  #include <assert.h>
--- 63,77 ----
   */
  
  #include <sys/types.h>
! #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>
  #include <assert.h>
diff --context --recurs m:\bind495p1/named/db_secure.c m:\bind/named/db_secure.c
*** m:\bind495p1/named/db_secure.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/db_secure.c	Tue Oct 08 13:06:58 1996
***************
*** 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:\bind495p1/named/db_update.c m:\bind/named/db_update.c
*** m:\bind495p1/named/db_update.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/db_update.c	Tue Oct 08 13:06:58 1996
***************
*** 59,73 ****
   */
  
  #include <stdio.h>
! #include <syslog.h>
  
! #include <sys/types.h>
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
! #include <resolv.h>
  
  #include "named.h"
  
--- 59,75 ----
   */
  
  #include <stdio.h>
! #ifndef WINNT
! #include <syslog.h>
  
! #include <sys/types.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>
  
  #include "named.h"
  
***************
*** 644,652 ****
  	if (dp->d_zone == 0 && !(dp->d_flags & DB_F_HINT)) {
  		if (dp->d_ttl <= tt.tv_sec)
  			return;
! 		else if (dp->d_ttl < tt.tv_sec+min_cache_ttl)
  			dp->d_ttl = tt.tv_sec+min_cache_ttl;
! 		else if (dp->d_ttl > tt.tv_sec+max_cache_ttl)
  			dp->d_ttl = tt.tv_sec+max_cache_ttl;
  	}
  	return;
--- 646,654 ----
  	if (dp->d_zone == 0 && !(dp->d_flags & DB_F_HINT)) {
  		if (dp->d_ttl <= tt.tv_sec)
  			return;
! 		else if ((u_int32_t)dp->d_ttl < tt.tv_sec+min_cache_ttl)
  			dp->d_ttl = tt.tv_sec+min_cache_ttl;
! 		else if ((u_int32_t)dp->d_ttl > tt.tv_sec+max_cache_ttl)
  			dp->d_ttl = tt.tv_sec+max_cache_ttl;
  	}
  	return;
Only in m:\bind/named: dmalloc.c
Only in m:\bind/named: dmalloc.h
Only in m:\bind/named: icon1.ico
Only in m:\bind/named: ipaddr.mak
Only in m:\bind/named: ipaddr.mdp
Only in m:\bind/named: ipaddr.ncb
Only in m:\bind/named: ipaddr.vcp
Only in m:\bind/named: ipaddr95.mak
Only in m:\bind/named: ipaddr95.mdp
Only in m:\bind/named: ipaddr95.ncb
Only in m:\bind/named: ipadr.c
Only in m:\bind/named: ipadr95.c
Only in m:\bind/named: leon.zip
diff --context --recurs m:\bind495p1/named/named-xfer.c m:\bind/named/named-xfer.c
*** m:\bind495p1/named/named-xfer.c	Thu Dec 19 02:24:24 1996
--- m:\bind/named/named-xfer.c	Thu Dec 19 02:27:37 1996
***************
*** 96,116 ****
  #endif /* not lint */
  
  #include <sys/types.h>
! #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>
--- 96,122 ----
  #endif /* not lint */
  
  #include <sys/types.h>
! #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>
***************
*** 118,126 ****
  #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>
--- 124,136 ----
  #include <errno.h>
  #include <resolv.h>
  #include <stdio.h>
+ #ifndef WINNT
  #include <syslog.h>
+ #else
+ #include <stdlib.h>
+ #endif
  #if !defined(SVR4) || !defined(sun)
! #include <math.h>
  #endif
  #include <ctype.h>
  #include <signal.h>
***************
*** 133,142 ****
--- 143,164 ----
  # 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 */
+ char * inet_nsap_ntoa();
+ const char * inet_ntop();
  
+ #ifndef WINNT
  static	char		ddtfilename[] = _PATH_TMPXFER,
  			*ddtfile = ddtfilename,
+ #else
+ static char	*ddtfile = pathtmpxfer,
+ #endif
  			*tmpname,
  			*domain;		/* domain being xfered */
  
***************
*** 154,160 ****
--- 176,184 ----
  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;
***************
*** 168,174 ****
  	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;
--- 192,201 ----
  	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;
***************
*** 179,184 ****
--- 206,223 ----
  	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
***************
*** 186,206 ****
--- 225,258 ----
  
  	(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
***************
*** 348,353 ****
--- 400,406 ----
  	 * 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);
***************
*** 368,373 ****
--- 421,427 ----
  	(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));
***************
*** 400,416 ****
  	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,
--- 454,482 ----
  	for (;  optind != argc;  optind++) {
  		tm = argv[optind];
  		if (!inet_aton(tm, &zp->z_addr[zp->z_addrcnt])) {
! /*#ifndef WINNT
! 		   hp = gethostbyname(tm);
! #else
! 		   hp = gethostbyname_nt(tm);
! #endif
! */
! /* lgk we may want the above code someday but for now use gethostbyname under nt
! (not the new version which will not resolve locahost or names in the host file ..
! this means ip6 will not work with xfer for now */
! 
!             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,
***************
*** 430,439 ****
--- 496,537 ----
  	_res.options &= ~(RES_DEFNAMES | RES_DNSRCH | RES_RECURSE);
  	result = getzone(zp, serial_no, port);
  	(void) my_fclose(dbfp);
+ 
+     /* lgk add code to close ddtfile here */
+ #ifdef DEBUG
+ 	if (debug)
+       (void) my_fclose(ddt);
+ #endif
+ 
  	switch (result) {
  
+ #ifdef WIN95
+ BOOL moveok;
+ #endif
+ 
  	case XFER_SUCCESS:			/* ok exit */
+ #ifndef WINNT
  		if (rename(tmpname, dbfile) == -1) {
+ #else /* lgk get rid of the ddt file if txfer ok in debug mode */
+ #ifdef DEBUG
+         if (debug)
+           (void) unlink(ddtfile);
+ #endif
+ 
+ /* lgk movefileex doesn't work on win95 so replace it */
+ #ifndef WIN95
+ 		/* C run time rename function under NT does not overwrite */
+ 		if(!MoveFileEx(tmpname, dbfile, MOVEFILE_REPLACE_EXISTING)) {
+ #else
+ 		moveok = CopyFile(tmpname, dbfile, FALSE);
+                 if (moveok)
+                   moveok = DeleteFile(tmpname);
+                 if (!moveok) {
+                     
+ #endif /* winnt or 95 versions */
+ 
+ #endif
+ 
  			perror("rename");
  			if (!quiet)
  			    syslog(LOG_ERR, "rename %s to %s: %m",
***************
*** 442,449 ****
--- 540,552 ----
  		}
  		exit(XFER_SUCCESS);
  
+ /* lgk add code to get rid of the ddt files if not in debug mode.. */
  	case XFER_UPTODATE:		/* the zone was already uptodate */
  		(void) unlink(tmpname);
+ #ifdef DEBUG
+         if (debug)
+           (void) unlink(ddtfile);
+ #endif
  		exit(XFER_UPTODATE);
  
  	default:
***************
*** 453,460 ****
  	case XFER_FAIL:
  #ifdef DEBUG
  		if (!debug)
! #endif
! 		    (void) unlink(tmpname);
  		exit(result);	/* error or timeout */
  	}
  	/*NOTREACHED*/
--- 556,563 ----
  	case XFER_FAIL:
  #ifdef DEBUG
  		if (!debug)
! #endif      
! 		(void) unlink(tmpname);
  		exit(result);	/* error or timeout */
  	}
  	/*NOTREACHED*/
***************
*** 493,499 ****
  
  #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 */
--- 596,603 ----
  
  #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 */
***************
*** 517,530 ****
  	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);
--- 621,643 ----
  	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);
***************
*** 540,545 ****
--- 653,660 ----
  		}
  	}
  #endif
+ 
+ #ifndef WINNT
  #ifdef POSIX_SIGNALS
  	bzero((char *)&sv, sizeof sv);
  	sv.sa_handler = (SIG_FN (*)()) read_alarm;
***************
*** 554,559 ****
--- 669,675 ----
  	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] == '.')
***************
*** 569,596 ****
  		error = 0;
  		if (buf == NULL) {
  			if ((buf = (u_char *)malloc(2 * PACKETSZ)) == NULL) {
! 				syslog(LOG_INFO, "malloc(%u) failed",
  				       2 * PACKETSZ);
  				error++;
  				break;
  			}
  			bufsize = 2 * PACKETSZ;
  		}
  		bzero((char *)&sin, sizeof(sin));
  		sin.sin_family = AF_INET;
  		sin.sin_port = (u_int16_t)port;
  		sin.sin_addr = zp->z_addr[cnt];
  		if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
! 			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)));
  		if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
  			if (!quiet)
! 				syslog(LOG_INFO,
  				       "connect(%s) for zone %s failed: %m",
  				       inet_ntoa(sin.sin_addr), zp->z_origin);
  			error++;
--- 685,713 ----
  		error = 0;
  		if (buf == NULL) {
  			if ((buf = (u_char *)malloc(2 * PACKETSZ)) == NULL) {
! 				syslog(LOG_WARNING, "malloc(%u) failed",
  				       2 * PACKETSZ);
  				error++;
  				break;
  			}
  			bufsize = 2 * PACKETSZ;
  		}
+ 
  		bzero((char *)&sin, sizeof(sin));
  		sin.sin_family = AF_INET;
  		sin.sin_port = (u_int16_t)port;
  		sin.sin_addr = zp->z_addr[cnt];
  		if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
! 			syslog(LOG_WARNING, "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)));
  		if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
  			if (!quiet)
! 				syslog(LOG_WARNING,
  				       "connect(%s) for zone %s failed: %m",
  				       inet_ntoa(sin.sin_addr), zp->z_origin);
  			error++;
***************
*** 604,625 ****
  				T_SOA, NULL, 0, NULL, buf, bufsize);
  		if (n < 0) {
  			if (!quiet)
! 				syslog(LOG_INFO,
  				       "zone %s: res_mkquery T_SOA failed",
  				       zp->z_origin);
  			(void) my_close(s);
  #ifdef POSIX_SIGNALS
  			(void) sigaction(SIGALRM, &osv, (struct sigaction *)0);
  #else
  			(void) sigvec(SIGALRM, &osv, (struct sigvec *)0);
  #endif
  			return (XFER_FAIL);
  		}
  		/*
  		 * Send length & message for SOA query
  		 */
  		if (writemsg(s, buf, n) < 0) {
! 			syslog(LOG_INFO, "writemsg: %m");
  			error++;
  			(void) my_close(s);
  			continue;	
--- 721,748 ----
  				T_SOA, NULL, 0, NULL, buf, bufsize);
  		if (n < 0) {
  			if (!quiet)
! 				syslog(LOG_WARNING,
  				       "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);
  		}
  		/*
  		 * Send length & message for SOA query
  		 */
+ #ifndef WINNT
  		if (writemsg(s, buf, n) < 0) {
! #else
! 		if (writemsg_sock(s, buf, n) < 0) {
! #endif
! 			syslog(LOG_WARNING, "writemsg: %m");
  			error++;
  			(void) my_close(s);
  			continue;	
***************
*** 638,644 ****
  		}
  		if (len > bufsize) {
  			if ((buf = (u_char *)realloc(buf, len)) == NULL) {
! 				syslog(LOG_INFO,
  		       "malloc(%u) failed for SOA from server [%s], zone %s\n",
  				       len,
  				       inet_ntoa(sin.sin_addr),
--- 761,767 ----
  		}
  		if (len > bufsize) {
  			if ((buf = (u_char *)realloc(buf, len)) == NULL) {
! 				syslog(LOG_WARNING,
  		       "malloc(%u) failed for SOA from server [%s], zone %s\n",
  				       len,
  				       inet_ntoa(sin.sin_addr),
***************
*** 660,668 ****
  		}
  #endif
  		hp = (HEADER *) buf;
! 		qdcount = ntohs(hp->qdcount);
! 		ancount = ntohs(hp->ancount);
! 		aucount = ntohs(hp->nscount);
  
  		/*
  		 * close socket if any of these apply:
--- 783,791 ----
  		}
  #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:
***************
*** 681,687 ****
  			}
  #endif
  #ifndef ultrix
! 			syslog(LOG_NOTICE,
         "[%s] %s for %s, SOA query got rcode %d, aa %d, ancount %d, aucount %d",
  			       inet_ntoa(sin.sin_addr),
  			       (hp->aa
--- 804,810 ----
  			}
  #endif
  #ifndef ultrix
! 			syslog(LOG_WARNING,
         "[%s] %s for %s, SOA query got rcode %d, aa %d, ancount %d, aucount %d",
  			       inet_ntoa(sin.sin_addr),
  			       (hp->aa
***************
*** 698,704 ****
  		if ((int)len < HFIXEDSZ + QFIXEDSZ) {
  			badsoa_msg = "too short";
   badsoa:
! 			syslog(LOG_INFO,
  			       "malformed SOA from [%s], zone %s: %s",
  			       inet_ntoa(sin.sin_addr), zp->z_origin,
  			       badsoa_msg);
--- 821,827 ----
  		if ((int)len < HFIXEDSZ + QFIXEDSZ) {
  			badsoa_msg = "too short";
   badsoa:
! 			syslog(LOG_WARNING,
  			       "malformed SOA from [%s], zone %s: %s",
  			       inet_ntoa(sin.sin_addr), zp->z_origin,
  			       badsoa_msg);
***************
*** 722,728 ****
  		GETSHORT(class, tmp);
  		if (class != curclass || type != T_SOA ||
  		    strcasecmp(zp->z_origin, name2) != 0) {
! 			syslog(LOG_INFO,
  			"wrong query in resp from [%s], zone %s: [%s %s %s]\n",
  			       inet_ntoa(sin.sin_addr), zp->z_origin,
  			       name2, p_class(class), p_type(type));
--- 845,851 ----
  		GETSHORT(class, tmp);
  		if (class != curclass || type != T_SOA ||
  		    strcasecmp(zp->z_origin, name2) != 0) {
! 			syslog(LOG_WARNING,
  			"wrong query in resp from [%s], zone %s: [%s %s %s]\n",
  			       inet_ntoa(sin.sin_addr), zp->z_origin,
  			       name2, p_class(class), p_type(type));
***************
*** 765,771 ****
  		} while (1);
  
  		if (strcasecmp(zp->z_origin, name2) != 0) {
! 			syslog(LOG_INFO,
  		       "wrong answer in resp from [%s], zone %s: [%s %s %s]\n",
  			       inet_ntoa(sin.sin_addr), zp->z_origin,
  			       name2, p_class(class), p_type(type));
--- 888,894 ----
  		} while (1);
  
  		if (strcasecmp(zp->z_origin, name2) != 0) {
! 			syslog(LOG_WARNING,
  		       "wrong answer in resp from [%s], zone %s: [%s %s %s]\n",
  			       inet_ntoa(sin.sin_addr), zp->z_origin,
  			       name2, p_class(class), p_type(type));
***************
*** 826,843 ****
  						if (!quiet) {
  #ifdef STUBS
  						    if (zp->z_type == Z_STUB)
! 							syslog(LOG_INFO,
  							       (type == T_SOA)
  					? "zone %s: res_mkquery T_SOA failed"
  					: "zone %s: res_mkquery T_NS failed",
  							       zp->z_origin);
  						    else
  #endif
! 							syslog(LOG_INFO,
  					  "zone %s: res_mkquery T_AXFR failed",
  							       zp->z_origin);
  						}
  						(void) my_close(s);
  #ifdef POSIX_SIGNALS
  						sigaction(SIGALRM, &osv,
  							(struct sigaction *)0);
--- 949,967 ----
  						if (!quiet) {
  #ifdef STUBS
  						    if (zp->z_type == Z_STUB)
! 							syslog(LOG_WARNING,
  							       (type == T_SOA)
  					? "zone %s: res_mkquery T_SOA failed"
  					: "zone %s: res_mkquery T_NS failed",
  							       zp->z_origin);
  						    else
  #endif
! 							syslog(LOG_WARNING,
  					  "zone %s: res_mkquery T_AXFR failed",
  							       zp->z_origin);
  						}
  						(void) my_close(s);
+ #ifndef WINNT
  #ifdef POSIX_SIGNALS
  						sigaction(SIGALRM, &osv,
  							(struct sigaction *)0);
***************
*** 845,857 ****
  						sigvec(SIGALRM, &osv,
  						       (struct sigvec *)0);
  #endif
  						return (XFER_FAIL);
  					}
  					/*
  					 * Send length & msg for zone transfer
  					 */
  					if (writemsg(s, buf, n) < 0) {
! 						syslog(LOG_INFO,
  						       "writemsg: %m");
  						error++;
  						(void) my_close(s);
--- 969,987 ----
  						sigvec(SIGALRM, &osv,
  						       (struct sigvec *)0);
  #endif
+ #endif /* WINNT */
  						return (XFER_FAIL);
  					}
  					/*
  					 * Send length & msg for zone transfer
  					 */
+ 					 
+ #ifndef WINNT
  					if (writemsg(s, buf, n) < 0) {
! #else
! 					if (writemsg_sock(s, buf, n) < 0) {
! #endif
! 						syslog(LOG_WARNING,
  						       "writemsg: %m");
  						error++;
  						(void) my_close(s);
***************
*** 886,892 ****
  				if (len < HFIXEDSZ) {
  		badrec:
  					error++;
! 					syslog(LOG_INFO,
  				       "record too short from [%s], zone %s\n",
  					       inet_ntoa(sin.sin_addr),
  					       zp->z_origin);
--- 1016,1022 ----
  				if (len < HFIXEDSZ) {
  		badrec:
  					error++;
! 					syslog(LOG_WARNING,
  				       "record too short from [%s], zone %s\n",
  					       inet_ntoa(sin.sin_addr),
  					       zp->z_origin);
***************
*** 905,912 ****
  				tmp = cp + n;
  #ifdef STUBS
  			if (zp->z_type == Z_STUB) {
! 				ancount = ntohs(hp->ancount);
! 				for (n = cnt = 0 ; cnt < ancount ; cnt++) {
  					n = print_output(buf, bufsize, cp);
  					if (n < 0)
  						break;
--- 1035,1042 ----
  				tmp = cp + n;
  #ifdef STUBS
  			if (zp->z_type == Z_STUB) {
! 				ancount = ntohs( (u_short) hp->ancount);
! 				for (n = cnt = 0 ; cnt < (u_int)ancount ; cnt++) {
  					n = print_output(buf, bufsize, cp);
  					if (n < 0)
  						break;
***************
*** 914,920 ****
  				}
  				if (n >= 0 && hp->nscount) {
  					/* we should not get here */
! 					ancount = ntohs(hp->nscount);
  					for (cnt = 0 ; cnt < ancount ; cnt++) {
  					    n = print_output(buf, bufsize, cp);
  					    if (n < 0)
--- 1044,1050 ----
  				}
  				if (n >= 0 && hp->nscount) {
  					/* we should not get here */
! 					ancount = ntohs((u_short)hp->nscount);
  					for (cnt = 0 ; cnt < ancount ; cnt++) {
  					    n = print_output(buf, bufsize, cp);
  					    if (n < 0)
***************
*** 922,941 ****
  					    cp += n;
  					}
  				}
! 				ancount = ntohs(hp->arcount);
  				for (cnt = 0 ; n >= 0 && cnt < ancount ; cnt++) {
  					n = print_output(buf, bufsize, cp);
  					cp += n;
  				}
  				if (n < 0) {
! 					syslog(LOG_INFO,
  			"print_output: unparseable answer (%d), zone %s",
  						hp->rcode, zp->z_origin);
  					error++;
  					break;
  				}
  				if (cp != eom) {
! 					syslog(LOG_INFO,
  				"print_output: short answer (%d, %d), zone %s",
  					       cp - buf, n, zp->z_origin);
  					error++;
--- 1052,1071 ----
  					    cp += n;
  					}
  				}
! 				ancount = ntohs((u_short)hp->arcount);
  				for (cnt = 0 ; n >= 0 && cnt < ancount ; cnt++) {
  					n = print_output(buf, bufsize, cp);
  					cp += n;
  				}
  				if (n < 0) {
! 					syslog(LOG_WARNING,
  			"print_output: unparseable answer (%d), zone %s",
  						hp->rcode, zp->z_origin);
  					error++;
  					break;
  				}
  				if (cp != eom) {
! 					syslog(LOG_WARNING,
  				"print_output: short answer (%d, %d), zone %s",
  					       cp - buf, n, zp->z_origin);
  					error++;
***************
*** 944,965 ****
  		
  			} else {
  #endif /*STUBS*/
! 				ancount = ntohs(hp->ancount);
! 				for (n = cnt = 0; cnt < ancount; cnt++) {
  					n = print_output(buf, bufsize, cp);
  					if (n < 0)
  						break;
  					cp += n;
  				}
  				if (n < 0) {
! 					syslog(LOG_INFO,
  			"print_output: unparseable answer (%d), zone %s",
  						hp->rcode, zp->z_origin);
  					error++;
  					break;
  				}
  				if (cp != eom) {
! 					syslog(LOG_INFO,
  				"print_output: short answer (%d, %d), zone %s",
  					       cp - buf, eom - buf,
  					       zp->z_origin);
--- 1074,1095 ----
  		
  			} else {
  #endif /*STUBS*/
! 				ancount = ntohs( (u_short) hp->ancount);
! 				for (n = cnt = 0; cnt < (u_int)ancount; cnt++) {
  					n = print_output(buf, bufsize, cp);
  					if (n < 0)
  						break;
  					cp += n;
  				}
  				if (n < 0) {
! 					syslog(LOG_WARNING,
  			"print_output: unparseable answer (%d), zone %s",
  						hp->rcode, zp->z_origin);
  					error++;
  					break;
  				}
  				if (cp != eom) {
! 					syslog(LOG_WARNING,
  				"print_output: short answer (%d, %d), zone %s",
  					       cp - buf, eom - buf,
  					       zp->z_origin);
***************
*** 979,985 ****
  						goto badsoa;
  					}
  					if (strcasecmp(name, zp->z_origin)!=0){
! 						syslog(LOG_INFO,
  			"wrong zone name in AXFR (wanted \"%s\", got \"%s\")",
  						       zp->z_origin, name);
  						badsoa_msg = "wrong soa name";
--- 1109,1115 ----
  						goto badsoa;
  					}
  					if (strcasecmp(name, zp->z_origin)!=0){
! 						syslog(LOG_WARNING,
  			"wrong zone name in AXFR (wanted \"%s\", got \"%s\")",
  						       zp->z_origin, name);
  						badsoa_msg = "wrong soa name";
***************
*** 1018,1024 ****
  				}
  				if (strcasecmp((char *)name,
  					       (char *)name2) != 0) {
! 					syslog(LOG_INFO,
  				"got extra SOA for \"%s\" in zone \"%s\"",
  					       name2, name);
  					continue;
--- 1148,1154 ----
  				}
  				if (strcasecmp((char *)name,
  					       (char *)name2) != 0) {
! 					syslog(LOG_WARNING,
  				"got extra SOA for \"%s\" in zone \"%s\"",
  					       name2, name);
  					continue;
***************
*** 1044,1052 ****
  					 * and seek to beginning to restart.
  					 */
  					fflush(dbfp);
  					if (ftruncate(fileno(dbfp), 0) != 0) {
  						if (!quiet)
! 						    syslog(LOG_INFO,
  							  "ftruncate %s: %m\n",
  							   tmpname);
  						return (XFER_FAIL);
--- 1174,1187 ----
  					 * 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_ERR,
  							  "ftruncate %s: %m\n",
  							   tmpname);
  						return (XFER_FAIL);
***************
*** 1064,1075 ****
--- 1199,1212 ----
  		}
  		(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"));
***************
*** 1082,1099 ****
  	    } else {
  		(void) my_close(s);
  		if (!quiet)
! 		    syslog(LOG_NOTICE,
  		      "serial from [%s], zone %s: %u lower than current: %u\n",
  			   inet_ntoa(sin.sin_addr), zp->z_origin,
  			   zp_start.z_serial, serial_no);
  		return (XFER_FAIL);
  	    }
  	}
  #ifdef POSIX_SIGNALS
  	(void) sigaction(SIGALRM, &osv, (struct sigaction *)0);
  #else
  	(void) sigvec(SIGALRM, &osv, (struct sigvec *)0);
  #endif
  	if (!error)
  		return (XFER_TIMEOUT);
  	return (XFER_FAIL);
--- 1219,1238 ----
  	    } else {
  		(void) my_close(s);
  		if (!quiet)
! 		    syslog(LOG_WARNING,
  		      "serial from [%s], zone %s: %u lower than current: %u\n",
  			   inet_ntoa(sin.sin_addr), zp->z_origin,
  			   zp_start.z_serial, serial_no);
  		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);
***************
*** 1115,1144 ****
  	register char *buf;
  	register int len;
  	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)
  			if (++retries < 42)	/* doug adams */
  				continue;
  #endif
! 			syslog(LOG_INFO, "premature EOF, fetching \"%s\"",
  			       domain);
  			return (-1);
  		}
--- 1254,1293 ----
  	register char *buf;
  	register int len;
  	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)
  			if (++retries < 42)	/* doug adams */
  				continue;
  #endif
! 			syslog(LOG_WARNING, "premature EOF, fetching \"%s\"",
  			       domain);
  			return (-1);
  		}
***************
*** 1163,1175 ****
--- 1312,1381 ----
  			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_ERR, "recv (in xfer) (len=%d): %m", len);
+ 					return (-1);
+ 				   }
+ 		       
+ 		       }
+ 		    else if (n == 0)
+ 			 {
+ 			   syslog(LOG_WARNING,"recv (in xfer) (connection closed by remote) : %m");
+ 			   return(-1);
+ 			 }
+ 		   }
+ 	        else /* error case on select */ 
+ 				{
+ 				  if (ret == SOCKET_ERROR)
+ 				  {
+ 					  syslog(LOG_ERR,"select (in xfer) error: %m");
+ 					  return(-1);
+ 				  }
+ 
+ 		 	      if (ret == 0) 
+ 				    { 
+ 				     WSASetLastError(WSAETIMEDOUT);
+ 			             syslog(LOG_WARNING, "select (in xfer timed out) 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);
  }
  
***************
*** 1441,1447 ****
  		/* finally, we copy over the variable-length signature.
  		   Its size is the total data length, minus what we copied. */
  		n = dlen - (18 + n);
! 		if (n > (sizeof data) - (cp1 - (u_char *)data))
  			return (-1);  /* out of room! */
  		bcopy(cp, cp1, n);
  		cp += n;
--- 1647,1653 ----
  		/* finally, we copy over the variable-length signature.
  		   Its size is the total data length, minus what we copied. */
  		n = dlen - (18 + n);
! 		if ((unsigned)n > (sizeof data) - (cp1 - (u_char *)data))
  			return (-1);  /* out of room! */
  		bcopy(cp, cp1, n);
  		cp += n;
***************
*** 1453,1459 ****
  		break;
  
  	default:
! 		syslog(LOG_INFO, "\"%s %s %s\" - unknown type (%d)",
  		       dname, p_class(class), p_type(type), type);
  		hp->rcode = NOTIMP;
  		return (-1);
--- 1659,1665 ----
  		break;
  
  	default:
! 		syslog(LOG_WARNING, "\"%s %s %s\" - unknown type (%d)",
  		       dname, p_class(class), p_type(type), type);
  		hp->rcode = NOTIMP;
  		return (-1);
Only in m:\bind/named: named.aps
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.rc
Only in m:\bind/named: named.vcp
Only in m:\bind/named: named95.mak
Only in m:\bind/named: named95.mdp
Only in m:\bind/named: named95.ncb
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
Only in m:\bind/named: ns_REsp.sav
diff --context --recurs m:\bind495p1/named/ns_defs.h m:\bind/named/ns_defs.h
*** m:\bind495p1/named/ns_defs.h	Thu Dec 19 02:24:23 1996
--- m:\bind/named/ns_defs.h	Tue Oct 08 13:07:02 1996
***************
*** 119,135 ****
  	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 */
--- 119,143 ----
  	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 */
***************
*** 175,182 ****
--- 183,195 ----
  #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 {
***************
*** 251,257 ****
--- 264,274 ----
  #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 */
***************
*** 266,272 ****
--- 283,293 ----
  #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:\bind495p1/named/ns_forw.c m:\bind/named/ns_forw.c
*** m:\bind495p1/named/ns_forw.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/ns_forw.c	Thu Dec 19 02:27:41 1996
***************
*** 59,77 ****
   */
  
  #include <sys/types.h>
! #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.
--- 59,88 ----
   */
  
  #include <sys/types.h>
! #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.
***************
*** 380,386 ****
  	register struct namebuf *np;
  	register struct databuf *dp, *nsdp;
  	register struct qserv *qs;
! 	register int n;
  	register u_int i;
  	struct hashbuf *tmphtp;
  	char *dname;
--- 391,397 ----
  	register struct namebuf *np;
  	register struct databuf *dp, *nsdp;
  	register struct qserv *qs;
! 	register unsigned int n;
  	register u_int i;
  	struct hashbuf *tmphtp;
  	char *dname;
***************
*** 650,657 ****
--- 661,672 ----
  		qp->q_addr[i].ns->d_rcnt++;
  	}
  	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);
  }
***************
*** 1060,1066 ****
  	struct qinfo *qp;
  {
  	struct qinfo *np;
- 	struct databuf *dp;
  
  	dprintf(3, (ddt, "Qfree(x%lx)\n", (u_long)qp));
  	if (qp->q_next)
--- 1075,1080 ----
diff --context --recurs m:\bind495p1/named/ns_func.h m:\bind/named/ns_func.h
*** m:\bind495p1/named/ns_func.h	Thu Dec 19 02:24:23 1996
--- m:\bind/named/ns_func.h	Mon Nov 11 16:17:30 1996
***************
*** 103,112 ****
  			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));
--- 103,116 ----
  			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:\bind495p1/named/ns_glob.h m:\bind/named/ns_glob.h
*** m:\bind495p1/named/ns_glob.h	Thu Dec 19 02:24:23 1996
--- m:\bind/named/ns_glob.h	Mon Nov 11 16:17:58 1996
***************
*** 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:\bind495p1/named/ns_init.c m:\bind/named/ns_init.c
*** m:\bind495p1/named/ns_init.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/ns_init.c	Thu Dec 19 02:27:46 1996
***************
*** 59,74 ****
   */
  
  #include <sys/types.h>
! #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 "named.h"
--- 59,78 ----
   */
  
  #include <sys/types.h>
! #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 "named.h"
***************
*** 105,114 ****
  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);
  }
  
--- 109,118 ----
  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);
  }
  
***************
*** 242,250 ****
--- 246,267 ----
  #endif
  	struct stat f_time;
  	static int tmpnum = 0;		/* unique number for tmp zone files */
+ #ifdef WINNT
+ 	extern char *pathtmpdir;
+ #endif
  	int slineno;			/* Saved global line number. */
  	int i;
+ 	
+ #if defined(WINNT) && defined(REGISTRY_PATHS)
+ 	/* software.com specific 
+ 	   PIW:  change to the temp dir that we got from the registry */
+ 	if (chdir(pathtmpdir) != TRUE)
+ 	{
+ 		syslog(LOG_CRIT, "Can't chdir to %s: %m\n",buf);
+ 		exit(1);
+ 	}
  
+ #endif
  	if ((fp = fopen(filename, "r")) == NULL) {
  		syslog(LOG_ERR, "%s: %m", filename);
  		if (includefile)
***************
*** 266,274 ****
  		}
  		if (strcasecmp(buf, "directory") == 0) {
  			(void) getword(buf, sizeof(buf), fp, 0);
  			if (chdir(buf) < 0) {
! 				syslog(LOG_CRIT, "directory %s: %m\n",
! 					buf);
  				exit(1);
  			}
  			continue;
--- 283,305 ----
  		}
  		if (strcasecmp(buf, "directory") == 0) {
  			(void) getword(buf, sizeof(buf), fp, 0);
+ #ifndef WINNT
  			if (chdir(buf) < 0) {
! #else
! #ifdef REGISTRY_PATHS
!             /* software.com specific 
! 		       PIW Software.com: ignore the directory, we got it from
! 			   the registry already in ns_main.c, and it is stored
! 			   in the global 'pathtmpdir'. */
! 
! 			syslog(LOG_INFO,"Ignoring directory entry in startup\n");
! 
! 			if (chdir(pathtmpdir) != TRUE) {
! #else
! 			if (chdir(buf) != TRUE) {
! #endif /* registry paths */
! #endif /* winnt */
! 				syslog(LOG_CRIT, "directory %s: %m\n",buf);
  				exit(1);
  			}
  			continue;
***************
*** 560,566 ****
--- 591,601 ----
  				 * 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;
***************
*** 991,997 ****
  	const char *owner;
  {
  	enum severity severity = checkname_severity[transport];
! 	int ok;
  
  	if (severity == ignore)
  		return (1);
--- 1026,1032 ----
  	const char *owner;
  {
  	enum severity severity = checkname_severity[transport];
! 	int ok = 0;
  
  	if (severity == ignore)
  		return (1);
***************
*** 1034,1040 ****
  				sprintf(o, " (owner \"%s\")", t);
  		}
  #ifndef ultrix
! 		syslog((transport == response_trans) ? LOG_INFO : LOG_NOTICE,
  		       "%s name \"%s\"%s %s (%s) is invalid - %s",
  		       context_strings[context],
  		       name, o != NULL ? o : "[malloc failed]", p_class(class),
--- 1069,1075 ----
  				sprintf(o, " (owner \"%s\")", t);
  		}
  #ifndef ultrix
! 		syslog((transport == response_trans) ? LOG_WARNING : LOG_WARNING,
  		       "%s name \"%s\"%s %s (%s) is invalid - %s",
  		       context_strings[context],
  		       name, o != NULL ? o : "[malloc failed]", p_class(class),
diff --context --recurs m:\bind495p1/named/ns_main.c m:\bind/named/ns_main.c
*** m:\bind495p1/named/ns_main.c	Thu Dec 19 02:24:24 1996
--- m:\bind/named/ns_main.c	Thu Dec 19 02:27:50 1996
***************
*** 6,21 ****
  /*
   * ++Copyright++ 1986, 1989, 1990
   * -
!  * Copyright (c) 1986, 1989, 1990
!  *    The Regents of the University of California.  All rights reserved.
   * 
!  * Redistribution and use in source and binary forms, with or without
!  * modification, are permitted provided that the following conditions
!  * are met:
!  * 1. Redistributions of source code must retain the above copyright
!  *    notice, this list of conditions and the following disclaimer.
!  * 2. Redistributions in binary form must reproduce the above copyright
!  *    notice, this list of conditions and the following disclaimer in the
   *    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:
--- 6,21 ----
  /*
   * ++Copyright++ 1986, 1989, 1990
   * -
!  * Copyright (c) 1986,  1989, 1990
!  *    The Regents of the University of California.  All rights reserved.
   * 
!  * Redistribution and use in source and binary forms, with or without
!  * modification, are permitted provided that the following conditions
!  * are met:
!  * 1. Redistributions of source code must retain the above copyright
!  *    notice, this list of conditions and the following disclaimer.
!  * 2. Redistributions in binary form must reproduce the above copyright
!  *    notice, this list of conditions and the following disclaimer in the
   *    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:
***************
*** 71,78 ****
--- 71,80 ----
   */
  
  #include <sys/types.h>
+ #ifndef WINNT
  #include <sys/param.h>
  #include <sys/file.h>
+ #endif
  #include <sys/stat.h>
  #if !defined(SYSV) && defined(XXX)
  #include <sys/wait.h>
***************
*** 82,90 ****
--- 84,94 ----
  				 * 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>
***************
*** 93,104 ****
--- 97,114 ----
  # 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>
***************
*** 113,118 ****
--- 123,133 ----
  
  #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 */
***************
*** 125,130 ****
--- 140,185 ----
  static	char			**Argv = NULL;
  static	char			*LastArg = NULL;	/* end of argv */
  
+ #ifdef WINNT
+ 
+ #ifdef WIN95
+ void ndc_thread(void *);
+ #endif
+ 
+     	/* handles for various threads, process, and objects */
+ 	HANDLE hReadWriteEvent = NULL, hServDoneEvent = NULL, hWorkerThread = NULL, hNDCThread = NULL;
+ 	/* variables used to inform the Service Control Manager of our current state */
+         volatile int doterminate = 0;
+ 	SERVICE_STATUS ServiceStatus;
+ 	SERVICE_STATUS_HANDLE   hServiceStatus;
+ 	OVERLAPPED overlap; 
+ 	int was_stopped = 0;
+ 	char *pathboot, *pathxfer, *pathdebug,
+ 	 	 *pathdumpfile, *pathpidfile, *pathstats,
+ 	 	 *pathxfertrace, *pathxferddt, *pathtmpdir, *pathsysdir;
+     CRITICAL_SECTION protected_zp;
+     CRITICAL_SECTION maint_section;
+     /* lgk 10/96 new critical section to protect outgoing zone transfers */
+     CRITICAL_SECTION doxfr_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
+ 	
+ #ifdef REGISTRY_PATHS
+ 	/* software.com specific
+ 	   PIW Software.com change to get path from registry */
+ 	static int GetRegistryPath(int max_len, char *directory);
+ #endif /* registry paths */
+ #endif /* WINNT */
+ 
+ 
  static	struct qstream		*sqadd __P((void));
  static	void			sq_query __P((struct qstream *)),
  				opensocket __P((struct qdatagram *)),
***************
*** 134,139 ****
--- 189,195 ----
  				setdebug __P((int));
  static	int			sq_here __P((struct qstream *));
  
+ #ifndef WINNT
  static	SIG_FN			onintr __P(()),
  				maint_alarm __P(()),
  				setdumpflg __P(()),
***************
*** 148,153 ****
--- 204,210 ----
  #endif /* SIGSYS */
  				setchkptflg __P(()),
  				setstatsflg __P(());
+ #endif /* WINNT */
  
  static void
  usage()
***************
*** 163,175 ****
  	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];
--- 220,235 ----
  	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];
***************
*** 177,183 ****
  	int old_sigmask;
  #endif
  	fd_set tmpmask;
! 	struct timeval t, *tp;
  	struct qstream *candidate = QSTREAM_NULL;
  	char **argp;
  #ifdef PID_FIX
--- 237,246 ----
  	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
***************
*** 193,198 ****
--- 256,290 ----
  	struct rlimit rl;
  #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);
+    InitializeCriticalSection(&doxfr_section);
+    /* initialize all pathnames */
+    expand_paths();
+ 
+        /* lgk add startup code here */
+        /* Set the Event-ID message-file name. */
+ 
+       /* lgk modified 10.96 to use getmodulefilename instead of getcurrent directory
+          so it works correctly when running as a service */
+            
+        GetModuleFileName(NULL,szMsgPath,sizeof(szMsgPath));
+        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 ****
  #ifdef LOG_NOWAIT
  	n |= LOG_NOWAIT;
  #endif
  #ifdef LOG_DAEMON
  	openlog("named", LOG_PID|LOG_CONS|LOG_NDELAY|n, LOGFAC);
- #else
- 	openlog("named", LOG_PID);
- #endif
  
  #ifdef	RLIMIT_NOFILE
  	rl.rlim_cur = rl.rlim_max = FD_SETSIZE;
--- 397,405 ----
  #ifdef LOG_NOWAIT
  	n |= LOG_NOWAIT;
  #endif
+ #ifndef WINNT
  #ifdef LOG_DAEMON
  	openlog("named", LOG_PID|LOG_CONS|LOG_NDELAY|n, LOGFAC);
  
  #ifdef	RLIMIT_NOFILE
  	rl.rlim_cur = rl.rlim_max = FD_SETSIZE;
***************
*** 318,323 ****
--- 408,420 ----
  #endif
  	/* check that udp checksums are on */
  	ns_udp();
+ #else
+         /* note under windows Nt udp checksums are always turned on
+         so this is a no-op */
+ 	openlog("named", LOG_PID);
+ #endif
+ 
+ #endif /* WINNT */
  
  #ifdef WANT_PIDFILE
  	/* tuck my process id away */
***************
*** 351,358 ****
  	** Open stream port.
  	*/
  	for (n = 0; ; n++) {
! 		int fd;
  		if ((vs = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
  			syslog(LOG_ERR, "socket(SOCK_STREAM): %m");
  			exit(1);
  		}	
--- 448,462 ----
  	** Open stream port.
  	*/
  	for (n = 0; ; n++) {
! #ifdef F_DUPFD
!  		int fd;
! #endif
! 
! #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);
  		}	
***************
*** 405,410 ****
--- 509,515 ----
  		exit(1);
  	}
  
+ #ifndef WINNT
    	/*
  	 * named would be terminated if one of these is sent and no handler.
  	 */
***************
*** 418,423 ****
--- 523,529 ----
  #if defined(SIGWINCH) && defined(QRYLOG)
  	setsignal(SIGWINCH, -1, setQrylogFlg);
  #endif
+ #endif /* WINNT */
  
  	/*
  	 * Get list of local addresses and set up datagram sockets.
***************
*** 443,448 ****
--- 549,555 ----
  	time(&boottime);
  	resettime = boottime;
  
+ #ifndef WINNT
  	setsignal(SIGALRM, SIGCHLD, maint_alarm);
  	setsignal(SIGCHLD, SIGALRM, reapchild);
  	setsignal(SIGPIPE, -1, (SIG_FN (*)())SIG_IGN);
***************
*** 460,465 ****
--- 567,573 ----
          /* 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;
***************
*** 469,474 ****
--- 577,583 ----
  	 * we've done any slow initialization
  	 * and are ready to answer queries.
  	 */
+ #ifndef WINNT
  #ifdef USE_SETSID
  	if (
  #ifdef DEBUG
***************
*** 547,552 ****
--- 656,865 ----
  #endif /* HAVE_DAEMON */
  	}
  #endif /* USE_SETSID */
+ 
+ #else /* WINNT */
+ 
+ #ifndef WIN95
+ 
+ #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 */
+ 
+ #else /* is win95 version */
+ 	   service_main(argc, argv);
+ #endif /* win95 version */
+ } /* 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;
+ {
+ 
+ #ifndef WIN95
+      DWORD dwWait;
+ #endif;
+ 
+ 
+ 
+ #ifdef NOWAIT
+ 	loopback.sin_family = AF_INET;
+ 	loopback.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ 	loopback.sin_port = local_ns_port;
+ #endif
+ 
+ 	/* lgk if win95 don't do this stuff */
+ #ifndef WIN95
+ 
+ #ifdef DEBUG
+ 	if(!debug) {
+ #endif /* DEBUG */
+ 
+     	/* 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 */
+ 
+ #else /* it is win95 so... no services */
+ 
+ 
+             /* still start up ndc thread even in win95 mode */
+             /* lgk new code now start up the ndc_named socket thread */
+             if (!(hNDCThread = (HANDLE)_beginthread(
+                     ndc_thread,
+                     0,       /* stack size			*/
+                     NULL))){    /* argument to thread	*/
+ 			syslog(LOG_ERR, "_beginthread: %m");
+ 			if (hServDoneEvent != NULL)
+ 			  CloseHandle(hServDoneEvent);
+ 			return;
+ 		}
+ 
+ worker_thread(NULL);
+ 
+ #endif /* win95 */
+ 
+ } /* 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;
+      /* would like to wait on the terminate even here. .but cannot find a way to declare
+         it volatile and it does not work .. so use the stupid doterminate flag */
+ 
+ 	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");
***************
*** 580,585 ****
--- 893,909 ----
  		  	exit(0);
                  }
  #endif /* XSTATS */
+ 
+ #ifdef WIN95 /* lgk need exit code for win95 since we don't stop the service to exit */
+     	/* test the terminate event and terminate if necessary */
+ if (doterminate)
+           {
+  	    CloseHandle(hServDoneEvent);
+  	    syslog(LOG_INFO, "named95: service stopped");
+ 	    ExitProcess(0);
+ 	 }
+ #endif
+ 			  
  		if (needreload) {
  			needreload = 0;
  			db_reload();
***************
*** 588,599 ****
--- 912,934 ----
  			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();
***************
*** 635,641 ****
--- 970,980 ----
  #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);
  		}
***************
*** 664,669 ****
--- 1003,1016 ----
  			    }
  			    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,707 ****
--- 1044,1067 ----
  			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;
+ 
+ #ifdef WINNT
+ EnterCriticalSection(&doxfr_section);
+ #endif
+ 
  				for (sp = streamq; sp; sp = nextsp) {
  					nextsp = sp->s_next;
  					if (sp->s_refcnt)
***************
*** 712,728 ****
  						sqrm(sp);
  					else if (lasttime > maxctime) {
  						candidate = sp;
- 						maxctime = lasttime;
  					}
  				}
  				if (candidate)
! 					sqrm(candidate);
  				continue;
  			}
  			if (rfd < 0) {
  				syslog(LOG_INFO, "accept: %m");
  				continue;
  			}
  			if ((n = fcntl(rfd, F_GETFL, 0)) < 0) {
  				syslog(LOG_INFO, "fcntl(rfd, F_GETFL): %m");
  				(void) my_close(rfd);
--- 1072,1096 ----
  						sqrm(sp);
  					else if (lasttime > maxctime) {
  						candidate = sp;
  					}
  				}
+ #ifdef WINNT
+ LeaveCriticalSection(&doxfr_section);
+ #endif
+ 
  				if (candidate)
! 				   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 ****
--- 1101,1113 ----
  				(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,
***************
*** 778,783 ****
--- 1153,1159 ----
  			}
  			if ((sp = sqadd()) == QSTREAM_NULL) {
  				(void) my_close(rfd);
+  	                        dprintf(1, (ddt, "sqadd: failed closing socket %d \n",rfd));
  				continue;
  			}
  			sp->s_rfd = rfd;	/* stream file descriptor */
***************
*** 798,803 ****
--- 1174,1184 ----
  		if (streamq)
  			dprintf(3, (ddt, "streamq = 0x%lx\n",
  				    (u_long)streamq));
+ 
+ #ifdef WINNT
+ EnterCriticalSection(&doxfr_section);
+ #endif
+ 
  		for (sp = streamq;  sp != QSTREAM_NULL;  sp = nextsp) {
  			nextsp = sp->s_next;
  			if (!FD_ISSET(sp->s_rfd, &tmpmask))
***************
*** 807,826 ****
  				    (u_long)sp, sp->s_rfd, sp->s_size,
  				    sp->s_time, (u_long)sp->s_next));
  			dprintf(5, (ddt,
! 				    "\tbufsize %d buf x%lx bufp x%lx\n",
  				    sp->s_bufsize,
! 				    (u_long)sp->s_buf, (u_long)sp->s_bufp));
  			if (sp->s_size < 0) {
  				size = INT16SZ
  				    - (sp->s_bufp - (u_char *)&sp->s_tempsize);
  			        while (size > 0 &&
  			           (n = read(sp->s_rfd, sp->s_bufp, size)) > 0
  				       ) {
  					sp->s_bufp += n;
  					size -= n;
  			        }
  				if ((n < 0) && (errno == PORT_WOULDBLK))
  					continue;
  				if (n <= 0) {
  					sqrm(sp);
  					continue;
--- 1188,1213 ----
  				    (u_long)sp, sp->s_rfd, sp->s_size,
  				    sp->s_time, (u_long)sp->s_next));
  			dprintf(5, (ddt,
! 				    "\tbufsize %d buf x%lx bufp x%lx refcnt %d\n",
  				    sp->s_bufsize,
! 				    (u_long)sp->s_buf, (u_long)sp->s_bufp, (u_long)sp->s_refcnt));
  			if (sp->s_size < 0) {
  				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;
  			        }
  				if ((n < 0) && (errno == PORT_WOULDBLK))
  					continue;
+ 
  				if (n <= 0) {
  					sqrm(sp);
  					continue;
***************
*** 858,867 ****
--- 1245,1261 ----
  			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;
***************
*** 883,890 ****
  				hp->nscount = 0;
  				hp->arcount = 0;
  				hp->rcode = SERVFAIL;
! 				(void) writemsg(sp->s_rfd, sp->s_buf,
! 						HFIXEDSZ);
  			    }
  			    continue;
  			}
--- 1277,1294 ----
  				hp->nscount = 0;
  				hp->arcount = 0;
  				hp->rcode = SERVFAIL;
! 
! #ifndef WINNT
! 				writemsg(sp->s_rfd, sp->s_buf,HFIXEDSZ);
! #else
! 				/* lgk new code here so that if the write failed.. we close the socket.. */
! 				if (writemsg_sock(sp->s_rfd, sp->s_buf,HFIXEDSZ) < 0)
! 				  {
!                         dprintf(1, (ddt, "writemsg: failed so closing bad socket!\n"));
!                         sqrm(sp);
!                       }
! #endif
! 
  			    }
  			    continue;
  			}
***************
*** 905,917 ****
  				hp->nscount = 0;
  				hp->arcount = 0;
  				hp->rcode = SERVFAIL;
  				(void) writemsg(sp->s_rfd, sp->s_buf,
  						HFIXEDSZ);
  			    }
  			    continue;
  			}
  			if ((n == -1) && (errno == PORT_WOULDBLK))
! 				continue;
  			if (n <= 0) {
  				sqrm(sp);
  				continue;
--- 1309,1360 ----
  				hp->nscount = 0;
  				hp->arcount = 0;
  				hp->rcode = SERVFAIL;
+ #ifndef WINNT
  				(void) writemsg(sp->s_rfd, sp->s_buf,
  						HFIXEDSZ);
+ #else
+ 
+ 				/* lgk new code here so that if the write failed.. we close the socket.. */
+ 				if (writemsg_sock(sp->s_rfd, sp->s_buf,HFIXEDSZ) < 0)
+ 				  {
+                         dprintf(1, (ddt, "writemsg: failed so closing bad socket!\n"));
+                         sqrm(sp);
+                       }
+ #endif
  			    }
+                    /* lgk the following continue is incorrect it stops the code from checking for
+                       a socket error i.e. -1 if message is too short that is ok but if we
+                       have a socket error we need to check this first and close the socket if so..
+                       otherwise we get a runaway socket and an endless loop when you disconnect
+                       a connection at just the right time and no data is on the socket.. and
+                        s_bufp = s_buf so the above if is true */
+ 
+ #ifndef WINNT
+ 			if ((n == -1) && (errno == PORT_WOULDBLK))
+ #else
+ 			if ((n == SOCKET_ERROR) && (errno == PORT_WOULDBLK))
+ #endif
+ 			   continue;
+ 
+ 
+ 			if (n <= 0) {
+ 				sqrm(sp);
+ 				continue;
+ 			}
+ 
+ 
  			    continue;
  			}
+ 
+ 
+ #ifndef WINNT
  			if ((n == -1) && (errno == PORT_WOULDBLK))
! #else
! 			if ((n == SOCKET_ERROR) && (errno == PORT_WOULDBLK))
! #endif
! 			   continue;
! 
! 
  			if (n <= 0) {
  				sqrm(sp);
  				continue;
***************
*** 936,941 ****
--- 1379,1390 ----
  				continue;
  			}
  		}
+ 
+ #ifdef WINNT
+ LeaveCriticalSection(&doxfr_section);
+ #endif
+ 
+ 
  	}
  	/* NOTREACHED */
  }
***************
*** 955,964 ****
--- 1404,1426 ----
  
  	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
+ #ifndef WIN95
+         if (get_winnt_interfaces(&ifc) < 0)
+ #else
+         if (get_win95_interfaces(&ifc) < 0)
+ #endif
+          {
+ 	   syslog(LOG_ERR, "get interface configuration: %m - exiting");
+ 	   exit(1);
+ 	}
+ #endif
+ 
  	ntp = NULL;
  #if defined(AF_LINK) && \
  	!defined(RISCOS_BSD) && !defined(M_UNIX) && \
***************
*** 971,979 ****
  	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) {
--- 1433,1446 ----
  	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) {
***************
*** 984,998 ****
  		 * 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.
--- 1451,1466 ----
  		 * 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.
***************
*** 1049,1054 ****
--- 1517,1523 ----
  		}
  		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");
***************
*** 1060,1069 ****
--- 1529,1546 ----
  		/* 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
***************
*** 1079,1084 ****
--- 1556,1563 ----
  					    (u_long)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");
***************
*** 1090,1095 ****
--- 1569,1578 ----
  		} 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.
***************
*** 1151,1156 ****
--- 1634,1646 ----
  			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;
  }
  
***************
*** 1193,1204 ****
--- 1683,1701 ----
  {
  	int m, n;
  	int on = 1;
+ #ifdef F_DUPFD
  	int fd;
+ #endif
  
  	/*
  	 * Open datagram sockets bound to interface address.
  	 */
+ #ifndef WINNT
  	if ((dqp->dq_dfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ #else
+ 	if ((dqp->dq_dfd = socket(AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET) {
+ #endif
+ 	 
  		syslog(LOG_ERR, "socket(SOCK_DGRAM): %m - exiting");
  		exit(1);
  	}	
***************
*** 1229,1234 ****
--- 1726,1732 ----
  				  (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. */
***************
*** 1236,1241 ****
--- 1734,1744 ----
  		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
***************
*** 1255,1260 ****
--- 1758,1764 ----
  	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
***************
*** 1318,1326 ****
          needToDoadump = 1;
  	errno = save_errno;
  }
  
  /*
! ** Turn on or off debuging by open or closeing the debug file
  */
  
  static void
--- 1822,1831 ----
          needToDoadump = 1;
  	errno = save_errno;
  }
+ #endif /* WINNT */
  
  /*
! ** Turn on or off debuging by open or closing the debug file
  */
  
  static void
***************
*** 1333,1339 ****
--- 1838,1846 ----
  #ifdef DEBUG
  
  	if (code) {
+ #ifndef WINNT
  		int n;
+ #endif
  
  		ddt = freopen(debugfile, "w+", stderr);
  		if ( ddt == NULL) {
***************
*** 1346,1357 ****
--- 1853,1866 ----
  #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;
***************
*** 1359,1364 ****
--- 1868,1874 ----
  #endif
  }
  
+ #ifndef WINNT
  /*
  ** Catch a special signal and set debug level.
  **
***************
*** 1463,1468 ****
--- 1973,1980 ----
  }
  #endif /* SIGSYS */
  
+ #endif /* WINNT */
+ 
  /*
  ** Routines for managing stream queue
  */
***************
*** 1472,1485 ****
--- 1984,2010 ----
  {
  	register struct qstream *sqp;
  
+ #ifdef WINNT
+ EnterCriticalSection(&doxfr_section);
+ #endif
+ 
+ 	
  	if (!(sqp = (struct qstream *)calloc(1, sizeof(struct qstream)))) {
  		syslog(LOG_ERR, "sqadd: calloc: %m");
+ #ifdef WINNT
+                 EnterCriticalSection(&doxfr_section);
+ #endif
  		return (QSTREAM_NULL);
  	}
  	dprintf(3, (ddt, "sqadd(x%lx)\n", (u_long)sqp));
  
  	sqp->s_next = streamq;
  	streamq = sqp;
+ 
+ #ifdef WINNT
+ LeaveCriticalSection(&doxfr_section);
+ #endif
+ 
  	return (sqp);
  }
  
***************
*** 1498,1503 ****
--- 2023,2032 ----
  	dprintf(2, (ddt, "sqrm(%#lx, %d) rfcnt=%d\n",
  		    (u_long)qp, qp->s_rfd, qp->s_refcnt));
  
+ #ifdef WINNT
+ EnterCriticalSection(&doxfr_section);
+ #endif
+ 
  	if (qp->s_bufsize != 0)
  		free(qp->s_buf);
  	FD_CLR(qp->s_rfd, &mask);
***************
*** 1514,1519 ****
--- 2043,2053 ----
  		}
  	}
  	free((char *)qp);
+ 
+ #ifdef WINNT
+ LeaveCriticalSection(&doxfr_section);
+ #endif
+ 
  }
  
  /* void
***************
*** 1529,1535 ****
  	register struct qstream *allbut;
  {
  	register struct qstream *sp, *spnext;
! 
  	for (sp = streamq; sp != NULL; sp = spnext) {
  		spnext = sp->s_next;
  		if (sp != allbut)
--- 2063,2069 ----
  	register struct qstream *allbut;
  {
  	register struct qstream *sp, *spnext;
! 	
  	for (sp = streamq; sp != NULL; sp = spnext) {
  		spnext = sp->s_next;
  		if (sp != allbut)
***************
*** 1565,1571 ****
  			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)
--- 2099,2105 ----
  			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)
***************
*** 1687,1689 ****
--- 2221,3259 ----
  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, (const char *)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 */
+ 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);
+ 	pathsysdir = (char *)malloc(MAX_PATH);
+ 
+ #ifdef REGISTRY_PATHS
+     /* software.com specific */
+ 	if (GetRegistryPath(MAX_PATH, pathtmpdir))
+ 	  {
+ 	    syslog(LOG_ERR, "GetRegistryPath() failed: %m");
+ 	  }
+ #else
+ 	if (!GetTempPath(MAX_PATH, pathtmpdir))
+ 		syslog(LOG_ERR, "GetTempPath() failed: %m");
+ 
+ 	if (!GetSystemDirectory((LPSTR)pathsysdir,MAX_PATH))
+ 		syslog(LOG_ERR, "GetSystemDirectory() failed: %m");
+     strcat(pathsysdir,"\\");
+ 
+ #endif
+ 
+ #ifdef REGISTRY_PATHS
+ 	}
+       	else
+ 		syslog(LOG_INFO,"Get registry info okay: %s",pathtmpdir);
+ 	/* software.com specific
+ 	    PIW:  use the directory we found from the registry for ALL files
+ 	          relating to the DNS:  */
+ 	pathboot = (char *)malloc(MAX_PATH);
+ 	strcpy(pathboot,pathtmpdir);
+ 	strcat(pathboot,"NAMED.BOOT");
+     bootfile = pathboot;
+ 
+ 	pathpidfile = (char *)malloc(MAX_PATH);
+ 	strcpy(pathpidfile,pathtmpdir);
+ 	strcat(pathpidfile,"NAMED.PID");
+ 
+ 	pathxfer = (char *)malloc(MAX_PATH);
+ 	strcpy(pathxfer,pathtmpdir);
+ 	strcat(pathxfer,"NAMED.XFER");
+ 
+ #else /* don't use registry paths */
+ 
+ 	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");
+ 	      }
+ #endif 
+ 
+ 	pathdebug = (char *)malloc(MAX_PATH);
+ 	strcpy(pathdebug, pathsysdir);
+ 	debugfile = strcat(pathdebug, _PATH_DEBUG);
+ 	
+ 	pathdumpfile = (char *)malloc(MAX_PATH);
+ 	strcpy(pathdumpfile, pathsysdir);
+ 	dumpfile = strcat(pathdumpfile, _PATH_DUMPFILE);
+ 	 
+ 	pathstats = (char *)malloc(MAX_PATH);
+ 	strcpy(pathstats, pathsysdir);
+ 	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);
+ }
+ 
+ /* software.com specific */
+ #ifdef REGISTRY_PATHS
+ 
+ /*----------------------------------------------------------------------------------------
+ /
+ /	Function:		GetRegistryPath
+ /
+ /	Description:	given a char buffer to fill (and a max length allowed) look in the
+ /					NT registry for the directory entry under Software.Com/DNS.
+ /
+ /	Returns:		0 means it worked, -1 if it didn't
+ /
+ /	History:		Paul W.		11/24/95	Created
+ /
+ /---------------------------------------------------------------------------------------*/
+ static int GetRegistryPath(int max_len, char *directory)
+ {
+ 	HKEY hk;
+ 	int bSuccess;
+ 	DWORD dw_maxlen = max_len;
+ 
+     /* get key for our application */
+     bSuccess = RegOpenKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\ISC\\DomainNameService",&hk);
+     if (bSuccess != ERROR_SUCCESS)
+       {
+     	syslog(LOG_ERR, "Cannot open the default directory registry key: %m");
+     	return -1;
+       }
+ 
+     bSuccess = RegQueryValueEx(hk,
+          "Directory",
+           NULL,
+           NULL,
+           (LPBYTE) directory,
+           &dw_maxlen);
+     if (bSuccess != ERROR_SUCCESS)
+       {
+ 	    syslog(LOG_ERR, "Error in RegQueryValueEx fetching service name parameter: %m");
+ 	    RegCloseKey(hk);
+ 	    return -1;
+       }
+ 
+ 	if (directory[dw_maxlen-1] != '\\')	/* if the directory does NOT have a trailing backslash */
+  	  {  
+ 		directory[dw_maxlen] = '\\';	/* put one on, and terminate a little longer */
+ 		directory[dw_maxlen+1] = '\0';	/* terminate at given length plus slash-space */
+ 	  }
+ 	else
+ 		directory[dw_maxlen] = '\0';	/* terminate at given length, already has slash */
+ 		
+     RegCloseKey(hk);
+ 	return 0;
+ }
+ #endif
+ 
+ #ifndef WIN95
+ 
+ /* ------------------------------------------------------------------------------------------------------------------ */
+ /* written by l. kahn */
+ /* modified with suggestions from Kevin Dunlap so we only pick out netcards bound to tcpip */
+   int get_winnt_interfaces(ifc)
+ 
+     struct ifconf *ifc;
+     
+ 
+   {
+         char *ifc_buffer = ifc->ifc_buf;
+ 
+     	   struct ifreq *ifr;
+         HKEY hk, hksub;                      /* registry key handle */
+         BOOL bSuccess;
+         char newkey[200];
+ 
+         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 bindservicenames[1000];
+         DWORD sizeofbindnames = 1000;
+ 
+        char oneIpAddress[16];
+        char oneSubNetMask[16];
+        int count = 0;
+        char *onenetcard;
+ 
+     /* now get all the netcard values which are bound to tcpip */ 
+ 
+     strcpy(newkey,"SYSTEM\\Currentcontrolset\\Services\\");
+     strcat(newkey,"tcpip\\linkage");
+        
+     bSuccess = RegOpenKey(HKEY_LOCAL_MACHINE,newkey,&hk);
+     if(bSuccess != ERROR_SUCCESS)
+     {
+         syslog(LOG_ERR, "failed to Open TCP/IP Linkage Registry key: %m");
+         dprintf(1, (ddt, "Cannot get TCP/IP Linkage from registery.\n"));
+         return -1;
+     }
+ 
+     /* now get the bind value */
+         sizeofbindnames = 1000;
+         bSuccess = RegQueryValueEx(hk,     /* subkey handle         */
+         "Bind",                            /* value name            */
+         NULL,                              /* must be zero          */
+         NULL,                              /* value type          not required  */
+         (LPBYTE) &bindservicenames,        /* address of value data */
+         &sizeofbindnames);                 /* length of value data  */
+         if(bSuccess != ERROR_SUCCESS)
+         {
+             syslog(LOG_ERR, "Error in RegQueryValueEx fetching Bind Service names parameter: %m");
+             RegCloseKey(hk);
+             return -1;
+         }
+ 
+ 
+     /* now loop through and get all the values which are bound to tcpip */ 
+     /* we can also close the key here as we have the values now */
+     RegCloseKey(hk);
+     onenetcard = bindservicenames;
+     while(1)
+     {
+ 
+        onenetcard = onenetcard + 8;
+        if  ((onenetcard < (bindservicenames + sizeofbindnames)) &&
+            (sscanf(onenetcard,"%s",servicename) != EOF))
+          {
+             onenetcard+= strlen(servicename) + 1;
+          }
+         else { /* no more */
+                break;
+              }
+ 
+         /* 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));
+           }
+         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 */
+ 
+            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);
+                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);
+                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 */
+         } /* it is/not a temporary ndiswan name */ 
+     } /* end of loop  */
+ 
+     /* now reset the length */
+     ifc->ifc_len = count * (sizeof(ifr->ifr_name) + sizeof(ifr->ifr_addr) + sizeof(ifr->ifr_mask));
+     return 0;
+ }
+ 
+ 
+ #else // win95 version
+ 
+   /* By Leon McCalla to get tcpip bound to netcards on 95*/
+   /* modified by l. kahn */
+   /* changed 12/96 by l. kahn to support the multi-ip address scheme
+      on win95 which uses commas instead of spaces like NT */
+      
+   int get_win95_interfaces(ifc)
+   struct ifconf *ifc;
+ 
+   {
+ 	char *ifc_buffer = ifc->ifc_buf;
+ 	struct ifreq *ifr;
+ 
+      HKEY hk, dk, rk, ck;                      /* registry key handle */
+      BOOL bSuccess;
+      char realkey[200];
+      DWORD sizeofrealkey = 200;
+      char netkey[50];
+      DWORD sizeofnetkey = 50;
+      char newkey[50];
+      DWORD sizeofnewkey = 50;
+      char driverkey[50];
+      DWORD sizeofdriverkey = 50;
+      char nettype[50];		
+      DWORD sizeofnettype = 50;
+      char subkey[50];
+      DWORD sizeofsubkey = 50;
+      char checkkey[50];
+      DWORD sizeofcheck = 50;
+      int Done = 0;
+      int Done2 = 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;
+      const int sep = (int)',';
+      char *token =  NULL;
+ 
+      
+      char oneIpAddress[16];
+      char oneSubNetMask[16];
+      int count = 0;
+      int ipcount = 0;
+ 
+     /* now get all the netcard (ie 0001) ..._  values which are bound to tcpip */ 
+ 
+     strcpy(newkey,"ENUM\\Network\\MSTCP");
+     bSuccess = RegOpenKey(HKEY_LOCAL_MACHINE,newkey,&hk);
+     if(bSuccess != ERROR_SUCCESS)
+     {
+         syslog(LOG_ERR, "failed to Open MSTCP network Registry key: %m");
+         dprintf(1, (ddt, "Cannot get MSTCP network linkage from registery.\n"));
+         return -1;
+     }
+ 
+      while (!Done)
+        {
+ 	    sizeofnetkey = 50;
+ 	     bSuccess = RegEnumKey(hk, (DWORD)count, (LPTSTR)netkey, sizeofnetkey);
+ 	     if(bSuccess == ERROR_NO_MORE_ITEMS)
+ 		  {
+ 			Done = TRUE;
+                         break;
+                   }
+ 	
+ 	     if ((bSuccess != ERROR_SUCCESS) && (bSuccess != ERROR_NO_MORE_ITEMS))
+ 		   {
+                         syslog(LOG_ERR, "Error in RegEnumKey fetching network card keys from registry: %m");
+ 			RegCloseKey(hk);
+ 			return -1;
+ 		   }
+ 
+         ++count;
+      
+ 	 /* now the devicedesc here does not specify the dial up so we must get the
+             last part off the key and try the key enum//root//net//netkey   */
+ 
+          strcpy(checkkey,"ENUM\\Root\\Net\\");
+          strcat(checkkey,netkey);
+ 
+        /* not sure if this works but on my eisa machine these were not there
+           so if they are not there assume they are not temporary .. ie enum\eisa
+           for eisa cards instead of enum\\root but I imagine all ras interfaces are like this
+           above.. so if not there it is not a ras temporary interface */
+ 
+ 	 // get the check value
+ 	 /*check for Dial up adapter*/
+  	 bSuccess = RegOpenKey(HKEY_LOCAL_MACHINE,checkkey,&ck);
+         if(bSuccess != ERROR_SUCCESS)
+ 	  {
+            strcpy(nettype,"dummy");
+ 	  }
+ 
+       else
+       {
+       // now get the value
+ 	 sizeofnettype = 50;
+ 	 bSuccess = RegQueryValueEx(ck,     /* subkey handle         */
+ 	         "DeviceDesc",              /* value name            */
+ 		    NULL,                   /* must be zero          */
+ 		    NULL,                   /* value type          not required  */
+               (LPBYTE) &nettype,            /* address of value data */
+               &sizeofnettype);              /* length of value data  */
+ 
+       RegCloseKey(ck); // not needed anymore either way
+       if(bSuccess != ERROR_SUCCESS)
+           {
+            strcpy(nettype,"dummy");
+           }
+       } // not there
+ 
+       // go on
+ 	 if (strncmp(strupr(nettype),"DIAL-UP ADAPTER",15) == 0)
+           {
+            /* skip it */
+   	   dprintf(1, (ddt, "Skippping temporary interface [%s]\n",nettype));
+           }
+ 
+          else { // is not temporary interface
+             // ok get drivername
+ 
+ 	// get the Driver value
+ 	/*now we have the values so we need to get the driver value for the key */
+ 	strcpy(driverkey,"ENUM\\Network\\MSTCP\\");
+ 	strcat(driverkey,netkey);
+ 
+ 
+ 	bSuccess = RegOpenKey(HKEY_LOCAL_MACHINE,driverkey,&dk);
+ 	if(bSuccess != ERROR_SUCCESS)
+ 	  {
+            char temp[300];
+            sprintf(temp,"Can not open key [%s] from the registry \n",driverkey);
+            syslog(LOG_ERR, temp);
+            RegCloseKey(hk);
+            return -1;
+ 	   }
+ 
+             // ok get drivername
+ 		sizeofsubkey = 50;
+ 		bSuccess = RegQueryValueEx(dk,     /* subkey handle         */
+ 	  	      "Driver",                    /* value name            */
+ 		      NULL,                        /* must be zero          */
+ 		      NULL,                        /* value type          not required  */
+ 		      (LPBYTE) &subkey,            /* address of value data */
+ 		      &sizeofsubkey);              /* length of value data  */
+ 
+           if(bSuccess != ERROR_SUCCESS)
+ 		  {
+ 		    syslog(LOG_ERR,"Error in RegQueryValueEx fetching Driver value: %m \n");
+ 		    RegCloseKey(dk);
+ 		    RegCloseKey(hk);
+ 		    return -1;
+ 		  }
+ 
+           RegCloseKey(dk); //driver key not needed any longer
+ 
+           // now open the real key
+ 	     strcpy(realkey,"SYSTEM\\CurrentControlSet\\Services\\Class\\");
+ 	     strcat(realkey,subkey);
+ 	     
+ 	     bSuccess = RegOpenKey(HKEY_LOCAL_MACHINE,realkey,&rk);
+ 	     if(bSuccess != ERROR_SUCCESS)
+ 		 {
+ 		   char temp[300];
+ 		   sprintf(temp,"Error opening real network key [%s].\n",realkey);
+                    syslog(LOG_ERR, temp);
+ 		   RegCloseKey(hk);
+                    return -1;
+ 		}
+         
+            sizeofipaddresses = 10000;
+            bSuccess = RegQueryValueEx(rk,     /* 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 \n");
+                RegCloseKey(rk);
+                RegCloseKey(hk);
+                return -1;
+               }
+               
+            /* ok now get the subnetmask */
+            sizeofsubnetmasks = 10000;
+            bSuccess = RegQueryValueEx(rk,     /* subkey handle         */
+               "IPMask",                       /* 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 IPMask parameter! %m\n");
+                RegCloseKey(rk);
+                RegCloseKey(hk);
+                return -1;
+               }
+ 
+           RegCloseKey(rk);
+           /* 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;
+         Done2 = 0;
+         token = NULL;
+         
+        /* lgk change here win95 mutli addresses are separated by commas not
+           spaces like NT, so replace the commas with spaces so the old
+           loop works  */
+ 
+        token = strchr(ipptr,sep);
+        while (token != NULL)
+         {
+          *token = ' ';
+          token = strchr(ipptr,sep);
+         }
+ 
+         /* now handle subnet block */
+        token = strchr(subptr,sep);
+        while (token != NULL)
+         {
+          *token = ' ';
+          token = strchr(subptr,sep);
+         }
+         
+         while (!Done2)
+         {
+          ifr = (struct ifreq *)ifc_buffer;
+          if (sscanf(ipptr,"%s",oneIpAddress) != EOF)
+            ipptr+= strlen(oneIpAddress) + 1; /* add one for terminator \0 */
+          else Done2 = 1;
+          
+          if (sscanf(subptr,"%s",oneSubNetMask) != EOF)
+            subptr += strlen(oneSubNetMask) + 1;
+          else Done2 = 1;
+ 
+          /* now add to interface structure */
+          if (!Done2)                  
+           {
+            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);
+ 
+            // subkey is the closest thing to a service name under win95
+            if (strlen(subkey) > 15)
+              strncpy(ifr->ifr_name,subkey,15);
+            else strcpy(ifr->ifr_name,subkey);
+ 
+            /* now increment pointer */
+ 	       ifc_buffer += sizeof (ifr->ifr_name) + sizeof(ifr->ifr_addr) + sizeof(ifr->ifr_mask);
+            ++ipcount;
+            if (((char *)ipptr == '\0') || ((char *)subptr == '\0')) 
+              Done2 = 1;
+              
+           } // if
+ 	    } // not done2 loop
+         } // not temporary interface
+        } // loop (while) through more things bound to MSTCP
+ 
+     RegCloseKey(hk); // done with top while so close key
+ 
+     /* now reset the length */
+     ifc->ifc_len = ipcount * (sizeof(ifr->ifr_name) + sizeof(ifr->ifr_addr) + sizeof(ifr->ifr_mask));
+ 
+     return 0;
+   }
+ 
+ // ndc_thread ... wait for ndc commands.. works both under nt and win95
+ // there will be a ndc95 command
+ // l. kahn.. this is needed for win95 port because there are no services and
+ // we cannot use sevice api's
+ // becuase the damn mailslots sendning more than once due to  how many network
+ // transports you have bound we must use and id.. to make sure we are not doing the
+ // same command twice..
+ // also named pipes do not work.. since win95 does not support them.. so switched
+ // to mail slots... also security api's don't work on win95
+ // cant use this under nt even though originally designed also to work under nt.. 
+ // actually it works under nt but the security doesn't so anyone can shut down your server etc.
+ // this is acceptable for win95 where there is no security but not for nt..
+ //when monitoring the code on win95 noticed 100% cpu utilization. Apparently the
+ //readfile api on a mailslot even with timeout set to infinite does a
+ //busy wait... to get around this did a loop with getmailslotinfo and my
+ //own sleep statement.... this worked but then decided to try waitforsingleobject
+ //(the correct call to use) even though the documentation specifically fails
+ //to mention this working on mailslot handles.. appparently it works so
+ //using this method..
+ // back to using the getmailslotinfo  with sleep solution.. not the prettiest..
+ 
+ 
+ 
+ VOID
+ ndc_thread(VOID *notUsed)
+ {
+     char                 inbuf[120];
+     char                 outbuf[60];
+     BOOL                 ret;
+     BOOL                 bad_code;
+     DWORD                bytesRead;
+     DWORD                bytesWritten;
+     char                 command[40];
+     char                 mbname[20];
+     char                 outname[80];
+     char                 machname[40];
+     int                  len;
+     SOCKET               s;
+     HANDLE               slotHandle;
+     HANDLE               outslot;
+     DWORD                id, lastid;
+     DWORD                wcount;
+     BOOL                 onefound;
+     BOOL                 fResult;
+     
+ // only do the event here if win95 as done elsewhere in nt
+ #ifdef WIN95
+     
+ 		/* 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");
+ 				return;
+     	}
+ 
+ #endif
+ 
+ #ifdef NOWAIT
+ 	loopback.sin_family = AF_INET;
+ 	loopback.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ 	loopback.sin_port = local_ns_port;
+ #endif
+ 
+ 
+     // open our mail slot
+     //    
+     slotHandle = CreateMailslot(
+                     "\\\\.\\mailslot\\sd_bind",0,MAILSLOT_WAIT_FOREVER,NULL);
+ 
+     if (slotHandle == INVALID_HANDLE_VALUE)
+       {
+        syslog(LOG_ERR, "CreateMailSlot for ndc communications failed: %m");
+ 	if (debug)
+ 	  fprintf(ddt, "CreateMailslot for ndc communications failed error = %d\n",GetLastError());
+        exit(1);
+       }
+ 
+     // okay, our pipe has been created, let's enter the simple
+     //  processing loop...
+     //
+     
+     id = 0;
+     lastid = 0;
+     while (1) {
+ 
+ 
+         // bug in readfile here.. under win95 even with timeout set to infinite this is a busy wait
+         // consuming 100% of cpu so try getmail slot info with sleep statement
+         // actually use waitforsingleobject which is the correct way even
+         // though the documentation on this api does not mention mailslots
+         // as a handle you can wait on.. apparently it does become signaled
+         // and can be used. ..
+         
+ 
+         onefound = FALSE;
+         wcount = 0;
+         while (!onefound)
+ 
+          {
+ 
+            fResult = GetMailslotInfo(slotHandle, /* mailslot handle         */ 
+                          (LPDWORD) NULL,              /* no maximum message size */ 
+                          (LPDWORD) NULL,              /* size of next message    */ 
+                          &wcount,                     /* number of messages      */ 
+                          (LPDWORD) NULL);             /* no read time-out        */ 
+  
+            if (!fResult)
+              { 
+                syslog(LOG_ERR,"Error in GetMailSlotInfo: %m");
+  	       if (debug)
+ 	         fprintf(ddt, "Error in GetMailSlotInfo error = %d\n",GetLastError());
+                Sleep(5000);
+                continue;
+              } 
+ 
+            if (wcount > 0)
+                onefound = TRUE;
+            else Sleep(5000);
+ 
+          } // end of one found loop
+          
+         // grab whatever's coming through the slot...
+         //
+         strcpy(inbuf,"                                           ");
+         strcpy(command,"                     ");
+         bad_code = FALSE;
+         bytesRead = 0;
+         ret = ReadFile(
+                     slotHandle,     // file to read from
+                     &inbuf,         // address of input buffer
+                     sizeof(inbuf),  // number of bytes to read
+                     &bytesRead,     // number of bytes read
+                     NULL);          // overlapped stuff, not needed
+ 
+         if ((!ret) || (bytesRead == 0))
+            continue;
+             // .. go back and reconnect
+             //
+ 
+         // ok now check which mailbox to send message back to either sd_ndc or sd_ndcpl
+ 
+           sscanf(inbuf,"%s %s %s %d",machname,mbname,command,&id);
+           // now check if same as last time and if so skip it..
+           
+ 	  if (debug > 0)
+ 	     { // for debugging
+               char temp[100];
+               sprintf(temp,"NDC remote command \"%s\" from machine %s with id %d reply to %s\n",command,machname,id,mbname);
+  	      dprintf(1, (ddt,temp));
+ 	     } 
+           
+ 	   if (id == lastid)
+              continue;
+ 
+           lastid = id;
+           strcpy(outbuf,"Ok"); // need some return so other pipe stops waiting
+ 
+        // start and restart are handled by ndc ...
+        if (strncmp(command,"stop",4) == 0)
+          {
+  #ifdef XSTATS
+             needToExit = 1;
+  #endif
+ 
+             was_stopped = 1;
+             doterminate = 1;
+             SetEvent(hServDoneEvent);
+          }
+ 
+        else if (strncmp(command,"status",6) == 0)
+ 		  { // returning that we are running ok
+ 			  char temp[40];
+           
+ 			  sprintf(temp,"Query log %s. ",qrylog ? "on":"off");
+ 			  strcpy(outbuf,temp);
+ 			  
+ 			  if (debug > 0) sprintf(temp,"Debug Level %d enabled.",debug);
+ 			  else  sprintf(temp,"Debuging Off!");
+ 			  strcat(outbuf,temp);
+ 			  
+           }
+ 
+        else if (strncmp(command,"dumpdb",6) == 0)
+          {
+           needToDoadump = 1;
+          }
+ 
+        else if (strncmp(command,"reload",6) == 0)
+          {
+ 	  needreload = 1;
+          }
+ 
+        else if (strncmp(command,"stats",5) == 0)
+          {
+ 	   needStatsDump = 1;
+          }
+ 
+        else if (strncmp(command,"trace",5) == 0)
+          {
+ 	   debug++;
+ 	   if (debug == 1)
+ 	     setdebug(1);
+ 	   fprintf(ddt, "Debug turned ON, Level %d\n", debug);
+          }
+ 
+        else if (strncmp(command,"notrace",7) == 0)
+          {
+ 	   setdebug(0);
+          }
+ 
+        else if (strncmp(command,"querylog",8) == 0)
+          {
+ 	   qrylog = !qrylog;
+ 	   syslog(LOG_NOTICE, "querylog %s\n", qrylog ? "on":"off");
+          }
+ 
+        else if (strncmp(command,"qrylog",6) == 0)
+          {
+ 	   qrylog = !qrylog;
+ 	   syslog(LOG_NOTICE, "querylog %s\n", qrylog ? "on":"off");
+          }
+ 
+        else
+        {
+  	    syslog(LOG_ERR, "invalid control code: %s", command);
+          bad_code = TRUE;
+        }
+        
+ #ifdef NOWAIT
+ 
+         // also don't do this for status as nothing is pending
+         if ((!bad_code) && (strncmp(command,"status",6) != 0))
+          {
+  	  
+              	if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+                  {
+ 			    syslog(LOG_ERR, "socket for nowait: %m");
+ 		       }
+ 
+                else
+                {
+                if (connect(s, (struct sockaddr *)&loopback, sizeof(loopback)) < 0) 
+ 				syslog(LOG_ERR,
+ 				       "connect for nowait (%s) for failed: %m",
+ 				       inet_ntoa(loopback.sin_addr));
+ 
+                else 
+                {  
+                  if((len = sendto(s, (const char *)loopbuf, 1, 0, (const struct sockaddr *)&loopback,
+ 	             sizeof(struct sockaddr_in))) == SOCKET_ERROR)
+ 		        syslog(LOG_ERR, "failed to send the control code immediately: %m");
+                }
+                (void) closesocket(s);
+                }
+          }
+ #endif
+ 
+           // now open the out mailbox and write response .. if it fails ignore
+           strcpy(outname,"\\\\");
+           strcat(outname,machname);
+           strcat(outname,"\\mailslot\\");
+           strcat(outname,mbname);
+        
+           outslot = CreateFile(outname,GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_EXISTING,
+                                FILE_ATTRIBUTE_NORMAL,NULL);
+ 
+           if (outslot == INVALID_HANDLE_VALUE)
+             {
+               char temp[200];
+               sprintf(temp,"Cannot open outgoing mailslot: %s ... response was %s !\n",outname,outbuf);
+               syslog(LOG_WARNING,temp);                    
+             }
+           else { // write data
+ 
+           ret = WriteFile(
+                     outslot,     // file to write to
+                     &outbuf,         // address of output buffer
+                     strlen(outbuf) + 1, // number of bytes to write
+                     &bytesWritten,  // number of bytes written
+                     NULL);          // overlapped stuff, not needed
+ 
+           if (!ret)
+             // failed... go back and reconnect
+             //
+             continue;
+         // close handle...
+         //
+         CloseHandle(outslot);
+ 
+        }
+     } // end of loop
+ }
+ 
+ #endif // win95
+ 
+ 
+ #endif /* WINNT */
diff --context --recurs m:\bind495p1/named/ns_maint.c m:\bind/named/ns_maint.c
*** m:\bind495p1/named/ns_maint.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/ns_maint.c	Tue Oct 08 13:07:00 1996
***************
*** 58,81 ****
   * --Copyright--
   */
  
! #include <sys/param.h>
! #include <sys/types.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
! #include <sys/wait.h>
! #include <stdio.h>
! #include <syslog.h>
! #include <signal.h>
  #include <errno.h>
  #include <sys/stat.h>
  
  #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 */
--- 58,91 ----
   * --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>
  
  #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 */
***************
*** 91,101 ****
  #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.
--- 101,185 ----
  #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;
+ HANDLE threadhandle2 = 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;
+ 
+ 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.
***************
*** 107,121 ****
  	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
  		if (debug >= 2)
  			printzoneinfo(zonenum);
  #endif
  		if (tt.tv_sec >= zp->z_time && zp->z_refresh > 0) {
  			switch (zp->z_type) {
  
--- 191,206 ----
  	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
  		if (debug >= 2)
  			printzoneinfo(zonenum);
  #endif
+                 dprintf(1, (ddt, "debug tt.tv_sec = %d , zp->z_time = %d, zp->z_refresh = %d \n",
+                                  tt.tv_sec,zp->z_time, zp->z_refresh));
+                 dprintf(1, (ddt, "want tv_sec > = z_time and z_refresh > 0 \n"));
  		if (tt.tv_sec >= zp->z_time && zp->z_refresh > 0) {
  			switch (zp->z_type) {
  
***************
*** 140,145 ****
--- 225,231 ----
  					break;
  				}
  				if (zp->z_flags & Z_XFER_RUNNING) {
+ 				        dprintf(1, (ddt, "calling abort\n"));
  					abortxfer(zp);
  					break;
  				}
***************
*** 176,182 ****
--- 262,272 ----
  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
***************
*** 192,198 ****
  	 *  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"));
--- 282,290 ----
  	 *  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"));
***************
*** 204,218 ****
--- 296,371 ----
  		 */
  		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 = NULL;
+        threadhandle = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)thread_timer_fx,(LPVOID)wDelay,0,&threadid);
+ 
+        if (threadhandle == NULL)
+ 	     {
+            syslog(LOG_ERR, "CreateThread() for maintenance: %m");
+ 	     }
+ 
+        
+        pending_delay = wDelay;
+  	   dprintf(1, (ddt, "sched_maint: Next interrupt in %d sec\n",wDelay/1000));
+        LeaveCriticalSection(&maint_section);
+ 
+ #endif
  }
  
  /*
***************
*** 276,282 ****
  	qp = sysquery(zp->z_origin, zp->z_class, T_SOA,
  		      zp->z_addr, zp->z_addrcnt, QUERY);
  	if (!qp) {
! 		syslog(LOG_INFO, "qserial_query(%s): sysquery FAILED",
  		       zp->z_origin);
  		return;		/* XXX - this is bad, we should do something */
  	}
--- 429,435 ----
  	qp = sysquery(zp->z_origin, zp->z_class, T_SOA,
  		      zp->z_addr, zp->z_addrcnt, QUERY);
  	if (!qp) {
! 		syslog(LOG_WARNING, "qserial_query(%s): sysquery FAILED",
  		       zp->z_origin);
  		return;		/* XXX - this is bad, we should do something */
  	}
***************
*** 340,345 ****
--- 493,499 ----
  #endif
  #endif /* POSIX_SIGNALS */
  
+ #ifndef WINNT
  void holdsigchld()
  {
  #ifdef POSIX_SIGNALS
***************
*** 366,371 ****
--- 520,526 ----
  #endif /* POSIX_SIGNALS */
  }
  
+ #endif
  	/* State of all running zone transfers */
  static struct {
  	pid_t 	xfer_pid;
***************
*** 390,396 ****
  	struct zoneinfo *zp;
  {
  	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];
--- 545,554 ----
  	struct zoneinfo *zp;
  {
  	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];
***************
*** 398,407 ****
  #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";
--- 556,584 ----
  #ifdef GEN_AXFR
  	char class_str[10];
  #endif
+ #ifdef WINNT
+ 	char *pos;
+ 	DWORD xfer_thread_id;
+ 	STARTUPINFO sui;
+ 	static char CommandLine[NSMAX*(MAXDNAME+1)+20*10];
+ 	PROCESS_INFORMATION *proc_info_copy;
+     
+ 
+ #else
+ 	int pid;
+ #endif
  
  	dprintf(1, (ddt, "startxfer() %s\n", zp->z_origin));
  
! #ifndef WINNT
! 	argv[argc++] = "_PATH_XFER";
! #else
! #ifndef WIN95
! 	argv[argc++] = "xfer";
! #else
! 	argv[argc++] = "xfer95";
! #endif
! #endif
  	argv[argc++] = "-z";
  	argv[argc++] = zp->z_origin;
  	argv[argc++] = "-f";
***************
*** 429,438 ****
--- 606,623 ----
  		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
***************
*** 460,488 ****
  			argv[argc++] = strcpy(argv_ns[argc_ns++],
  					      inet_ntoa(a));
  		}
!         }
  
  	argv[argc] = 0;
  
  #ifdef DEBUG
  	if (debug) {
  		for (i = 0; i < argc; i++) 
  			fprintf(ddt, " %s", argv[i]);
  		fprintf(ddt, "\n");
!         }
  #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;
  	}
--- 645,694 ----
  			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
  	if (debug) {
  		for (i = 0; i < argc; i++) 
  			fprintf(ddt, " %s", argv[i]);
  		fprintf(ddt, "\n");
! 	}
  #endif /* DEBUG */
  
  	gettime(&tt);
! #ifndef WINNT
!    	holdsigchld();
! #else
!     /* make sure we don't have two accessing the same structures */
!     /* lgk use critical section here for this and in endxfer where this is read to make sure that not more
!        than one is trying to start a xfer process at a time */
!     EnterCriticalSection(&protected_zp);
!     proc_info_copy = (PROCESS_INFORMATION *)malloc(sizeof(PROCESS_INFORMATION));
!  
! #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;
  	}
***************
*** 491,508 ****
  		/* 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 *
--- 697,756 ----
  		/* 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)proc_info_copy))
!       {
! 	     syslog(LOG_ERR, "CreateProcess() for xfer: %m");
!              LeaveCriticalSection(&protected_zp);
! 	     return;
! 	  }
! 
! 	threadhandle2 = NULL;
! 	threadhandle2 = 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);
! 
!     if (threadhandle2 == NULL)
! 	  {
!         syslog(LOG_ERR, "CreateThread() for xfer status: %m");
!         LeaveCriticalSection(&protected_zp);
! 	return;
! 	  }
! 	CloseHandle(threadhandle2); /* no handle to this needed */
! 	
! #endif /* WINNT */
! 	/* parent */
! #ifdef WINNT
! 	dprintf(1, (ddt, "started xfer child %d\n", proc_info_copy->hProcess));
!     zp->z_xferpid = proc_info_copy->hProcess;
!   	xferstatus[i].xfer_pid = (long)proc_info_copy->hProcess;
! #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 *
***************
*** 645,651 ****
  	    !ns_wildcard(NAME(*np))) {
  		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;
--- 893,899 ----
  	    !ns_wildcard(NAME(*np))) {
  		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;
***************
*** 795,810 ****
  /*
   * 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;
  			}
--- 1043,1075 ----
  /*
   * Abort an xfer that has taken too long.
   */
+ 
  static void
  abortxfer(zp)
  	struct zoneinfo *zp;
!    {
! 
! #ifdef WINNT
! 	    TerminateProcess(zp->z_xferpid, (UINT)XFER_KILLED);
! 
! 	    syslog(LOG_WARNING,
! 		"zone transfer timeout for \"%s\"; pid %lu killed",
! 		zp->z_origin, (u_long)zp->z_xferpid);
!              dprintf(1, (ddt, "zone transfer timeout for %s pid %lu killed\n",
! 		zp->z_origin, (u_long)zp->z_xferpid));
! 
! 		zp->z_flags |= Z_XFER_ABORTED;
! 	     ns_retrytime(zp, tt.tv_sec);
!  	     (void) nxfers(zp, -1);        
! 
! #else
! 
  	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;
  			}
***************
*** 814,834 ****
  			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;
--- 1079,1102 ----
  			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;
***************
*** 844,851 ****
  		       zp->z_origin, (u_long)zp->z_xferpid);
  		zp->z_flags |= Z_XFER_ABORTED;
  	}
! }
  
  /*
   * SIGCHLD signal handler: process exit of xfer's.
   * (Note: also called when outgoing transfer completes.)
--- 1112,1123 ----
  		       zp->z_origin, (u_long)zp->z_xferpid);
  		zp->z_flags |= Z_XFER_ABORTED;
  	}
! 	
! #endif
!    }
! 
  
+ #ifndef WINNT
  /*
   * SIGCHLD signal handler: process exit of xfer's.
   * (Note: also called when outgoing transfer completes.)
***************
*** 883,921 ****
  	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
  				    )
--- 1155,1252 ----
  	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;
  #if defined(sequent)
  	union wait status;
  #else
  	int status;
  #endif /* sequent */
+ #else
+ 	DWORD exitstatus;
+ #endif
+     int i;
  
! gettime(&tt);
  
! /* under Win NT this should not get called unless a transfer has completed 
!  * 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 (%d) process: %m",pid);
! 	    dprintf(1, (ddt, "endxfer: cannot determine return code of the xfer (%d) process: %d",pid,GetLastError()));
!             /* lgk new code here if we cannot figure this out dummy it up so it gets rescheduled anyway */
!             /* dont return as previously or the zone does not get rescheduled */
!             exitstatus = XFER_FAIL;
! 	  }
! #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;
+ 			    	
+ 			   } 
+ 		      }
+ 		     /* lgk problem is here we cannot close the handle here as it will reuse it and then close it again later
+ 		        don't think we need to close this handle anyway as it is the same handle that is closed before the free
+ 		        in named_xfer  the problem was that critical sections allow the same thread
+ 		        to go into the same critical section more than once and since this handle was
+ 		        already closed here it was re-allocated and closed again in named-xfer after the call to endxfer  
+ 		     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
  				    )
***************
*** 929,934 ****
--- 1260,1270 ----
  				}
  				ns_retrytime(zp, tt.tv_sec);
  			} else {
+ #else /* WINNT */
+ 			dprintf(1, (ddt,
+ 		            "\nendxfer: child %d zone %s returned status=%d \n", 
+ 				    pid, zp->z_origin, exitstatus));
+ #endif /* WINNT */
  				switch (exitstatus) {
  				case XFER_UPTODATE:
  					markUpToDate(zp);
***************
*** 939,978 ****
  					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();
  }
  
  /*
--- 1275,1329 ----
  					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_WARNING,
! 	 	                                        "zoneref: Masters for secondary zone \"%s\" unreachable",
  						       zp->z_origin);
  					}
+                     dprintf(1, (ddt, "Masters for secondary zone %s unreachable (xfer timed out) (child = %d)\n",zp->z_origin,pid));
  					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;
+                     dprintf(1, (ddt, "(xfer for %s failed in endxfer) (child = %d)\n",zp->z_origin,pid));
+                     syslog(LOG_WARNING, "(xfer for %s failed) (child = %d) - rescheduling!\n",zp->z_origin,pid);
  					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();
+ 
  }
  
  /*
***************
*** 1046,1052 ****
   */
  void
  loadxfer() {
!     	register struct zoneinfo *zp;   
  
  	gettime(&tt);
  	for (zp = zones; zp < &zones[nzones]; zp++) {
--- 1397,1403 ----
   */
  void
  loadxfer() {
! 	register struct zoneinfo *zp;   
  
  	gettime(&tt);
  	for (zp = zones; zp < &zones[nzones]; zp++) {
***************
*** 1085,1087 ****
--- 1436,1519 ----
  		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);
+ 
+ 
+     /* now check reason we woke up */
+     /* remove the return now so let it go into endxfer even if the wait fails so we can resched. the xfer */
+     switch (dwWait)
+      {
+ 
+       case WAIT_TIMEOUT:
+            syslog(LOG_ERR, "WaitForSingleObject() on named-xfer process (%d) status timed out!",(*proc_info).hProcess);
+            dprintf(1,(ddt, "WaitForSingleObject() on named-xfer process (%d) status timed out!\n",(*proc_info).hProcess));
+ 	       break;
+ 
+       case WAIT_FAILED:
+            syslog(LOG_ERR, "WaitForSingleObject() on named-xfer process (%d) status failed: %m",(*proc_info).hProcess);
+            dprintf(1,(ddt, "WaitForSingleObject() on named-xfer process (%d) status failed: %d\n",(*proc_info).hProcess,GetLastError()));
+ 	       break;
+ 
+       case WAIT_OBJECT_0:
+            /* normal case */
+            break;
+        
+       default:
+         dprintf(1, (ddt, "Unknown return type from WaitForSingleObject on named-xfer (%d) status! (%d)\n",(*proc_info).hProcess,dwWait));
+         syslog(LOG_ERR, "Unknown return type from WaitForSingleObject on named-xfer (%d) status %d:",(*proc_info).hProcess,dwWait);
+         break;
+       
+      }
+     
+     /* lgk new code using critical section to synchronize */
+     EnterCriticalSection(&protected_zp);
+     endxfer((*proc_info).hProcess);
+     /* dont try the close if the wait failed for some reason */
+     /* if we have an extra handle around so be it but if the handle is bad ie wait failed not sure what close will do */
+     if (dwWait == WAIT_OBJECT_0)
+       {
+        CloseHandle((*proc_info).hProcess);
+        CloseHandle((*proc_info).hThread);
+       }
+     free((char *)proc_info);
+     LeaveCriticalSection(&protected_zp);
+ }
+ #endif /* WINNT */
diff --context --recurs m:\bind495p1/named/ns_ncache.c m:\bind/named/ns_ncache.c
*** m:\bind495p1/named/ns_ncache.c	Thu Dec 19 02:24:24 1996
--- m:\bind/named/ns_ncache.c	Tue Oct 08 13:07:00 1996
***************
*** 7,21 ****
   */
  
  #include <sys/types.h>
! #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>
  
  #include "named.h"
  
--- 7,25 ----
   */
  
  #include <sys/types.h>
! #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>
  
  #include "named.h"
  
***************
*** 33,39 ****
--- 37,45 ----
  	int n;
  	int type, class;
  #ifdef VALIDATE
+ #ifdef VALIDATE
  	int Vcode;
+ #endif
  #endif
  	int flags;
  
diff --context --recurs m:\bind495p1/named/ns_req.c m:\bind/named/ns_req.c
*** m:\bind495p1/named/ns_req.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/ns_req.c	Mon Nov 04 22:45:18 1996
***************
*** 81,96 ****
   */
  
  #include <sys/types.h>
! #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>
  
--- 81,100 ----
   */
  
  #include <sys/types.h>
! #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>
  
***************
*** 103,108 ****
--- 107,126 ----
  	u_int16_t	a_class;		/* class for address */
  };
  
+ #ifdef WINNT
+ extern CRITICAL_SECTION doxfr_section;
+ 
+ #define _exit(x) ExitThread(x)
+ struct ntxfr {
+ 	struct qstream *qsp;
+ 	struct namebuf *np;
+ 	u_char *soa;
+ 	int soalen;
+ 	int class;
+      u_char *dnptrs[40];
+ };
+ #endif
+ 
  enum req_action { Finish, Refuse, Return };
  
  static enum req_action	req_query __P((HEADER *hp, u_char **cpp, u_char *eom,
***************
*** 120,130 ****
--- 138,160 ----
  					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
+ #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
  
  static struct addinfo	addinfo[NADDRECS];
  static void		addname __P((const char *, const char *,
***************
*** 183,189 ****
  	buflen -= HFIXEDSZ;
  
  	free_addinfo();	/* sets addcount to zero */
! 	dnptrs[0] = NULL;
  
  	switch (hp->opcode) {
  	case QUERY:
--- 213,219 ----
  	buflen -= HFIXEDSZ;
  
  	free_addinfo();	/* sets addcount to zero */
! 	dnptrs [0] = NULL;
  
  	switch (hp->opcode) {
  	case QUERY:
***************
*** 249,255 ****
  #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*/
--- 279,286 ----
  #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*/
***************
*** 434,443 ****
  	*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);
--- 465,474 ----
  	*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);
***************
*** 522,528 ****
  			 * for negation some day.
  			 */
  			if (!addr_on_netlist(from->sin_addr, xfrnets)) {
! 				syslog(LOG_INFO,
  				       "unapproved AXFR from %s for %s",
  				       sin_ntoa(from), *dnbuf ? dnbuf : ".");
  				return (Refuse);
--- 553,559 ----
  			 * for negation some day.
  			 */
  			if (!addr_on_netlist(from->sin_addr, xfrnets)) {
! 				syslog(LOG_WARNING,
  				       "unapproved AXFR from %s for %s",
  				       sin_ntoa(from), *dnbuf ? dnbuf : ".");
  				return (Refuse);
***************
*** 552,558 ****
  
   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 = "";
--- 583,589 ----
  
   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 = "";
***************
*** 689,695 ****
  			*cpp += n;
  			*buflenp -= n;
  			*msglenp += n;
! 			hp->nscount = htons(count);
  		}
  #endif
  		founddata = 1;
--- 720,726 ----
  			*cpp += n;
  			*buflenp -= n;
  			*msglenp += n;
!                hp->nscount = htons((u_int16_t)count);
  		}
  #endif
  		founddata = 1;
***************
*** 700,706 ****
  	*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,
--- 731,737 ----
  	*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,
***************
*** 784,790 ****
  				*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 */
  				free_nsp(nsp);
--- 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 */
  				free_nsp(nsp);
***************
*** 968,977 ****
  	nameserIncr(from->sin_addr, nssRcvdIQ);
  #endif
  
! 	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);
--- 999,1008 ----
  	nameserIncr(from->sin_addr, nssRcvdIQ);
  #endif
  
! 	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);
***************
*** 1111,1126 ****
--- 1142,1169 ----
  }
  
  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);
  	}
***************
*** 1213,1219 ****
  	register int32_t n;
  	register int16_t type = dp->d_type;
  	register u_int32_t ttl;
! 	u_char **edp = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
  
  	dprintf(5, (ddt, "make_rr(%s, %lx, %lx, %d, %d) %d zone %d ttl %lu\n",
  		    name, (u_long)dp, (u_long)buf,
--- 1256,1262 ----
  	register int32_t n;
  	register int16_t type = dp->d_type;
  	register u_int32_t ttl;
!         u_char **edp = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
  
  	dprintf(5, (ddt, "make_rr(%s, %lx, %lx, %d, %d) %d zone %d ttl %lu\n",
  		    name, (u_long)dp, (u_long)buf,
***************
*** 1232,1238 ****
  	/* check for outdated RR before updating dnptrs by dn_comp() (?) */
  	if (zp->z_type == Z_CACHE) {
  		if ((dp->d_flags & DB_F_HINT) != 0
! 		    || dp->d_ttl < (u_int32_t)tt.tv_sec) {
  			ttl = 0;
  		} else
  			ttl = dp->d_ttl - (u_int32_t) tt.tv_sec;
--- 1275,1585 ----
  	/* check for outdated RR before updating dnptrs by dn_comp() (?) */
  	if (zp->z_type == Z_CACHE) {
  		if ((dp->d_flags & DB_F_HINT) != 0
! #ifndef WINNT
! 	        || dp->d_ttl < (u_int32_t)tt.tv_sec) {
! #else
!      		|| dp->d_ttl < (int32_t)tt.tv_sec) {
! #endif
! 			ttl = 0;
! 		} else
! 			ttl = dp->d_ttl - (u_int32_t) tt.tv_sec;
! 	} else {
! 		if (dp->d_ttl != USE_MINIMUM)
! 			ttl = dp->d_ttl;
! 		else
! 			ttl = zp->z_minimum;		/* really default */
! #ifdef notdef /* don't decrease ttl based on time since verification */
! 		if (zp->z_type == Z_SECONDARY) {
! 			/*
! 			 * Set ttl to value received from primary,
! 			 * less time since we verified it (but never
! 			 * less than a small positive value).
! 			 */
! 			ttl -= tt.tv_sec - zp->z_lastupdate;
! 			if (ttl <= 0)
! 				ttl = 120;
! 		}
! #endif
! 	}
! 
! 	buflen -= RRFIXEDSZ;
! #if defined(RETURNSOA) && defined(NCACHE)
! 	if (dp->d_rcode) {
! 		name = (char *)dp->d_data;
! 		name += strlen(name) +1;
! 		name += strlen(name) +1;
! 		name += 5 * INT32SZ;
! 		type = T_SOA;
! 	}
! #endif
! 	if ((n = dn_comp(name, buf, buflen, dnptrs, edp)) < 0)
! 		return (-1);
! 	cp = buf + n;
! 	buflen -= n;
! 	PUTSHORT((u_int16_t)type, cp);
! 	PUTSHORT((u_int16_t)dp->d_class, cp);
! 	PUTLONG(ttl, cp);
! 	sp = cp;
! 	cp += INT16SZ;
! 	switch (type) {
! 	case T_CNAME:
! 	case T_MG:
! 	case T_MR:
! 	case T_PTR:
! 		n = dn_comp((char *)dp->d_data, cp, buflen, dnptrs, edp);
! 		if (n < 0)
! 			return (-1);
! 		PUTSHORT((u_int16_t)n, sp);
! 		cp += n;
! 		break;
! 
! 	case T_MB:
! 	case T_NS:
! 		/* Store domain name in answer */
! 		n = dn_comp((char *)dp->d_data, cp, buflen, dnptrs, edp);
! 		if (n < 0)
! 			return (-1);
! 		PUTSHORT((u_int16_t)n, sp);
! 		cp += n;
! 		if (doadd)
! 			addname((char*)dp->d_data, name,
! 				type, dp->d_class);
! 		break;
! 
! 	case T_SOA:
! 	case T_MINFO:
! 	case T_RP:
! 		cp1 = dp->d_data;
! 		n = dn_comp((char *)cp1, cp, buflen, dnptrs, edp);
! 		if (n < 0)
! 			return (-1);
! 		cp += n;
! 		buflen -= type == T_SOA ? n + 5 * INT32SZ : n;
! 		cp1 += strlen((char *)cp1) + 1;
! 		n = dn_comp((char *)cp1, cp, buflen, dnptrs, edp);
! 		if (n < 0)
! 			return (-1);
! 		cp += n;
! 		if (type == T_SOA) {
! 			cp1 += strlen((char *)cp1) + 1;
! 			bcopy(cp1, cp, (n = 5 * INT32SZ));
! 			cp += n;
! 		}
! 		n = (u_int16_t)((cp - sp) - INT16SZ);
! 		PUTSHORT((u_int16_t)n, sp);
! 		break;
! 
! 	case T_NAPTR:
! 		/* cp1 == our data/ cp == data of RR */
! 		cp1 = dp->d_data;
! 
!  		if ((buflen -= INT16SZ) < 0)
! 			return (-1);
! 
!  		/* copy order */
!  		bcopy(cp1, cp, INT16SZ);
!  		cp += INT16SZ;
!  		cp1 += INT16SZ;
! 		n = (u_int16_t)((cp - sp) - INT16SZ);
! 		dprintf(1, (ddt, "current size n = %u\n", n));
! 
! 		/* copy preference */
! 		bcopy(cp1, cp, INT16SZ);
! 		cp += INT16SZ;
! 		cp1 += INT16SZ;
! 		n = (u_int16_t)((cp - sp) - INT16SZ);
! 		dprintf(1, (ddt, "current size n = %u\n", n));
! 
! 		/* Flags */
! 		n = *cp1++;
! 		dprintf(1, (ddt, "size of n at flags = %d\n", n));
! 		*cp++ = n;
! 		bcopy(cp1,cp,n);
! 		cp += n;
! 		cp1 += n;
! 		n = (u_int16_t)((cp - sp) - INT16SZ);
! 		dprintf(1, (ddt, "current size n = %u\n", n));
! 		
! 		/* Service */
! 		n = *cp1++;
! 		*cp++ = n;
! 		bcopy(cp1,cp,n);
! 		cp += n;
! 		cp1 += n;
! 		n = (u_int16_t)((cp - sp) - INT16SZ);
! 		dprintf(1, (ddt, "current size n = %u\n", n));
! 
! 		/* Regexp */
! 		n = *cp1++;
! 		*cp++ = n;
! 		bcopy(cp1,cp,n);
! 		cp += n;
! 		cp1 += n;
! 		n = (u_int16_t)((cp - sp) - INT16SZ);
! 		dprintf(1, (ddt, "current size n = %u\n", n));
! 
! 		/* Replacement */
! 		dprintf(1, (ddt, "Replacement = %s\n", cp1));
! 		n = dn_comp((char *)cp1, cp, buflen, dnptrs, edp);
! 		dprintf(1, (ddt, "dn_comp's n = %u\n", n));
! 		if (n < 0)
! 			return (-1);
! 		cp += n;
! 
! 		/* save data length */
! 		n = (u_int16_t)((cp - sp) - INT16SZ);
! 		dprintf(1, (ddt, "saved size n = %u\n", n));
! 		PUTSHORT((u_int16_t)n, sp);
! 
! 		break;
! 
! 	case T_MX:
! 	case T_AFSDB:
! 	case T_RT:
! 	case T_SRV:
! 		/* cp1 == our data/ cp == data of RR */
! 		cp1 = dp->d_data;
! 
!  		if ((buflen -= INT16SZ) < 0)
! 			return (-1);
! 
!  		/* copy preference */
!  		bcopy(cp1, cp, INT16SZ);
!  		cp += INT16SZ;
!  		cp1 += INT16SZ;
! 
! 		if (type == T_SRV) {
! 			bcopy(cp1, cp, INT16SZ*2);
! 			cp += INT16SZ*2;
! 			cp1 += INT16SZ*2;
! 		}
! 
! 		n = dn_comp((char *)cp1, cp, buflen, dnptrs, edp);
! 		if (n < 0)
! 			return (-1);
! 		cp += n;
! 
! 		/* save data length */
! 		n = (u_int16_t)((cp - sp) - INT16SZ);
! 		PUTSHORT((u_int16_t)n, sp);
! 		if (doadd)
! 			addname((char*)cp1, name, type, dp->d_class);
! 		break;
! 
! 	case T_PX:
! 		cp1 = dp->d_data;
! 
! 		if ((buflen -= INT16SZ) < 0)
! 			return (-1);
! 
! 		/* copy preference */
! 		bcopy(cp1, cp, INT16SZ);
! 		cp += INT16SZ;
! 		cp1 += INT16SZ;
! 
! 		n = dn_comp((char *)cp1, cp, buflen, dnptrs, edp);
! 		if (n < 0)
! 			return (-1);
! 		cp += n;
! 		buflen -= n;
! 		cp1 += strlen((char *)cp1) + 1;
! 		n = dn_comp((char *)cp1, cp, buflen, dnptrs, edp);
! 		if (n < 0)
! 			return (-1);
! 		cp += n;
! 
! 		/* save data length */
! 		n = (u_int16_t)((cp - sp) - INT16SZ);
! 		PUTSHORT((u_int16_t)n, sp);
! 		break;
! 
! 	case T_SIG:
! 		/* cp1 == our data; cp == data of target RR */
! 		cp1 = dp->d_data;
! 
! 		/* first just copy over the type_covered, algorithm, */
! 		/* labels, orig ttl, two timestamps, and the footprint */
! 		if ((dp->d_size - 18) > buflen)
! 			return (-1);  /* out of room! */
! 		bcopy( cp1, cp, 18 );
! 		cp  += 18;
! 		cp1 += 18;
! 		buflen -= 18;
! 
! 		/* then the signer's name */
! 		n = dn_comp((char *)cp1, cp, buflen, NULL, NULL);
! 		if (n < 0)
! 			return (-1);
! 		cp += n;
! 		buflen -= n;
! 		cp1 += strlen((char*)cp1)+1;
! 
! 		/* finally, we copy over the variable-length signature */
! 		n = dp->d_size - (u_int16_t)((cp1 - dp->d_data));
! 		if (n > buflen)
! 			return (-1);  /* out of room! */
! 		bcopy(cp1, cp, n);
! 		cp += n;
! 		
!   		/* save data length & return */
! 		n = (u_int16_t)((cp - sp) - INT16SZ);
!   		PUTSHORT((u_int16_t)n, sp);
! 		break;
! 
! 	default:
! 		if (dp->d_size > buflen)
! 			return (-1);
! 		bcopy(dp->d_data, cp, dp->d_size);
! 		PUTSHORT((u_int16_t)dp->d_size, sp);
! 		cp += dp->d_size;
! 	}
! 
! 	return (cp - buf);
! }
! 
! 
! 
! /*
!  * Copy databuf into a resource record for replies.
!  * Return size of RR if OK, -1 if buffer is full.
!  */
! int
! make_rr2(name, dp, buf, buflen, doadd, dnptrs)
! 	const char *name;
! 	register struct databuf *dp;
! 	u_char *buf;
! 	int buflen, doadd;
! 	u_char **dnptrs;
! {
! 	register u_char *cp;
! 	u_char *cp1, *sp;
! 	struct zoneinfo *zp;
! 	register int32_t n;
! 	register int16_t type = dp->d_type;
! 	register u_int32_t ttl;
!         u_char **edp = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
! 	dprintf(5, (ddt, "make_rr2(%s, %lx, %lx, %d, %d) %d zone %d ttl %lu\n",
! 		    name, (u_long)dp, (u_long)buf,
! 		    buflen, doadd, dp->d_size, dp->d_zone, (u_long)dp->d_ttl));
! 
! #ifdef	NCACHE
! 	if (dp->d_rcode
! #ifdef RETURNSOA
! 	    && dp->d_size == 0
! #endif
! 	) {
! 		panic(-1, "make_rr2: impossible d_rcode value");
! 	}
! #endif
! 	zp = &zones[dp->d_zone];
! 	/* check for outdated RR before updating dnptrs by dn_comp() (?) */
! 	if (zp->z_type == Z_CACHE) {
! 		if ((dp->d_flags & DB_F_HINT) != 0
! #ifndef WINNT
! 	        || dp->d_ttl < (u_int32_t)tt.tv_sec) {
! #else
!      		|| dp->d_ttl < (int32_t)tt.tv_sec) {
! #endif
  			ttl = 0;
  		} else
  			ttl = dp->d_ttl - (u_int32_t) tt.tv_sec;
***************
*** 1489,1494 ****
--- 1836,1845 ----
  	return (cp - buf);
  }
  
+ 
+ 
+ 
+ 
  #if defined(__STDC__) || defined(__GNUC__)
  static void
  addname(register const char *dname,
***************
*** 1664,1670 ****
  		}
  		return (0);
  	}
! 	hp->nscount = htons(ntohs(hp->nscount) + 1);
  	return (n);
  }
  
--- 2015,2021 ----
  		}
  		return (0);
  	}
! 	hp->nscount = htons((u_short)(ntohs((u_short)hp->nscount) + 1));
  	return (n);
  }
  
***************
*** 1679,1689 ****
--- 2030,2049 ----
   * 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, dnptrs_copy)
+ 	register struct namebuf *np;
+ 	SOCKET rfd;
+ 	struct namebuf *top;
+ 	int class;		/* Class to transfer */
+ 	u_char **dnptrs_copy;
+ #endif
  {
  	register struct databuf *dp;
  	register int n;
***************
*** 1724,1733 ****
--- 2084,2101 ----
  #endif
  	    if (dp->d_type == T_NS) {
  		fndns = 1;
+ #ifndef WINNT
  		n = make_rr(dname, dp, cp, sizeof(msg)-HFIXEDSZ, 0);
+ #else
+ 		n = make_rr2(dname, dp, cp, sizeof(msg)-HFIXEDSZ, 0, dnptrs_copy);
+ #endif
  		if (n < 0)
  			continue;
+ #ifndef WINNT
  		fwritemsg(rfp, msg, n + HFIXEDSZ);
+ #else
+ 		fwritemsg(rfd, msg, n + HFIXEDSZ);
+ #endif
  #ifdef NO_GLUE
  		if ((np != top) || (NAME(*top)[0] == '\0')) {
  #endif /*NO_GLUE*/
***************
*** 1782,1791 ****
  			if (gdp->d_rcode)
  			    continue;
  #endif
   			n = make_rr(fname, gdp, cp, sizeof(msg)-HFIXEDSZ, 0);
! 			if (n < 0)
  			    continue;
   			fwritemsg(rfp, msg, n + HFIXEDSZ);
   		    }
  #ifdef NO_GLUE
  		}
--- 2150,2167 ----
  			if (gdp->d_rcode)
  			    continue;
  #endif
+ #ifndef WINNT
   			n = make_rr(fname, gdp, cp, sizeof(msg)-HFIXEDSZ, 0);
! #else
!  			n = make_rr2(fname, gdp, cp, sizeof(msg)-HFIXEDSZ, 0, dnptrs_copy);
! #endif
!                if (n < 0)
  			    continue;
+ #ifndef WINNT
   			fwritemsg(rfp, msg, n + HFIXEDSZ);
+ #else
+  			fwritemsg(rfd, msg, n + HFIXEDSZ);
+ #endif
   		    }
  #ifdef NO_GLUE
  		}
***************
*** 1825,1833 ****
  		if (dp->d_rcode)
  			continue;
  #endif
! 		if ((n = make_rr(dname, dp, cp, sizeof(msg)-HFIXEDSZ, 0)) < 0)
  			continue;
! 		fwritemsg(rfp, msg, n + HFIXEDSZ);
  	}
  
  	/* Finally do non-delegated subdomains.  Delegated subdomains
--- 2201,2216 ----
  		if (dp->d_rcode)
  			continue;
  #endif
! #ifndef WINNT
!            if ((n = make_rr(dname, dp, cp, sizeof(msg)-HFIXEDSZ, 0)) < 0)
  			continue;
!             fwritemsg(rfp, msg, n + HFIXEDSZ);
! #else
! 		
!  		if ((n = make_rr2(dname, dp, cp, sizeof(msg)-HFIXEDSZ, 0, dnptrs_copy)) < 0)
!           	continue;
!           fwritemsg(rfd, msg, n + HFIXEDSZ);
! #endif
  	}
  
  	/* Finally do non-delegated subdomains.  Delegated subdomains
***************
*** 1872,1883 ****
--- 2255,2271 ----
  	while (npp < nppend) {
  		for (np = *npp++; np != NULL; np = np->n_next) {
  		    if (NAME(*np)[0] != '\0') { /* don't redo root domain */
+ #ifndef WINNT
  			doaxfr(np, rfp, top, class);
+ #else
+ 			doaxfr(np, rfd, top, class, dnptrs_copy);
+ #endif
  		    }
  		}
  	}
  	if (np == top)
  		dprintf(1, (ddt, "exit doaxfr()\n"));
+ 
  }
  
  static void
***************
*** 1885,1894 ****
  	struct qstream	*qsp;
  	struct namebuf	*np;
  	u_char		*soa;
! 	int		soalen;
! 	int		class;
  	const char	*dname;
  {
  	FILE *rfp;
  	int fdstat;
  	pid_t pid;
--- 2273,2283 ----
  	struct qstream	*qsp;
  	struct namebuf	*np;
  	u_char		*soa;
! 	int		     soalen;
! 	int		     class;
  	const char	*dname;
  {
+ #ifndef WINNT
  	FILE *rfp;
  	int fdstat;
  	pid_t pid;
***************
*** 1903,1911 ****
--- 2292,2307 ----
  #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
  	/* create a pipe to synchronize parent and child */
  	if (pipe(pipefd) != 0) {
  		syslog(LOG_NOTICE, "startxfr(%s -> %s) failing; pipe: %m",
***************
*** 1939,1945 ****
--- 2335,2422 ----
  		close(pipefd[1]);
  		return;
  	}
+ #else
+ 	if ((xfr_child = (struct ntxfr *)malloc(sizeof(struct ntxfr))) == NULL) {
+ 		syslog(LOG_ERR, "startxfr: malloc xfr_child: %m");
+ 		sqrm(qsp);
+ 		return;
+ 	}
+ 	if ((xfrbuf = (u_char *)malloc(BUFSIZ)) == NULL) {
+ 		syslog(LOG_ERR, "startxfr: malloc xfrbuf: %m");
+ 		sqrm(qsp);
+ 		return;
+ 	}
+ 
+      /* fill in the dnptrs also */
+    	{
+       u_char **edp = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
+       int len = (int)edp - (int)dnptrs;
+       memcpy(xfr_child->dnptrs,dnptrs,len);
+     }
+ 
+         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, CREATE_SUSPENDED, &id);
+ 	
+      if(xfr_thread_handle == NULL) {
+ 		syslog(LOG_NOTICE, "startxfr(%s -> %s) failing; CreateThread(): %m",
+ 		       dname, sin_ntoa(&qsp->s_from));
+ 		sqrm(qsp);
+ 	}
+ 	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 */
+         /* lgk this handle is being closed ok but there are still two open after
+            an outgoing transfer that I need to track down  adding sqrm should fix this
+            but we need to make sure child waits until this is done before continueing
+            as above in unix the pipes synchronize the two.. the child waits until parent
+            pipe is closed and then goes on... we can do this by makeing the child thread
+            wait for its startup */
+         dprintf(1, (ddt, "ns_req: resuming thread/closing thread handle  = %d id = %d\n",xfr_thread_handle,id));
+         ResumeThread(xfr_thread_handle);
+         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;
+ 	u_char **dnptrs_copy = pxfr_child->dnptrs;
+ 
+ 	pid = GetCurrentThreadId();
+ #endif /* WINNT */
  
+ #ifndef WINNT
  	/*
  	 * Child.
  	 *
***************
*** 1963,1984 ****
  		; /* nothing */
  	close(pipefd[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.
--- 2440,2476 ----
  		; /* nothing */
  	close(pipefd[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.
***************
*** 1998,2017 ****
  	 *	when we fill a 64K DNS/AXFR "message" rather than on each RR.
  	 *	(PVM@ISI gets credit for this idea.)
  	 */
  	fwritemsg(rfp, soa, soalen);
  	doaxfr(np, rfp, np, class);
  	fwritemsg(rfp, soa, soalen);
  	(void) fflush(rfp);
  #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
  	 * bug but it's harmless on systems that are not broken, so...
  	 */
  	setsockopt(qsp->s_rfd, SOL_SOCKET, SO_LINGER,
! 		   (char *)&ll, sizeof ll);
  	close(qsp->s_rfd);
  #endif
  	_exit(0);
  	/* NOTREACHED */
  }
  
--- 2490,2543 ----
  	 *	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,dnptrs_copy);
+ #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
  	 * bug but it's harmless on systems that are not broken, so...
  	 */
  	setsockopt(qsp->s_rfd, SOL_SOCKET, SO_LINGER,
!         	   (char *)&ll, sizeof ll);
! #ifdef WINNT
!         dprintf(1, (ddt, "closing xfer socket = %d threadid = %d\n",
! 			    qsp->s_rfd,(u_long)pid));
! 			    // lgk 10.96 nt not freeing the buf or the pxfr_child so do it
! 			    // lgk it looks like sqrm does this and by not doing it we
! 			    // are not unlinking which may be causing the crash/
  	close(qsp->s_rfd);
+      free(soa);
+      free(pxfr_child);
+      sqrm(qsp);
+ 
+         
+ 	
+ #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:\bind495p1/named/ns_resp.c m:\bind/named/ns_resp.c
*** m:\bind495p1/named/ns_resp.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/ns_resp.c	Thu Dec 19 02:27:52 1996
***************
*** 81,96 ****
   */
  
  #include <sys/types.h>
! #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"
  
--- 81,100 ----
   */
  
  #include <sys/types.h>
! #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"
  
***************
*** 255,261 ****
  	nsp[0] = NULL;
  	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;
  	}
--- 259,265 ----
  	nsp[0] = NULL;
  	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;
  	}
***************
*** 269,278 ****
  	/*
  	 * 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;
--- 273,282 ----
  	/*
  	 * 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;
***************
*** 471,479 ****
  			if (ns->d_nstime == 0)
  				t = rtrip;
  			else
! 				t = ns->d_nstime * ALPHA
  					+
! 				   (1 - ALPHA) * rtrip;
  			if (t > 65535)
  				t = 65535;
  			ns->d_nstime = (u_int16_t)t;
--- 475,483 ----
  			if (ns->d_nstime == 0)
  				t = rtrip;
  			else
! 				t = (u_long)(ns->d_nstime * ALPHA
  					+
! 				   (1 - ALPHA) * rtrip);
  			if (t > 65535)
  				t = 65535;
  			ns->d_nstime = (u_int16_t)t;
***************
*** 513,525 ****
  				continue;
  			if (qs->stime.tv_sec) {
  			    if (ns2->d_nstime == 0)
! 				t = (rtrip * BETA);
  			    else
! 				t = ns2->d_nstime * BETA
  					+
! 				   (1 - ALPHA) * rtrip;
  			} else
! 			    t = ns2->d_nstime * GAMMA;
  			if (t > 65535)
  				t = 65535;
  			ns2->d_nstime = (u_int16_t)t;
--- 517,529 ----
  				continue;
  			if (qs->stime.tv_sec) {
  			    if (ns2->d_nstime == 0)
! 				t = (u_long)(rtrip * BETA);
  			    else
! 				t = (u_long)(ns2->d_nstime * BETA
  					+
! 				   (1 - ALPHA) * rtrip);
  			} else
! 			    t = (u_long)(ns2->d_nstime * GAMMA);
  			if (t > 65535)
  				t = 65535;
  			ns2->d_nstime = (u_int16_t)t;
***************
*** 1024,1030 ****
  #endif
  	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;
--- 1028,1034 ----
  #endif
  	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;
***************
*** 1598,1604 ****
  		/* finally, we copy over the variable-length signature.
  		   Its size is the total data length, minus what we copied. */
  		n = dlen - (18 + n);
! 		if (n > (sizeof data) - (cp1 - (u_char *)data))
  			return (-1);  /* out of room! */
  		bcopy(cp, cp1, n);
  		cp += n;
--- 1602,1608 ----
  		/* finally, we copy over the variable-length signature.
  		   Its size is the total data length, minus what we copied. */
  		n = dlen - (18 + n);
! 		if ((unsigned)n > (sizeof data) - (cp1 - (u_char *)data))
  			return (-1);  /* out of room! */
  		bcopy(cp, cp1, n);
  		cp += n;
***************
*** 2489,2495 ****
  			 * used often.
  			 */
  			dp->d_ttl = tt.tv_sec
! 					+
  				0.95 * (int) (dp->d_ttl - tt.tv_sec);
  #endif
  		}
--- 2493,2500 ----
  			 * used often.
  			 */
  			dp->d_ttl = tt.tv_sec
! 					+ (int) (
! 				0.95 * (int) (dp->d_ttl - tt.tv_sec));
  				0.95 * (int) (dp->d_ttl - tt.tv_sec);
  #endif
  		}
***************
*** 2546,2551 ****
--- 2551,2568 ----
  			return (*lenp - buflen);
  		}
  
+ #ifdef MSN_LIMIT
+           if ((count >= 28) && (type == T_A) && (class = C_IN)) 
+             {
+               // normally we would put truncation bit here...
+               // don't put truncation bit in here as win95 cannot handle it
+               //hp->tc = 1;
+               dprintf(3, (ddt, "MSN_LIMIT is in effect ... limiting query response to 28 records\n"));
+               *countp = 28;
+               return (*lenp - buflen);
+           }
+    
+ #endif
  		cp += n;
  		buflen -= n;
  		count++;
***************
*** 2766,2772 ****
  		if (first) {
  			ttl = dp->d_ttl;
  			first = 0;
! 		} else if (ttl != dp->d_ttl) {
  			return(1);
  		}
  	}
--- 2783,2789 ----
  		if (first) {
  			ttl = dp->d_ttl;
  			first = 0;
! 		} else if (ttl != (unsigned)dp->d_ttl) {
  			return(1);
  		}
  	}
***************
*** 2786,2792 ****
  		if (first) {
  			ttl = dbp->db_dp->d_ttl;
  			first = 0;
! 		} else if (ttl != dbp->db_dp->d_ttl) {
  			return(0);
  		}
  		dbp = dbp->db_next;
--- 2803,2809 ----
  		if (first) {
  			ttl = dbp->db_dp->d_ttl;
  			first = 0;
! 		} else if (ttl != (unsigned)dbp->db_dp->d_ttl) {
  			return(0);
  		}
  		dbp = dbp->db_next;
diff --context --recurs m:\bind495p1/named/ns_sort.c m:\bind/named/ns_sort.c
*** m:\bind495p1/named/ns_sort.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/ns_sort.c	Tue Oct 08 13:07:00 1996
***************
*** 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:\bind495p1/named/ns_stats.c m:\bind/named/ns_stats.c
*** m:\bind495p1/named/ns_stats.c	Thu Dec 19 02:24:24 1996
--- m:\bind/named/ns_stats.c	Tue Oct 08 13:07:00 1996
***************
*** 64,79 ****
  /**************************************************************************/
  
  #include <sys/types.h>
! #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] = {
--- 64,83 ----
  /**************************************************************************/
  
  #include <sys/types.h>
! #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] = {
***************
*** 242,248 ****
--- 246,256 ----
  		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:\bind495p1/named/ns_udp.c m:\bind/named/ns_udp.c
*** m:\bind495p1/named/ns_udp.c	Thu Dec 19 02:24:24 1996
--- m:\bind/named/ns_udp.c	Tue Oct 08 13:07:00 1996
***************
*** 20,40 ****
   */
  
  #include <sys/types.h>
! #include <sys/param.h>
! #include <sys/stat.h>
! #include <sys/socket.h>
! #include <sys/file.h>
! 
! #include <netinet/in.h>
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! 
! #include <ctype.h>
  #include <errno.h>
  #include <stdio.h>
  #include <syslog.h>
- #include <netdb.h>
  #include <nlist.h>
  #include <resolv.h>
  
  #include "named.h"
--- 20,48 ----
   */
  
  #include <sys/types.h>
! #ifndef WINNT
! #include <sys/param.h>
! #endif
! #include <sys/stat.h>
! #ifndef WINNT
! #include <sys/socket.h>
! #include <sys/file.h>
! #include <netinet/in.h>
! #endif
! 
! #include <arpa/nameser.h>
! #include <arpa/inet.h>
! 
! #include <ctype.h>
  #include <errno.h>
  #include <stdio.h>
+ 
+ #ifndef WINNT
  #include <syslog.h>
  #include <nlist.h>
+ #endif
+ 
+ #include <netdb.h>
  #include <resolv.h>
  
  #include "named.h"
diff --context --recurs m:\bind495p1/named/ns_validate.c m:\bind/named/ns_validate.c
*** m:\bind495p1/named/ns_validate.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/ns_validate.c	Tue Oct 08 13:07:00 1996
***************
*** 8,22 ****
   */
  
  #include <sys/types.h>
! #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>
--- 8,24 ----
   */
  
  #include <sys/types.h>
! #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:\bind495p1/named/pathnames.h m:\bind/named/pathnames.h
*** m:\bind495p1/named/pathnames.h	Thu Dec 19 02:24:24 1996
--- m:\bind/named/pathnames.h	Tue Oct 08 13:07:02 1996
***************
*** 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 */
Only in m:\bind/named: resource.h
diff --context --recurs m:\bind495p1/named/storage.c m:\bind/named/storage.c
*** m:\bind495p1/named/storage.c	Thu Dec 19 02:24:23 1996
--- m:\bind/named/storage.c	Tue Oct 08 13:07:00 1996
***************
*** 54,61 ****
   */
  
  #include <sys/types.h>
! #include <sys/param.h>
! #include <syslog.h>
  
  #include "../conf/portability.h"
  #include "../conf/options.h"
--- 54,63 ----
   */
  
  #include <sys/types.h>
! #ifndef WINNT
! #include <sys/param.h>
! #include <syslog.h>
! #endif
  
  #include "../conf/portability.h"
  #include "../conf/options.h"
Only in m:\bind/named: strip.bat
Only in m:\bind/named: t3ansrespchanges
Only in m:\bind/named: versav.c
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/named: xfer95.mak
Only in m:\bind/named: xfer95.mdp
Only in m:\bind/named: xfer95.ncb
Only in m:\bind: nslookup.mak
Only in m:\bind: ntbind49326_vc22.zip
Only in m:\bind: ntbind49327.zip
Only in m:\bind: ntbind49332.zip
Only in m:\bind: ntbind493rel.zip
Only in m:\bind: ntbind493relo3.zip
Only in m:\bind: ntbind493relo5.zip
Only in m:\bind: ntbind493relp2.zip
Only in m:\bind: ntbind494arel.zip
Only in m:\bind: ntbind494beta2.zip
Only in m:\bind: ntbind494p1.zip
Only in m:\bind: ntbind494rel.zip
Only in m:\bind: ntbind494t3b2.zip
Only in m:\bind: ntbind494t4a.zip
Only in m:\bind: ntbind494t4b.zip
Only in m:\bind: ntbind494t5b.zip
Only in m:\bind: ntbind495p1.zip
Only in m:\bind: ntbind495rel.zip
Only in m:\bind: ntbind495relmsn.zip
Only in m:\bind: ntbind495t1.zip
Only in m:\bind: ntbind495t1a.zip
Only in m:\bind: ntbind495t1b.zip
Only in m:\bind: ntbind495t3a.zip
Only in m:\bind: ntbind495t3b.zip
Only in m:\bind: ntbind495t4b.zip
Only in m:\bind: ntbind495t5b+.zip
Only in m:\bind: ntbind495t5b.zip
Only in m:\bind: ntbind495t6b.zip
Only in m:\bind: ntbind495t6bo.zip
Only in m:\bind: ntbind495t6bold.zip
Only in m:\bind: ntdns49326bin_vc22.zip
Only in m:\bind: ntdns493relbin-nongui.zip
Only in m:\bind: ntdns493relbin.zip
Only in m:\bind: ntdns493relbino5.zip
Only in m:\bind: ntdns493relp2bin-nongui.zip
Only in m:\bind: ntdns493relp2bin.zip
Only in m:\bind: ntdns494arelbin-nongui.zip
Only in m:\bind: ntdns494arelbin.zip
Only in m:\bind: ntdns494beta2bin-nongui.zip
Only in m:\bind: ntdns494beta2bin.zip
Only in m:\bind: ntdns494p1bin-nongui.zip
Only in m:\bind: ntdns494p1bin.zip
Only in m:\bind: ntdns494relbin-nongui.zip
Only in m:\bind: ntdns494relbin.zip
Only in m:\bind: ntdns494t3b2bin.zip
Only in m:\bind: ntdns494t4abin-nongui.zip
Only in m:\bind: ntdns494t4abin.zip
Only in m:\bind: ntdns494t4bbin-nongui.zip
Only in m:\bind: ntdns494t4bbin.zip
Only in m:\bind: ntdns494t5bbin-nongui.zip
Only in m:\bind: ntdns494t5bbin.zip
Only in m:\bind: ntdns495p1-nongui.zip
Only in m:\bind: ntdns495p1bin.zip
Only in m:\bind: ntdns495rel-nongui.zip
Only in m:\bind: ntdns495relbin.zip
Only in m:\bind: ntdns495relmsnbin.zip
Only in m:\bind: ntdns495t1abin-nongui.zip
Only in m:\bind: ntdns495t1abin.zip
Only in m:\bind: ntdns495t1bbin-nongui.zip
Only in m:\bind: ntdns495t1bbin.zip
Only in m:\bind: ntdns495t1bin-nongui.zip
Only in m:\bind: ntdns495t1bin.zip
Only in m:\bind: ntdns495t3abin-nongui.zip
Only in m:\bind: ntdns495t3abin.zip
Only in m:\bind: ntdns495t3bbin-nongui.zip
Only in m:\bind: ntdns495t3bbin.zip
Only in m:\bind: ntdns495t4bbin-nongui.zip
Only in m:\bind: ntdns495t4bbin.zip
Only in m:\bind: ntdns495t5bbin-nongui.zip
Only in m:\bind: ntdns495t5bbin.zip
Only in m:\bind: ntdns495t6bbin-nongui.zip
Only in m:\bind: ntdns495t6bbin-nonguio.zip
Only in m:\bind: ntdns495t6bbin.zip
Only in m:\bind: out
Only in m:\bind: p1c1
Only in m:\bind: p1c2
Only in m:\bind: page1.html
Only in m:\bind: readme.nt
Only in m:\bind/res: WinRel
diff --context --recurs m:\bind495p1/res/base64.c m:\bind/res/base64.c
*** m:\bind495p1/res/base64.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/base64.c	Tue Oct 08 13:12:32 1996
***************
*** 41,55 ****
   */
  
  #include <sys/types.h>
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
  
! #include <ctype.h>
! #include <resolv.h>
! #include <stdio.h>
  
  #if defined(BSD) && (BSD >= 199103) && defined(AF_INET6)
  # include <stdlib.h>
--- 41,57 ----
   */
  
  #include <sys/types.h>
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
  
! #include <ctype.h>
! #include <resolv.h>
! #include <stdio.h>
  
  #if defined(BSD) && (BSD >= 199103) && defined(AF_INET6)
  # include <stdlib.h>
***************
*** 137,143 ****
  	size_t datalength = 0;
  	u_char input[3];
  	u_char output[4];
! 	int i;
  
  	while (2 < srclength) {
  		input[0] = *src++;
--- 139,145 ----
  	size_t datalength = 0;
  	u_char input[3];
  	u_char output[4];
! 	size_t i;
  
  	while (2 < srclength) {
  		input[0] = *src++;
***************
*** 224,230 ****
  		switch (state) {
  		case 0:
  			if (target) {
! 				if (tarindex >= targsize)
  					return (-1);
  				target[tarindex] = (pos - Base64) << 2;
  			}
--- 226,232 ----
  		switch (state) {
  		case 0:
  			if (target) {
! 				if ((size_t)tarindex >= targsize)
  					return (-1);
  				target[tarindex] = (pos - Base64) << 2;
  			}
***************
*** 232,238 ****
  			break;
  		case 1:
  			if (target) {
! 				if (tarindex + 1 >= targsize)
  					return (-1);
  				target[tarindex]   |=  (pos - Base64) >> 4;
  				target[tarindex+1]  = ((pos - Base64) & 0x0f)
--- 234,240 ----
  			break;
  		case 1:
  			if (target) {
! 				if ((size_t)(tarindex + 1) >= targsize)
  					return (-1);
  				target[tarindex]   |=  (pos - Base64) >> 4;
  				target[tarindex+1]  = ((pos - Base64) & 0x0f)
***************
*** 243,249 ****
  			break;
  		case 2:
  			if (target) {
! 				if (tarindex + 1 >= targsize)
  					return (-1);
  				target[tarindex]   |=  (pos - Base64) >> 2;
  				target[tarindex+1]  = ((pos - Base64) & 0x03)
--- 245,251 ----
  			break;
  		case 2:
  			if (target) {
! 				if ((size_t)(tarindex + 1) >= targsize)
  					return (-1);
  				target[tarindex]   |=  (pos - Base64) >> 2;
  				target[tarindex+1]  = ((pos - Base64) & 0x03)
***************
*** 254,260 ****
  			break;
  		case 3:
  			if (target) {
! 				if (tarindex >= targsize)
  					return (-1);
  				target[tarindex] |= (pos - Base64);
  			}
--- 256,262 ----
  			break;
  		case 3:
  			if (target) {
! 				if ((size_t)tarindex >= targsize)
  					return (-1);
  				target[tarindex] |= (pos - Base64);
  			}
diff --context --recurs m:\bind495p1/res/gethnamaddr.c m:\bind/res/gethnamaddr.c
*** m:\bind495p1/res/gethnamaddr.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/gethnamaddr.c	Tue Oct 08 13:12:32 1996
***************
*** 59,76 ****
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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
--- 59,80 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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
***************
*** 95,100 ****
--- 99,110 ----
  # define SPRINTF(x) ((size_t)sprintf x)
  #endif
  
+ #ifdef WINNT
+ extern char *pathhosts;
+ extern int res_paths_initialized;
+ extern init_res_paths();
+ #endif
+ 
  #define	MAXALIASES	35
  #define	MAXADDRS	35
  
***************
*** 110,115 ****
--- 120,126 ----
  static FILE *hostf = NULL;
  static int stayopen = 0;
  
+ int inet_pton();
  static void map_v4v6_address __P((const char *src, char *dst));
  static void map_v4v6_hostent __P((struct hostent *hp, char **bp, int *len));
  
***************
*** 133,139 ****
--- 144,152 ----
      char ac;
  } align;
  
+ #ifndef WINNT
  extern int h_errno;
+ #endif
  
  #ifdef DEBUG
  static void
***************
*** 145,151 ****
--- 158,169 ----
  		int save = errno;
  
  		printf(msg, num);
+ #ifndef WINNT
  		errno = save;
+ #else
+ 		WSASetLastError(save);
+ 		SetLastError(save);
+ #endif
  	}
  }
  #else
***************
*** 189,206 ****
  	 * 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);
  	}
  	n = dn_expand(answer->buf, eom, cp, bp, buflen);
  	if ((n < 0) || !(*name_ok)(bp)) {
  		h_errno = NO_RECOVERY;
  		return (NULL);
  	}
  	cp += n + QFIXEDSZ;
--- 207,232 ----
  	 * 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);
  	}
  	n = dn_expand(answer->buf, eom, cp, bp, buflen);
  	if ((n < 0) || !(*name_ok)(bp)) {
+ #ifndef WINNT
  		h_errno = NO_RECOVERY;
+ #else
+ 		WSASetLastError(NO_RECOVERY);
+ #endif
  		return (NULL);
  	}
  	cp += n + QFIXEDSZ;
***************
*** 299,305 ****
  		case T_PTR:
  			if (strcasecmp(tname, bp) != 0) {
  				syslog(LOG_NOTICE|LOG_AUTH,
! 				       AskedForGot, qname, bp);
  				cp += n;
  				continue;	/* XXX - had_error++ ? */
  			}
--- 325,331 ----
  		case T_PTR:
  			if (strcasecmp(tname, bp) != 0) {
  				syslog(LOG_NOTICE|LOG_AUTH,
! 				       (char *) AskedForGot, qname, bp);
  				cp += n;
  				continue;	/* XXX - had_error++ ? */
  			}
***************
*** 330,343 ****
  				buflen -= n;
  				map_v4v6_hostent(&host, &bp, &buflen);
  			}
! 			h_errno = NETDB_SUCCESS;
  			return (&host);
  #endif
  		case T_A:
  		case T_AAAA:
  			if (strcasecmp(host.h_name, bp) != 0) {
  				syslog(LOG_NOTICE|LOG_AUTH,
! 				       AskedForGot, host.h_name, bp);
  				cp += n;
  				continue;	/* XXX - had_error++ ? */
  			}
--- 356,373 ----
  				buflen -= n;
  				map_v4v6_hostent(&host, &bp, &buflen);
  			}
! #ifndef WINNT
!    		       h_errno = NETDB_SUCCESS;
! #else
!  		       WSASetLastError(NETDB_SUCCESS);
! #endif
  			return (&host);
  #endif
  		case T_A:
  		case T_AAAA:
  			if (strcasecmp(host.h_name, bp) != 0) {
  				syslog(LOG_NOTICE|LOG_AUTH,
! 				       (char *)AskedForGot, host.h_name, bp);
  				cp += n;
  				continue;	/* XXX - had_error++ ? */
  			}
***************
*** 402,434 ****
  		}
  		if (_res.options & RES_USE_INET6)
  			map_v4v6_hostent(&host, &bp, &buflen);
! 		h_errno = NETDB_SUCCESS;
  		return (&host);
  	}
   try_again:
  	h_errno = TRY_AGAIN;
  	return (NULL);
  }
  
  struct hostent *
- gethostbyname(name)
- 	const char *name;
- {
- 	struct hostent *hp;
- 
- 	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
- 		h_errno = NETDB_INTERNAL;
- 		return (NULL);
- 	}
- 	if (_res.options & RES_USE_INET6) {
- 		hp = gethostbyname2(name, AF_INET6);
- 		if (hp)
- 			return (hp);
- 	}
- 	return (gethostbyname2(name, AF_INET));
- }
- 
- struct hostent *
  gethostbyname2(name, af)
  	const char *name;
  	int af;
--- 432,454 ----
  		}
  		if (_res.options & RES_USE_INET6)
  			map_v4v6_hostent(&host, &bp, &buflen);
! #ifndef WINNT
!    		       h_errno = NETDB_SUCCESS;
! #else
!  		       WSASetLastError(NETDB_SUCCESS);
! #endif
  		return (&host);
  	}
   try_again:
+ #ifndef WINNT
  	h_errno = TRY_AGAIN;
+ #else
+         WSASetLastError(TRY_AGAIN);
+ #endif
  	return (NULL);
  }
  
  struct hostent *
  gethostbyname2(name, af)
  	const char *name;
  	int af;
***************
*** 440,446 ****
--- 460,470 ----
  	extern struct hostent *_gethtbyname2();
  
  	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ #ifndef WINNT
  		h_errno = NETDB_INTERNAL;
+ #else
+ 		WSASetLastError(NETDB_INTERNAL);
+ #endif
  		return (NULL);
  	}
  
***************
*** 454,461 ****
--- 478,490 ----
  		type = T_AAAA;
  		break;
  	default:
+ #ifndef WINNT
  		h_errno = NETDB_INTERNAL;
  		errno = EAFNOSUPPORT;
+ #else
+ 		WSASetLastError(NETDB_INTERNAL);
+ 		SetLastError(WSAEAFNOSUPPORT);
+ #endif
  		return (NULL);
  	}
  
***************
*** 485,491 ****
--- 514,524 ----
  				 * done a lookup.
  				 */
  				if (inet_pton(af, name, host_addr) <= 0) {
+ #ifndef WINNT
  					h_errno = HOST_NOT_FOUND;
+ #else
+                     WSASetLastError(HOST_NOT_FOUND);
+ #endif
  					return (NULL);
  				}
  				strncpy(hostbuf, name, MAXDNAME);
***************
*** 500,506 ****
  				host.h_addr_list = h_addr_ptrs;
  				if (_res.options & RES_USE_INET6)
  					map_v4v6_hostent(&host, &bp, &len);
! 				h_errno = NETDB_SUCCESS;
  				return (&host);
  			}
  			if (!isdigit(*cp) && *cp != '.') 
--- 533,543 ----
  				host.h_addr_list = h_addr_ptrs;
  				if (_res.options & RES_USE_INET6)
  					map_v4v6_hostent(&host, &bp, &len);
! #ifndef WINNT
!    		       h_errno = NETDB_SUCCESS;
! #else
!  		       WSASetLastError(NETDB_SUCCESS);
! #endif
  				return (&host);
  			}
  			if (!isdigit(*cp) && *cp != '.') 
***************
*** 517,523 ****
--- 554,564 ----
  				 * done a lookup.
  				 */
  				if (inet_pton(af, name, host_addr) <= 0) {
+ #ifndef WINNT
  					h_errno = HOST_NOT_FOUND;
+ #else
+                     WSASetLastError(HOST_NOT_FOUND);
+ #endif
  					return (NULL);
  				}
  				strncpy(hostbuf, name, MAXDNAME);
***************
*** 530,536 ****
  				h_addr_ptrs[0] = (char *)host_addr;
  				h_addr_ptrs[1] = NULL;
  				host.h_addr_list = h_addr_ptrs;
! 				h_errno = NETDB_SUCCESS;
  				return (&host);
  			}
  			if (!isxdigit(*cp) && *cp != ':' && *cp != '.') 
--- 571,581 ----
  				h_addr_ptrs[0] = (char *)host_addr;
  				h_addr_ptrs[1] = NULL;
  				host.h_addr_list = h_addr_ptrs;
! #ifndef WINNT
!    		       h_errno = NETDB_SUCCESS;
! #else
!  		       WSASetLastError(NETDB_SUCCESS);
! #endif
  				return (&host);
  			}
  			if (!isxdigit(*cp) && *cp != ':' && *cp != '.') 
***************
*** 547,553 ****
--- 592,628 ----
  }
  
  struct hostent *
+ #ifndef WINNT
+ gethostbyname(name)
+ #else
+ gethostbyname_nt(name)
+ #endif
+ 	const char *name;
+ {
+ 	struct hostent *hp;
+ 
+ 	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ #ifndef WINNT
+ 		h_errno = NETDB_INTERNAL;
+ #else
+ 		WSASetLastError(NETDB_INTERNAL);
+ #endif
+ 		return (NULL);
+ 	}
+ 	if (_res.options & RES_USE_INET6) {
+ 		hp = gethostbyname2(name, AF_INET6);
+ 		if (hp)
+ 			return (hp);
+ 	}
+ 	return (gethostbyname2(name, AF_INET));
+ }
+ 
+ struct hostent *
+ #ifndef WINNT
  gethostbyaddr(addr, len, af)
+ #else
+ gethostbyaddr_nt(addr, len, af)
+ #endif
  	const char *addr;	/* XXX should have been def'd as u_char! */
  	int len, af;
  {
***************
*** 564,574 ****
  	u_long old_options;
  	char hname2[MAXDNAME+1];
  #endif /*SUNSECURITY*/
! 	extern struct hostent *_gethtbyaddr();
  	
  	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
  		h_errno = NETDB_INTERNAL;
! 		return (NULL);
  	}
  	if (af == AF_INET6 && len == IN6ADDRSZ &&
  	    (!bcmp(uaddr, mapped, sizeof mapped) ||
--- 639,653 ----
  	u_long old_options;
  	char hname2[MAXDNAME+1];
  #endif /*SUNSECURITY*/
! 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 (0);
  	}
  	if (af == AF_INET6 && len == IN6ADDRSZ &&
  	    (!bcmp(uaddr, mapped, sizeof mapped) ||
***************
*** 587,600 ****
  		size = IN6ADDRSZ;
  		break;
  	default:
  		errno = EAFNOSUPPORT;
  		h_errno = NETDB_INTERNAL;
! 		return (NULL);
  	}
  	if (size != len) {
  		errno = EINVAL;
  		h_errno = NETDB_INTERNAL;
! 		return (NULL);
  	}
  	switch (af) {
  	case AF_INET:
--- 666,689 ----
  		size = IN6ADDRSZ;
  		break;
  	default:
+ #ifndef WINNT
  		errno = EAFNOSUPPORT;
  		h_errno = NETDB_INTERNAL;
! #else
!  		SetLastError(WSAEAFNOSUPPORT);
! 		WSASetLastError(NETDB_INTERNAL);
! #endif
! 		return (0);
  	}
  	if (size != len) {
+ #ifndef WINNT
  		errno = EINVAL;
  		h_errno = NETDB_INTERNAL;
! #else
!  		SetLastError(WSAEINVAL);
! 		WSASetLastError(NETDB_INTERNAL);
! #endif
! 		return (0);
  	}
  	switch (af) {
  	case AF_INET:
***************
*** 621,630 ****
  		dprintf("res_query failed (%d)\n", n);
  		if (errno == ECONNREFUSED)
  			return (_gethtbyaddr(addr, len, af));
! 		return (NULL);
  	}
  	if (!(hp = getanswer(&buf, n, qbuf, T_PTR)))
! 		return (NULL);	/* h_errno was set by getanswer() */
  #ifdef SUNSECURITY
  	if (af == AF_INET) {
  	    /*
--- 710,719 ----
  		dprintf("res_query failed (%d)\n", n);
  		if (errno == ECONNREFUSED)
  			return (_gethtbyaddr(addr, len, af));
! 		return (0);
  	}
  	if (!(hp = getanswer(&buf, n, qbuf, T_PTR)))
! 		return (0);	/* h_errno was set by getanswer() */
  #ifdef SUNSECURITY
  	if (af == AF_INET) {
  	    /*
***************
*** 636,647 ****
  	    old_options = _res.options;
  	    _res.options &= ~RES_DNSRCH;
  	    _res.options |= RES_DEFNAMES;
! 	    if (!(rhp = gethostbyname(hname2))) {
  		syslog(LOG_NOTICE|LOG_AUTH,
  		       "gethostbyaddr: No A record for %s (verifying [%s])",
  		       hname2, inet_ntoa(*((struct in_addr *)addr)));
  		_res.options = old_options;
! 		h_errno = HOST_NOT_FOUND;
  		return (NULL);
  	    }
  	    _res.options = old_options;
--- 725,740 ----
  	    old_options = _res.options;
  	    _res.options &= ~RES_DNSRCH;
  	    _res.options |= RES_DEFNAMES;
! 	    if (!(rhp = gethostbyname_nt(hname2))) {
  		syslog(LOG_NOTICE|LOG_AUTH,
  		       "gethostbyaddr: No A record for %s (verifying [%s])",
  		       hname2, inet_ntoa(*((struct in_addr *)addr)));
  		_res.options = old_options;
! #ifndef WINNT
! 					h_errno = HOST_NOT_FOUND;
! #else
!                     WSASetLastError(HOST_NOT_FOUND);
! #endif
  		return (NULL);
  	    }
  	    _res.options = old_options;
***************
*** 652,658 ****
  		syslog(LOG_NOTICE|LOG_AUTH,
  		       "gethostbyaddr: A record of %s != PTR record [%s]",
  		       hname2, inet_ntoa(*((struct in_addr *)addr)));
! 		h_errno = HOST_NOT_FOUND;
  		return (NULL);
  	    }
  	}
--- 745,755 ----
  		syslog(LOG_NOTICE|LOG_AUTH,
  		       "gethostbyaddr: A record of %s != PTR record [%s]",
  		       hname2, inet_ntoa(*((struct in_addr *)addr)));
! #ifndef WINNT
! 					h_errno = HOST_NOT_FOUND;
! #else
!                     WSASetLastError(HOST_NOT_FOUND);
! #endif
  		return (NULL);
  	    }
  	}
***************
*** 667,673 ****
  		hp->h_addrtype = AF_INET6;
  		hp->h_length = IN6ADDRSZ;
  	}
! 	h_errno = NETDB_SUCCESS;
  	return (hp);
  }
  
--- 764,774 ----
  		hp->h_addrtype = AF_INET6;
  		hp->h_length = IN6ADDRSZ;
  	}
! #ifndef WINNT
!    		       h_errno = NETDB_SUCCESS;
! #else
!  		       WSASetLastError(NETDB_SUCCESS);
! #endif
  	return (hp);
  }
  
***************
*** 675,682 ****
--- 776,793 ----
  _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;
***************
*** 698,710 ****
  	register char *cp, **q;
  	int af, len;
  
! 	if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) {
  		h_errno = NETDB_INTERNAL;
  		return (NULL);
  	}
   again:
  	if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) {
! 		h_errno = HOST_NOT_FOUND;
  		return (NULL);
  	}
  	if (*p == '#')
--- 809,837 ----
  	register char *cp, **q;
  	int af, len;
  
! #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 == '#')
***************
*** 759,765 ****
  
  		map_v4v6_hostent(&host, &bp, &buflen);
  	}
! 	h_errno = NETDB_SUCCESS;
  	return (&host);
  }
  
--- 886,896 ----
  
  		map_v4v6_hostent(&host, &bp, &buflen);
  	}
! #ifndef WINNT
!    		       h_errno = NETDB_SUCCESS;
! #else
!  		       WSASetLastError(NETDB_SUCCESS);
! #endif
  	return (&host);
  }
  
diff --context --recurs m:\bind495p1/res/getnetbyaddr.c m:\bind/res/getnetbyaddr.c
*** m:\bind495p1/res/getnetbyaddr.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/getnetbyaddr.c	Tue Oct 08 13:12:32 1996
***************
*** 37,42 ****
--- 37,45 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <netdb.h>
+ #ifdef WINNT
+ #include "../conf/portability.h"
+ #endif
  
  extern int _net_stayopen;
  
diff --context --recurs m:\bind495p1/res/getnetbyname.c m:\bind/res/getnetbyname.c
*** m:\bind495p1/res/getnetbyname.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/getnetbyname.c	Tue Oct 08 13:12:32 1996
***************
*** 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:\bind495p1/res/getnetent.c m:\bind/res/getnetent.c
*** m:\bind495p1/res/getnetent.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/getnetent.c	Tue Oct 08 13:12:32 1996
***************
*** 47,67 ****
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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;
--- 47,77 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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;
***************
*** 95,102 ****
--- 105,120 ----
  	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;
***************
*** 119,125 ****
--- 137,151 ----
  	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:\bind495p1/res/getnetnamadr.c m:\bind/res/getnetnamadr.c
*** m:\bind495p1/res/getnetnamadr.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/getnetnamadr.c	Tue Oct 08 13:12:32 1996
***************
*** 45,70 ****
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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
--- 45,76 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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
***************
*** 120,135 ****
  	 */
  	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)
--- 126,149 ----
  	 */
  	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)
***************
*** 197,203 ****
--- 211,221 ----
  		net_entry.n_aliases++;
  		return (&net_entry);
  	}
+ #ifndef WINNT
  	h_errno = TRY_AGAIN;
+ #else
+ 	WSASetLastError(TRY_AGAIN);
+ #endif
  	return (NULL);
  }
  
***************
*** 267,273 ****
--- 285,295 ----
  	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:\bind495p1/res/herror.c m:\bind/res/herror.c
*** m:\bind495p1/res/herror.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/herror.c	Tue Oct 08 13:12:32 1996
***************
*** 59,73 ****
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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)",
--- 59,75 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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)",
***************
*** 78,84 ****
--- 80,88 ----
  };
  int	h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
  
+ #ifndef WINNT
  extern int	h_errno;
+ #endif
  
  /*
   * herror --
***************
*** 90,95 ****
--- 94,102 ----
  {
  	struct iovec iov[4];
  	register struct iovec *v = iov;
+ #ifdef WINNT
+ 	char err[50];
+ #endif
  
  	if (s && *s) {
  		v->iov_base = (char *)s;
***************
*** 99,105 ****
--- 106,118 ----
  		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";
***************
*** 107,112 ****
--- 120,126 ----
  	writev(STDERR_FILENO, iov, (v - iov) + 1);
  }
  
+ #ifndef WINNT
  const char *
  hstrerror(err)
  	int err;
***************
*** 117,119 ****
--- 131,134 ----
  		return (h_errlist[err]);
  	return ("Unknown resolver error");
  }
+ #endif
diff --context --recurs m:\bind495p1/res/hostnamelen.c m:\bind/res/hostnamelen.c
*** m:\bind495p1/res/hostnamelen.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/hostnamelen.c	Tue Oct 08 13:12:32 1996
***************
*** 57,65 ****
  static char rcsid[] = "$Id: hostnamelen.c,v 8.2 1995/08/22 05:01:47 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <sys/types.h>
! #include <netinet/in.h>
  #include <arpa/nameser.h>
  #include <resolv.h>
  
--- 57,68 ----
  static char rcsid[] = "$Id: hostnamelen.c,v 8.2 1995/08/22 05:01:47 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/param.h>
! #include <sys/types.h>
! #include <netinet/in.h>
! #endif
! 
  #include <arpa/nameser.h>
  #include <resolv.h>
  
diff --context --recurs m:\bind495p1/res/inet_addr.c m:\bind/res/inet_addr.c
*** m:\bind495p1/res/inet_addr.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/inet_addr.c	Tue Oct 08 13:12:32 1996
***************
*** 59,74 ****
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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
--- 59,79 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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
***************
*** 81,86 ****
--- 86,92 ----
  		return (val.s_addr);
  	return (INADDR_NONE);
  }
+ #endif  /* NEED_INETADDR */
  
  /* 
   * Check whether "cp" is a valid ascii representation
diff --context --recurs m:\bind495p1/res/inet_net_ntop.c m:\bind/res/inet_net_ntop.c
*** m:\bind495p1/res/inet_net_ntop.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/inet_net_ntop.c	Fri Nov 22 15:47:26 1996
***************
*** 20,35 ****
  #endif
  
  #include <sys/types.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
  
! #include <errno.h>
! #include <stdio.h>
! #include <string.h>
! #include <stdlib.h>
  
! #ifdef SPRINTF_CHAR
  # define SPRINTF(x) strlen(sprintf/**/x)
  #else
  # define SPRINTF(x) ((size_t)sprintf x)
--- 20,37 ----
  #endif
  
  #include <sys/types.h>
! #ifndef WINNT
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/inet.h>
  
! #include <errno.h>
! #include <stdio.h>
! #include <string.h>
! #include <stdlib.h>
  
! #ifdef SPRINTF_CHAR
  # define SPRINTF(x) strlen(sprintf/**/x)
  #else
  # define SPRINTF(x) ((size_t)sprintf x)
***************
*** 60,67 ****
  	case AF_INET:
  		return (inet_net_ntop_ipv4(src, bits, dst, size));
  	default:
! 		errno = EAFNOSUPPORT;
! 		return (NULL);
  	}
  }
  
--- 62,78 ----
  	case AF_INET:
  		return (inet_net_ntop_ipv4(src, bits, dst, size));
  	default:
! 
! #ifndef WINNT
! 	errno = EAFNOSUPPORT;
!      return (NULL);
! #else
! 
! 	WSASetLastError(WSAEAFNOSUPPORT);
! 	SetLastError(WSAEAFNOSUPPORT);
!      return (NULL);
! #endif
! 
  	}
  }
  
***************
*** 134,139 ****
  	return (odst);
  
   emsgsize:
! 	errno = EMSGSIZE;
! 	return (NULL);
  }
--- 145,159 ----
  	return (odst);
  
   emsgsize:
! 
!  #ifndef WINNT
!      errno = EMSGSIZE;
!      return (NULL);
! #else
!      WSASetLastError(WSAEMSGSIZE);
!      SetLastError(WSAEMSGSIZE);
!      return (NULL);
! #endif
! 
! 
  }
diff --context --recurs m:\bind495p1/res/inet_net_pton.c m:\bind/res/inet_net_pton.c
*** m:\bind495p1/res/inet_net_pton.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/inet_net_pton.c	Mon Nov 11 16:01:34 1996
***************
*** 20,35 ****
  #endif
  
  #include <sys/types.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
  
! #include <assert.h>
! #include <ctype.h>
! #include <errno.h>
! #include <stdio.h>
! #include <string.h>
! #include <stdlib.h>
  
  #ifdef SPRINTF_CHAR
  # define SPRINTF(x) strlen(sprintf/**/x)
--- 20,37 ----
  #endif
  
  #include <sys/types.h>
! #ifndef WINNT
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/inet.h>
  
! #include <assert.h>
! #include <ctype.h>
! #include <errno.h>
! #include <stdio.h>
! #include <string.h>
! #include <stdlib.h>
  
  #ifdef SPRINTF_CHAR
  # define SPRINTF(x) strlen(sprintf/**/x)
***************
*** 64,71 ****
  	case AF_INET:
  		return (inet_net_pton_ipv4(src, dst, size));
  	default:
! 		errno = EAFNOSUPPORT;
! 		return (-1);
  	}
  }
  
--- 66,81 ----
  	case AF_INET:
  		return (inet_net_pton_ipv4(src, dst, size));
  	default:
! #ifndef WINNT
! 	errno = EAFNOSUPPORT;
!      return (-1);
! #else
! 
! 	WSASetLastError(WSAEAFNOSUPPORT);
! 	SetLastError(WSAEAFNOSUPPORT);
!      return (-1);
! #endif
! 		
  	}
  }
  
***************
*** 198,207 ****
  	return (bits);
  
   enoent:
! 	errno = ENOENT;
! 	return (-1);
  
   emsgsize:
  	errno = EMSGSIZE;
! 	return (-1);
  }
--- 208,231 ----
  	return (bits);
  
   enoent:
! 
! #ifndef WINNT
! 	errno = ENOENT
!      return (-1);
! #else
!      SetLastError(ENOENT);
!      return (-1);
! #endif
  
   emsgsize:
+ 
+ #ifndef WINNT
  	errno = EMSGSIZE;
!      return (-1);
! #else
!      SetLastError(WSAEMSGSIZE);
!      WSASetLastError(WSAEMSGSIZE);
!      return (-1);
! #endif
! 
  }
diff --context --recurs m:\bind495p1/res/inet_neta.c m:\bind/res/inet_neta.c
*** m:\bind495p1/res/inet_neta.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/inet_neta.c	Tue Oct 08 13:12:32 1996
***************
*** 20,35 ****
  #endif
  
  #include <sys/types.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
  
! #include <errno.h>
! #include <stdio.h>
  
! #ifdef SPRINTF_CHAR
! # define SPRINTF(x) strlen(sprintf/**/x)
! #else
  # define SPRINTF(x) ((size_t)sprintf x)
  #endif
  
--- 20,37 ----
  #endif
  
  #include <sys/types.h>
! #ifndef WINNT
! #include <sys/socket.h>
! #include <netinet/in.h>
! #endif
! #include <arpa/inet.h>
  
! #include <errno.h>
! #include <stdio.h>
  
! #ifdef SPRINTF_CHAR
! # define SPRINTF(x) strlen(sprintf/**/x)
! #else
  # define SPRINTF(x) ((size_t)sprintf x)
  #endif
  
***************
*** 54,60 ****
  	char *tp;
  
  	while (src & 0xffffffff) {
! 		u_char b = (src & 0xff000000) >> 24;
  
  		src <<= 8;
  		if (b) {
--- 56,62 ----
  	char *tp;
  
  	while (src & 0xffffffff) {
! 		u_char b = (u_char)((src & 0xff000000) >> 24);
  
  		src <<= 8;
  		if (b) {
***************
*** 77,82 ****
  	return (odst);
  
   emsgsize:
! 	errno = EMSGSIZE;
! 	return (NULL);
  }
--- 79,92 ----
  	return (odst);
  
   emsgsize:
! 
!  #ifndef WINNT
!      errno = EMSGSIZE;
!      return (NULL);
! #else
!      WSASetLastError(WSAEMSGSIZE);
!      SetLastError(WSAEMSGSIZE);
!      return (NULL);
! #endif
! 
  }
diff --context --recurs m:\bind495p1/res/inet_ntop.c m:\bind/res/inet_ntop.c
*** m:\bind495p1/res/inet_ntop.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/inet_ntop.c	Tue Oct 08 13:12:34 1996
***************
*** 18,33 ****
  static char rcsid[] = "$Id: inet_ntop.c,v 8.7 1996/08/05 08:41:18 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <sys/types.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
! #include <string.h>
! #include <errno.h>
! #include <stdio.h>
! #include "../conf/portability.h"
  
  #ifdef SPRINTF_CHAR
  # define SPRINTF(x) strlen(sprintf/**/x)
--- 18,35 ----
  static char rcsid[] = "$Id: inet_ntop.c,v 8.7 1996/08/05 08:41:18 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #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>
! #include <string.h>
! #include <errno.h>
! #include <stdio.h>
! #include "../conf/portability.h"
  
  #ifdef SPRINTF_CHAR
  # define SPRINTF(x) strlen(sprintf/**/x)
***************
*** 64,70 ****
--- 66,77 ----
  	case AF_INET6:
  		return (inet_ntop6(src, dst, size));
  	default:
+ #ifndef WINNT
  		errno = EAFNOSUPPORT;
+ #else
+ 		SetLastError(WSAEAFNOSUPPORT);
+ 		WSASetLastError(WSAEAFNOSUPPORT);
+ #endif
  		return (NULL);
  	}
  	/* NOTREACHED */
***************
*** 90,97 ****
  	static const char fmt[] = "%u.%u.%u.%u";
  	char tmp[sizeof "255.255.255.255"];
  
! 	if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > size) {
  		errno = ENOSPC;
  		return (NULL);
  	}
  	strcpy(dst, tmp);
--- 97,109 ----
  	static const char fmt[] = "%u.%u.%u.%u";
  	char tmp[sizeof "255.255.255.255"];
  
! 	if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) > (int)size) {
! #ifndef WINNT
  		errno = ENOSPC;
+ #else
+ 		SetLastError(ENOSPC);
+ 		WSASetLastError(ENOSPC);
+ #endif
  		return (NULL);
  	}
  	strcpy(dst, tmp);
***************
*** 187,193 ****
--- 199,210 ----
  	 * Check for overflow, copy, and we're done.
  	 */
  	if ((size_t)(tp - tmp) > size) {
+ #ifndef WINNT
  		errno = ENOSPC;
+ #else
+ 		SetLastError(ENOSPC);
+ 		WSASetLastError(ENOSPC);
+ #endif
  		return (NULL);
  	}
  	strcpy(dst, tmp);
diff --context --recurs m:\bind495p1/res/inet_pton.c m:\bind/res/inet_pton.c
*** m:\bind495p1/res/inet_pton.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/inet_pton.c	Tue Oct 08 13:12:34 1996
***************
*** 18,32 ****
  static char rcsid[] = "$Id: inet_pton.c,v 8.7 1996/08/05 08:31:35 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <sys/types.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
! #include <string.h>
! #include <errno.h>
! #include "../conf/portability.h"
  
  /*
   * WARNING: Don't even consider trying to compile this on a system where
--- 18,34 ----
  static char rcsid[] = "$Id: inet_pton.c,v 8.7 1996/08/05 08:31:35 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #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>
! #include <string.h>
! #include <errno.h>
! #include "../conf/portability.h"
  
  /*
   * WARNING: Don't even consider trying to compile this on a system where
***************
*** 59,65 ****
--- 61,71 ----
  	case AF_INET6:
  		return (inet_pton6(src, dst));
  	default:
+ #ifndef WINNT
  		errno = EAFNOSUPPORT;
+ #else
+         SetLastError(WSAEAFNOSUPPORT);
+ #endif
  		return (-1);
  	}
  	/* NOTREACHED */
diff --context --recurs m:\bind495p1/res/nsap_addr.c m:\bind/res/nsap_addr.c
*** m:\bind495p1/res/nsap_addr.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/nsap_addr.c	Tue Oct 08 13:12:34 1996
***************
*** 19,33 ****
  static char rcsid[] = "$Id: nsap_addr.c,v 8.3 1996/08/05 08:31:35 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/types.h>
! #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
--- 19,35 ----
  static char rcsid[] = "$Id: nsap_addr.c,v 8.3 1996/08/05 08:31:35 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #ifndef WINNT
! #include <sys/types.h>
! #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
***************
*** 49,55 ****
  inet_nsap_addr(ascii, binary, maxlen)
  	const char *ascii;
  	u_char *binary;
! 	int maxlen;
  {
  	register u_char c, nib;
  	u_int len = 0;
--- 51,57 ----
  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:\bind495p1/res/res_comp.c m:\bind/res/res_comp.c
*** m:\bind495p1/res/res_comp.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/res_comp.c	Thu Dec 19 02:32:41 1996
***************
*** 59,66 ****
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #include <sys/param.h>
! #include <netinet/in.h>
  #include <arpa/nameser.h>
  
  #include <stdio.h>
--- 59,68 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #ifndef WINNT
! #include <sys/param.h>
! #include <netinet/in.h>
! #endif
  #include <arpa/nameser.h>
  
  #include <stdio.h>
diff --context --recurs m:\bind495p1/res/res_data.c m:\bind/res/res_data.c
*** m:\bind495p1/res/res_data.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/res_data.c	Tue Oct 08 13:12:34 1996
***************
*** 58,67 ****
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #include <sys/param.h>
! #include <sys/socket.h>
! #include <sys/time.h>
! #include <netinet/in.h>
  #include <arpa/inet.h>
  #include <arpa/nameser.h>
  
--- 58,69 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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:\bind495p1/res/res_debug.c m:\bind/res/res_debug.c
*** m:\bind495p1/res/res_debug.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/res_debug.c	Thu Dec 19 02:32:45 1996
***************
*** 80,95 ****
  static char rcsid[] = "$Id: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #include <sys/param.h>
! #include <sys/types.h>
! #include <sys/socket.h>
! #include <netinet/in.h>
! #include <arpa/inet.h>
! #include <arpa/nameser.h>
  
! #include <ctype.h>
! #include <netdb.h>
! #include <resolv.h>
  #include <stdio.h>
  #include <time.h>
  
--- 80,97 ----
  static char rcsid[] = "$Id: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #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>
  
! #include <ctype.h>
! #include <netdb.h>
! #include <resolv.h>
  #include <stdio.h>
  #include <time.h>
  
***************
*** 106,111 ****
--- 108,115 ----
  
  extern const char *_res_opcodes[];
  extern const char *_res_resultcodes[];
+ char * inet_nsap_ntoa();
+ const char * inet_ntop();
  
  /* XXX: we should use getservbyport() instead. */
  static const char *
***************
*** 203,209 ****
  	 * Print answer records.
  	 */
  	sflag = (_res.pfcode & pflag);
! 	if (n = ntohs(cnt)) {
  		if ((!_res.pfcode) ||
  		    ((sflag) && (_res.pfcode & RES_PRF_HEAD1)))
  			fprintf(file, hs);
--- 207,213 ----
  	 * 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);
***************
*** 300,306 ****
  		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))
--- 304,310 ----
  		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))
***************
*** 325,334 ****
  			fprintf(file, " cd");
  	}
  	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))) {
--- 329,338 ----
  			fprintf(file, " cd");
  	}
  	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))) {
***************
*** 337,343 ****
  	/*
  	 * Print question records.
  	 */
! 	if (n = ntohs(hp->qdcount)) {
  		if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
  			fprintf(file, ";; QUESTIONS:\n");
  		while (--n >= 0) {
--- 341,347 ----
  	/*
  	 * 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) {
***************
*** 496,502 ****
--- 500,510 ----
  	char base64_key[MAX_KEY_BASE64];
  
  	if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ #ifndef WINNT
  		h_errno = NETDB_INTERNAL;
+ #else
+ 		WSASetLastError(NETDB_INTERNAL);
+ #endif
  		return (NULL);
  	}
  	cp = __p_fqnname(cp, msg, MAXCDNAME, rrname, sizeof rrname);
***************
*** 805,811 ****
  				n, c);
  		/* orig ttl */
  		n = _getlong((u_char*)cp);
! 		if (n != tmpttl)
  			fprintf(file, " %u", n);
  		cp += INT32SZ;
  		/* sig expire */
--- 813,819 ----
  				n, c);
  		/* orig ttl */
  		n = _getlong((u_char*)cp);
! 		if ((u_int32_t)n != tmpttl)
  			fprintf(file, " %u", n);
  		cp += INT32SZ;
  		/* sig expire */
***************
*** 1418,1424 ****
  	longval = (templ - ((unsigned)1<<31));
  
  	GETLONG(templ, cp);
! 	if (templ < referencealt) { /* below WGS 84 spheroid */
  		altval = referencealt - templ;
  		altsign = -1;
  	} else {
--- 1426,1432 ----
  	longval = (templ - ((unsigned)1<<31));
  
  	GETLONG(templ, cp);
! 	if (templ < (u_int32_t)referencealt) { /* below WGS 84 spheroid */
  		altval = referencealt - templ;
  		altsign = -1;
  	} else {
diff --context --recurs m:\bind495p1/res/res_init.c m:\bind/res/res_init.c
*** m:\bind495p1/res/res_init.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/res_init.c	Tue Oct 08 13:12:34 1996
***************
*** 59,82 ****
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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)
--- 59,92 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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)
***************
*** 171,176 ****
--- 181,198 ----
  	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,
***************
*** 257,263 ****
--- 279,293 ----
  #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:\bind495p1/res/res_mkquery.c m:\bind/res/res_mkquery.c
*** m:\bind495p1/res/res_mkquery.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/res_mkquery.c	Tue Oct 08 13:12:34 1996
***************
*** 59,74 ****
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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
  
--- 59,76 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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
  
***************
*** 97,103 ****
--- 99,109 ----
  	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:\bind495p1/res/res_query.c m:\bind/res/res_query.c
*** m:\bind495p1/res/res_query.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/res_query.c	Tue Oct 08 13:12:34 1996
***************
*** 59,74 ****
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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>
--- 59,76 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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>
***************
*** 87,93 ****
--- 89,97 ----
  #endif
  
  const char *hostalias __P((const char *));
+ #ifndef WINNT
  int h_errno;
+ #endif
  
  /*
   * Formulate a normal query, send, and await answer.
***************
*** 113,119 ****
--- 117,127 ----
  	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
***************
*** 128,134 ****
--- 136,146 ----
  		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);
***************
*** 137,167 ****
  		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);
--- 149,199 ----
  		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);
***************
*** 189,199 ****
--- 221,240 ----
  	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);
+ 	SetLastError(0);
+ #endif
  	dots = 0;
  	for (cp = name; *cp; cp++)
  		dots += (*cp == '.');
***************
*** 216,222 ****
--- 257,267 ----
  		ret = res_querydomain(name, NULL, class, type, answer, anslen);
  		if (ret > 0)
  			return (ret);
+ #ifndef WINNT
  		saved_herrno = h_errno;
+ #else
+                 saved_herrno = WSAGetLastError();
+ #endif
  		tried_as_is++;
  	}
  
***************
*** 253,259 ****
--- 298,308 ----
  			 * fully-qualified.
  			 */
  			if (errno == ECONNREFUSED) {
+ #ifndef WINNT
  				h_errno = TRY_AGAIN;
+ #else
+ 				WSASetLastError(TRY_AGAIN);
+ #endif
  				return (-1);
  			}
  
***************
*** 301,312 ****
--- 350,370 ----
  	 * 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);
  }
  
***************
*** 326,332 ****
--- 384,394 ----
  	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:\bind495p1/res/res_send.c m:\bind/res/res_send.c
*** m:\bind495p1/res/res_send.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/res_send.c	Tue Oct 08 13:12:34 1996
***************
*** 70,85 ****
   */
  
  #include <sys/types.h>
! #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)
--- 70,87 ----
   */
  
  #include <sys/types.h>
! #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)
***************
*** 94,100 ****
--- 96,107 ----
  # include <../conf/options.h>
  #endif
  
+ #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? */
  
***************
*** 142,148 ****
--- 149,160 ----
  			ntohs(address.sin_port),
  			strerror(error));
  	}
+ #ifndef WINNT
  	errno = save;
+ #else
+ 	WSASetLastError(save);
+ 	SetLastError(save);
+ #endif
      }
      static void
      Perror(file, string, error)
***************
*** 156,162 ****
--- 168,178 ----
  		fprintf(file, "res_send: %s: %s\n",
  			string, strerror(error));
  	}
+ #ifndef WINNT
  	errno = save;
+ #else
+  	SetLastError(save);
+ #endif
      }
  #endif
  
***************
*** 228,234 ****
  	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];
***************
*** 265,273 ****
  	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];
***************
*** 297,302 ****
--- 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. */
***************
*** 361,367 ****
  			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.
***************
*** 373,384 ****
--- 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
+ 				SetLastError(0);
+ #endif
  				if (connect(s, (struct sockaddr *)nsap,
  					    sizeof(struct sockaddr)) < 0) {
  					terrno = errno;
***************
*** 411,417 ****
--- 448,460 ----
  read_len:
  			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 ****
--- 491,503 ----
  				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 ****
--- 520,532 ----
  					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;
***************
*** 500,510 ****
  			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
--- 555,573 ----
  			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
***************
*** 529,534 ****
--- 592,598 ----
  			 * 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
***************
*** 554,559 ****
--- 618,624 ----
  					goto next_ns;
  				}
  			} else {
+ #endif /* WINNT */
  				/*
  				 * Disconnect if we want to listen
  				 * for responses from more than one server.
***************
*** 571,577 ****
--- 636,646 ----
  						       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);
***************
*** 579,585 ****
--- 648,658 ----
  					       (stdout, ";; new DG socket\n"))
  #endif
  					connected = 0;
+ #ifndef WINNT
  					errno = 0;
+ #else
+ 					SetLastError(0);
+ #endif
  				}
  				if (sendto(s, (char*)buf, buflen, 0,
  					   (struct sockaddr *)nsap,
***************
*** 590,596 ****
--- 663,671 ----
  					res_close();
  					goto next_ns;
  				}
+ #ifndef WINNT
  			}
+ #endif
  
  			/*
  			 * Wait for reply
***************
*** 607,613 ****
--- 682,692 ----
  			n = select(s+1, &dsmask, (fd_set *)NULL,
  				   (fd_set *)NULL, &timeout);
  			if (n < 0) {
+ #ifndef WINNT
  				if (errno == EINTR)
+ #else
+ 				if (errno == WSAEINTR)
+ #endif
  					goto wait;
  				Perror(stderr, "select", errno);
  				res_close();
***************
*** 623,634 ****
--- 702,722 ----
  				res_close();
  				goto next_ns;
  			}
+ #ifndef WINNT
  			errno = 0;
+ #else
+  			WSASetLastError(0);
+  			SetLastError(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;
  			}
***************
*** 753,765 ****
  	} /*foreach retry*/
  	res_close();
  	if (!v_circuit)
! 		if (!gotsomewhere)
  			errno = ECONNREFUSED;	/* no nameservers found */
! 		else
  			errno = ETIMEDOUT;	/* no answer obtained */
! 	else
  		errno = terrno;
  	return (-1);
  }
  
  /*
--- 841,869 ----
  	} /*foreach retry*/
  	res_close();
  	if (!v_circuit)
! 		if (!gotsomewhere) {
! #ifndef WINNT
  			errno = ECONNREFUSED;	/* no nameservers found */
! #else
!  			WSASetLastError(ECONNREFUSED);
!   			SetLastError(ECONNREFUSED);
! #endif
! 		} else {
! #ifndef WINNT
  			errno = ETIMEDOUT;	/* no answer obtained */
! #else
!  			WSASetLastError(ETIMEDOUT);
!  			SetLastError(ETIMEDOUT);
! #endif
! 		} else {
! #ifndef WINNT
  		errno = terrno;
+ #else
+  		WSASetLastError(terrno);
+  		SetLastError(terrno);
+ #endif
  	return (-1);
+  }
  }
  
  /*
***************
*** 774,780 ****
--- 878,888 ----
  {
  	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
Only in m:\bind/res: resolv_vc22.mak
Only in m:\bind/res: resolv_vc22.vcp
diff --context --recurs m:\bind495p1/res/sethostent.c m:\bind/res/sethostent.c
*** m:\bind495p1/res/sethostent.c	Thu Dec 19 02:24:24 1996
--- m:\bind/res/sethostent.c	Tue Oct 08 13:12:34 1996
***************
*** 37,44 ****
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #include <sys/param.h>
! #include <netinet/in.h>
  #include <arpa/nameser.h>
  #include <netdb.h>
  #include <resolv.h>
--- 37,46 ----
  #endif /* LIBC_SCCS and not lint */
  
  #include <sys/types.h>
! #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/res: strip.bat
Only in m:\bind: resolv.mak
diff --context --recurs m:\bind495p1/shres/irix/Makefile m:\bind/shres/irix/Makefile
*** m:\bind495p1/shres/irix/Makefile	Thu Dec 19 02:24:26 1996
--- m:\bind/shres/irix/Makefile	Tue Oct 08 13:02:02 1996
***************
*** 1,13 ****
! # $Id: Makefile,v 8.2 1996/09/22 00:13:32 vixie Exp $
  
! CFLAGS=	-O -I../${INCL} -I../${COMPINCL} ${DEFS} ${LOCDEFS} 
  
! LOCDEFS= -DUSE_OPTIONS_H
  
! OBJS=	base64.o herror.o res_debug.o res_data.o \
! 	res_comp.o res_init.o res_mkquery.o res_query.o res_send.o \
! 	getnetbyaddr.o getnetbyname.o getnetent.o getnetnamadr.o \
! 	gethnamaddr.o sethostent.o nsap_addr.o inet_pton.o inet_ntop.o \
  	inet_addr.o
  
  all: libresolv.so
--- 1,13 ----
! # $Id: Makefile,v 1.4 1996/05/22 04:56:31 vixie Exp $
  
! CFLAGS=	-O -I../${INCL} -I../${COMPINCL} ${DEFS} ${LOCDEFS} 
  
! LOCDEFS= -DUSE_OPTIONS_H
  
! OBJS=	herror.o res_debug.o res_data.o \
! 	res_comp.o res_init.o res_mkquery.o res_query.o res_send.o \
! 	getnetbyaddr.o getnetbyname.o getnetent.o getnetnamadr.o \
! 	gethnamaddr.o sethostent.o nsap_addr.o inet_pton.o inet_ntop.o \
  	inet_addr.o
  
  all: libresolv.so
***************
*** 35,41 ****
  libresolv.so: ${OBJS}
  	LD_OPTIONS="-h libresolv.so.2" $(SHLD) -o $@ $(OBJS) $(LIBS)
  
- base64.o: ../../res/base64.c
  herror.o: ../../res/herror.c
  res_comp.o: ../../res/res_comp.c
  res_debug.o: ../../res/res_debug.c
--- 35,40 ----
Only in m:\bind/shres/netbsd: .cvsignore
Only in m:\bind/shres/netbsd: Letter
Only in m:\bind: t6b-rel
Only in m:\bind/tools: MYDLL.DEF
Only in m:\bind/tools: bdlltest.c
Only in m:\bind/tools: bdltest.mak
Only in m:\bind/tools: bdltest.vcp
Only in m:\bind/tools: binddll.def
Only in m:\bind/tools: binddll.mak
Only in m:\bind/tools: binddll.mdp
Only in m:\bind/tools: binddll.ncb
Only in m:\bind/tools: binddll.vcp
Only in m:\bind/tools: bindll.c
Only in m:\bind/tools: dig.c.sav
Only in m:\bind/tools: dig_nt.c
Only in m:\bind/tools: instsrv.c
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: WinRel
Only in m:\bind/tools/nslookup: addr
diff --context --recurs m:\bind495p1/tools/nslookup/commands.l m:\bind/tools/nslookup/commands.l
*** m:\bind495p1/tools/nslookup/commands.l	Thu Dec 19 02:24:24 1996
--- m:\bind/tools/nslookup/commands.l	Tue Oct 08 13:02:02 1996
***************
*** 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:\bind495p1/tools/nslookup/debug.c m:\bind/tools/nslookup/debug.c
*** m:\bind495p1/tools/nslookup/debug.c	Thu Dec 19 02:24:24 1996
--- m:\bind/tools/nslookup/debug.c	Thu Dec 19 02:31:08 1996
***************
*** 70,92 ****
   *******************************************************************************
   */
  
! #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 "res.h"
! #include "../../conf/portability.h"
  
  /*
   *  Imported from res_debug.c
   */
  extern char *_res_resultcodes[];
  extern char *_res_opcodes[];
  
  /*
   *  Used to highlight the start of a record when printing it.
   */
--- 70,103 ----
   *******************************************************************************
   */
  
! #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 "res.h"
! #include "../../conf/portability.h"
  
  /*
   *  Imported from res_debug.c
   */
  extern char *_res_resultcodes[];
  extern char *_res_opcodes[];
+ char * inet_nsap_ntoa();
+ const char * inet_ntop();
+ 
+ /*
+  *  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.
   */
***************
*** 99,111 ****
   * This is intended to be primarily a debugging routine.
   */
  
  Print_query(msg, eom, printHeader)
  	char *msg, *eom;
  	int printHeader;
  {
! 	Fprint_query(msg, eom, printHeader,stdout);
  }
  
  Fprint_query(msg, eom, printHeader,file)
  	u_char *msg, *eom;
  	int printHeader;
--- 110,124 ----
   * This is intended to be primarily a debugging routine.
   */
  
+ void
  Print_query(msg, eom, printHeader)
  	char *msg, *eom;
  	int printHeader;
  {
! 	Fprint_query(msg, eom, printHeader, stdout);
  }
  
+ void
  Fprint_query(msg, eom, printHeader,file)
  	u_char *msg, *eom;
  	int printHeader;
***************
*** 125,131 ****
  	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) {
--- 138,144 ----
  	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) {
***************
*** 147,162 ****
  		    fprintf(file,", authentic data");
  	    if (hp->cd)
  		    fprintf(file,", checking disabled");
! 	    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");
--- 160,175 ----
  		    fprintf(file,", authentic data");
  	    if (hp->cd)
  		    fprintf(file,", checking disabled");
!   	    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");
***************
*** 174,180 ****
  	/*
  	 * Print authoritative answer records
  	 */
! 	if (n = ntohs(hp->ancount)) {
  		fprintf(file,"    ANSWERS:\n");
  		if (type == T_A && n > MAXADDRS) {
  			printf("Limiting response to MAX Addrs = %d \n",
--- 187,193 ----
  	/*
  	 * Print authoritative answer records
  	 */
! 	if (n = ntohs( (u_short) hp->ancount)) {
  		fprintf(file,"    ANSWERS:\n");
  		if (type == T_A && n > MAXADDRS) {
  			printf("Limiting response to MAX Addrs = %d \n",
***************
*** 191,197 ****
  	/*
  	 * print name server records
  	 */
! 	if (n = ntohs(hp->nscount)) {
  		fprintf(file,"    AUTHORITY RECORDS:\n");
  		while (--n >= 0) {
  			fprintf(file, INDENT);
--- 204,210 ----
  	/*
  	 * print name server records
  	 */
! 	if (n = ntohs( (u_short) hp->nscount)) {
  		fprintf(file,"    AUTHORITY RECORDS:\n");
  		while (--n >= 0) {
  			fprintf(file, INDENT);
***************
*** 203,209 ****
  	/*
  	 * print additional records
  	 */
! 	if (n = ntohs(hp->arcount)) {
  		fprintf(file,"    ADDITIONAL RECORDS:\n");
  		while (--n >= 0) {
  			fprintf(file, INDENT);
--- 216,222 ----
  	/*
  	 * print additional records
  	 */
! 	if (n = ntohs( (u_short) hp->arcount)) {
  		fprintf(file,"    ADDITIONAL RECORDS:\n");
  		while (--n >= 0) {
  			fprintf(file, INDENT);
***************
*** 607,613 ****
  				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);
--- 620,626 ----
  				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);
Only in m:\bind/tools/nslookup: dig.c
Only in m:\bind/tools/nslookup: dig.mak
Only in m:\bind/tools/nslookup: dig.mdp
Only in m:\bind/tools/nslookup: dig.ncb
Only in m:\bind/tools/nslookup: dig.vcp
Only in m:\bind/tools/nslookup: fix1
diff --context --recurs m:\bind495p1/tools/nslookup/getinfo.c m:\bind/tools/nslookup/getinfo.c
*** m:\bind495p1/tools/nslookup/getinfo.c	Thu Dec 19 02:24:24 1996
--- m:\bind/tools/nslookup/getinfo.c	Thu Dec 19 02:31:11 1996
***************
*** 71,86 ****
   ******************************************************************************
   */
  
! #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,88 ----
   ******************************************************************************
   */
  
! #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();
***************
*** 113,118 ****
--- 115,129 ----
  
  #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);
+ 
  
  /*
   ******************************************************************************
***************
*** 185,194 ****
  	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
--- 196,205 ----
  	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
***************
*** 598,604 ****
      if (n == 0 && (cp = hostalias(name))) {
  	    printf("Aliased to \"%s\"\n\n", cp);
  	    return (GetHostDomain(nsAddrPtr, queryClass, queryType,
! 		    cp, (char *)NULL, hostPtr, isServer));
      }
  
      /*
--- 609,615 ----
      if (n == 0 && (cp = hostalias(name))) {
  	    printf("Aliased to \"%s\"\n\n", cp);
  	    return (GetHostDomain(nsAddrPtr, queryClass, queryType,
! 		    (char *)cp, (char *)NULL, hostPtr, isServer));
      }
  
      /*
***************
*** 645,651 ****
  	    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.
***************
*** 664,669 ****
--- 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:\bind495p1/tools/nslookup/list.c m:\bind/tools/nslookup/list.c
*** m:\bind495p1/tools/nslookup/list.c	Thu Dec 19 02:24:24 1996
--- m:\bind/tools/nslookup/list.c	Thu Dec 19 02:31:13 1996
***************
*** 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,116 ----
  extern int	queryType;
  extern int	queryClass;
  
+ char * inet_nsap_ntoa();
+ const char * inet_ntop();
+ 
+ /*
+  * Forward references
+  */
+ 
+ int
+ PrintListInfo(FILE *file, u_char *msg, u_char *eom, int qtype, char *domain);
+ 
+ 
  static int sockFD = -1;
  int ListSubr();
  
***************
*** 312,320 ****
  	 */
  
  	__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;
--- 325,340 ----
  	 */
  
  	__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;
***************
*** 328,334 ****
  	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);
--- 348,354 ----
  	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);
***************
*** 351,357 ****
--- 371,381 ----
  
  	    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;
***************
*** 383,389 ****
--- 407,418 ----
  
  	    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;
  	    }
***************
*** 397,448 ****
  		error = ERR_PRINTING;
  		break;
  	    }
! 	    numRecords += htons(((HEADER *)answer)->ancount);
  	    numAnswers++;
  	    if (cmd != NULL && ((numAnswers % HASH_SIZE) == 0)) {
  		fprintf(stdout, "#");
  		fflush(stdout);
  	    }
! 	    /* Header. */
! 	    cp = answer + HFIXEDSZ;
! 	    /* Question. */
! 	    for (count = ntohs(((HEADER* )answer)->qdcount);
! 		 count > 0;
! 		 count--)
! 		    cp += dn_skipname(cp, answer + len) + QFIXEDSZ;
! 	    /* Answer. */
! 	    for (count = ntohs(((HEADER* )answer)->ancount);
! 		 count > 0;
! 		 count--) {
! 		int type, class, rlen;
! 
! 		n = dn_expand(answer, answer + len, cp,
! 			      dname[soacnt], sizeof dname[0]);
! 		if (n < 0) {
! 		    error = ERR_PRINTING;
! 		    done++;
! 		    break;
! 		}
! 		cp += n;
! 		GETSHORT(type, cp);
! 		GETSHORT(class, cp);
! 		cp += INT32SZ;	/* ttl */
! 		GETSHORT(rlen, cp);
! 		cp += rlen;
! 		if (type == T_SOA && soacnt++ &&
! 		    !strcasecmp(dname[0], dname[1])) {
! 		    done++;
! 		    break;
! 		}
! 	    }
! 	}
! 
! 	if (cmd != NULL) {
! 	    fprintf(stdout, "%sReceived %d answer%s (%d record%s).\n",
! 		(numAnswers >= HASH_SIZE) ? "\n" : "",
! 		numAnswers, (numAnswers != 1) ? "s" : "",
! 		numRecords, (numRecords != 1) ? "s" : "");
! 	}
  
  	(void) close(sockFD);
  	sockFD = -1;
--- 426,477 ----
  		error = ERR_PRINTING;
  		break;
  	    }
! 	    numRecords += htons((u_short)((HEADER *)answer)->ancount);
  	    numAnswers++;
  	    if (cmd != NULL && ((numAnswers % HASH_SIZE) == 0)) {
  		fprintf(stdout, "#");
  		fflush(stdout);
  	    }
!  	    /* Header. */
!   	    cp = answer + HFIXEDSZ;
!  	    /* Question. */
!  	    for (count = ntohs((u_short)((HEADER* )answer)->qdcount);
!  		 count > 0;
!  		 count--)
!  		    cp += dn_skipname((u_char *)cp, (u_char *)answer + len) + QFIXEDSZ;
!  	    /* Answer. */
!  	    for (count = ntohs((u_short)((HEADER* )answer)->ancount);
!  		 count > 0;
!  		 count--) {
!  		int type, class, rlen;
!  
!  		n = dn_expand(answer, answer + len, cp,
!  			      dname[soacnt], sizeof dname[0]);
!  		if (n < 0) {
!  		    error = ERR_PRINTING;
!  		    done++;
!  		    break;
!  		}
!  		cp += n;
!  		GETSHORT(type, cp);
!  		GETSHORT(class, cp);
!  		cp += INT32SZ;	/* ttl */
!  		GETSHORT(rlen, cp);
!  		cp += rlen;
!  		if (type == T_SOA && soacnt++ &&
!  		    !strcasecmp(dname[0], dname[1])) {
!  		    done++;
!  		    break;
!  		}
!   	    }
!   	}
!   
!   	if (cmd != NULL) {
!  	    fprintf(stdout, "%sReceived %d answer%s (%d record%s).\n",
!   		(numAnswers >= HASH_SIZE) ? "\n" : "",
!  		numAnswers, (numAnswers != 1) ? "s" : "",
!  		numRecords, (numRecords != 1) ? "s" : "");
!   	}
  
  	(void) close(sockFD);
  	sockFD = -1;
***************
*** 467,480 ****
  		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);
  	}
  }
- 
  
  /*
   *******************************************************************************
--- 496,508 ----
  		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);
  	}
  }
  
  /*
   *******************************************************************************
***************
*** 515,520 ****
--- 543,549 ----
  }
  
  
+ int
  PrintListInfo(file, msg, eom, qtype, domain)
      FILE	*file;
      u_char	*msg, *eom;
***************
*** 546,563 ****
       *  there aren't any question records.
       */
  
!     if (ntohs(headerPtr->ancount) == 0) {
  	return(NO_INFO);
!     }
!     for (n = ntohs(headerPtr->qdcount); n > 0; n--) {
! 	nameLen = dn_skipname(cp, eom);
! 	if (nameLen < 0)
! 	    return (ERROR);
! 	cp += nameLen + QFIXEDSZ;
!     }
!     for (count = ntohs(headerPtr->ancount); count > 0; count--) {
! 	nameLen = dn_expand(msg, eom, cp, name, sizeof name);
! 	if (nameLen < 0)
  	    return (ERROR);
  	cp += nameLen;
  
--- 575,592 ----
       *  there aren't any question records.
       */
  
!     if (ntohs( (u_short) headerPtr->ancount) == 0) {
  	return(NO_INFO);
!       }
!       for (n = ntohs((u_short) headerPtr->qdcount); n > 0; n--) {
!  	nameLen = dn_skipname(cp, eom);
!  	if (nameLen < 0)
!  	    return (ERROR);
!  	cp += nameLen + QFIXEDSZ;
!       }
!       for (count = ntohs((u_short)headerPtr->ancount); count > 0; count--) {
!   	nameLen = dn_expand(msg, eom, cp, name, sizeof name);
!   	if (nameLen < 0)
  	    return (ERROR);
  	cp += nameLen;
  
***************
*** 890,895 ****
--- 919,925 ----
   *******************************************************************************
   */
  
+ void
  ViewList(string)
      char *string;
  {
***************
*** 925,931 ****
--- 955,967 ----
  {
  	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];
***************
*** 981,987 ****
  	if (!putToFile) {
  	    filePtr = stdout;
  	} else {
! 	    filePtr = OpenFile(string, file);
  	    if (filePtr == NULL) {
  		fprintf(stderr, "*** Can't open %s for writing\n", file);
  		close(sockFD);
--- 1017,1023 ----
  	if (!putToFile) {
  	    filePtr = stdout;
  	} else {
! 	    filePtr = AppOpenFile(string, file);
  	    if (filePtr == NULL) {
  		fprintf(stderr, "*** Can't open %s for writing\n", file);
  		close(sockFD);
***************
*** 993,1003 ****
  	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) {
--- 1029,1047 ----
  	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) {
***************
*** 1013,1022 ****
  	    }
  	    putc(lastc = c, filePtr);
  	}
! 	if (lastc != '\n') {
  	    putc('\n', filePtr);
! 	}
! 	putc('\n', filePtr);
  
  	close(sockFD);
  	sockFD = -1;
--- 1057,1090 ----
  	    }
  	    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;
***************
*** 1028,1033 ****
--- 1096,1102 ----
  	return (SUCCESS);
  }
  
+ void
  ListHost_close()
  {
      if (sockFD != -1) {
diff --context --recurs m:\bind495p1/tools/nslookup/main.c m:\bind/tools/nslookup/main.c
*** m:\bind495p1/tools/nslookup/main.c	Thu Dec 19 02:24:24 1996
--- m:\bind/tools/nslookup/main.c	Fri Nov 22 16:10:46 1996
***************
*** 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,214 ----
  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 (OnWinnt() == TRUE)
+           {
+ 	    if (!ExpandEnvironmentStrings(_PATH_HELPFILE, pathhelpfile, MAX_PATH)) {
+ 	 	  syslog(LOG_ERR, "ExpandEnvironmentStrings(_PATH_HELPFILE) failed: %m\n");
+ 	    }
+ 	  }
+           else
+            { 
+  	    if (!ExpandEnvironmentStrings(_PATH_95HELPFILE, pathhelpfile, MAX_PATH)) {
+ 	 	  syslog(LOG_ERR, "ExpandEnvironmentStrings(_PATH_95HELPFILE) failed: %m\n");
+ 	    }
+ 	   }
+ }
+ #endif /* WINNT */
+ 
+ 
  
  /*
   ******************************************************************************
***************
*** 182,187 ****
--- 235,261 ----
      /*
       *  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");
***************
*** 244,250 ****
--- 318,328 ----
  	    _res.nscount = 1;
  	    _res.nsaddr.sin_addr = addr;
  	} else {
+ #ifndef WINNT
  	    hp = gethostbyname(*argv);
+ #else
+ 	    hp = gethostbyname_nt(*argv);
+ #endif
  	    if (hp == NULL) {
  		fprintf(stderr, "*** Can't find server address for '%s': ", 
  			*argv);
***************
*** 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);
  
  	/* 
--- 398,413 ----
  
  	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. 
--- 416,422 ----
  
  	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 ****
--- 424,430 ----
  
  	printf("> ");
  	fflush(stdout);
+ 
  	while(yylex()) {
  	    printf("> ");
  	    fflush(stdout);
***************
*** 352,357 ****
--- 434,440 ----
  }
  
  
+ 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);
--- 442,458 ----
  
      (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 ****
--- 469,475 ----
   ******************************************************************************
   */
  
+ void 
  Usage()
  {
      fprintf(stderr, "Usage:\n");
***************
*** 682,688 ****
      if (!putToFile) {
  	filePtr = stdout;
      } else {
! 	filePtr = OpenFile(string, file);
  	if (filePtr == NULL) {
  	    fprintf(stderr, "*** Can't open %s for writing\n", file);
  	    return(ERROR);
--- 774,780 ----
      if (!putToFile) {
  	filePtr = stdout;
      } else {
! 	filePtr = AppOpenFile(string, file);
  	if (filePtr == NULL) {
  	    fprintf(stderr, "*** Can't open %s for writing\n", file);
  	    return(ERROR);
***************
*** 743,749 ****
      if (!putToFile) {
  	filePtr = stdout;
      } else {
! 	filePtr = OpenFile(string, file);
  	if (filePtr == NULL) {
  	    fprintf(stderr, "*** Can't open %s for writing\n", file);
  	    return(ERROR);
--- 835,841 ----
      if (!putToFile) {
  	filePtr = stdout;
      } else {
! 	filePtr = AppOpenFile(string, file);
  	if (filePtr == NULL) {
  	    fprintf(stderr, "*** Can't open %s for writing\n", file);
  	    return(ERROR);
***************
*** 932,937 ****
--- 1024,1030 ----
  /*
   * Fake a reinitialization when the domain is changed.
   */
+ void
  res_re_init()
  {
      register char *cp, **pp;
***************
*** 954,959 ****
--- 1047,1053 ----
  
  #define SRCHLIST_SEP '/'
  
+ void
  res_dnsrch(cp)
      register char *cp;
  {
***************
*** 1050,1057 ****
  PrintHelp()
  {
  	char cmd[PATH_MAX];
! 
  	sprintf(cmd, "%s %s", pager, _PATH_HELPFILE);
  	system(cmd);
  }
  
--- 1144,1156 ----
  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);
  }
  
***************
*** 1106,1112 ****
--- 1205,1215 ----
  	(strlen(cp) + strlen(_PATH_NSLOOKUPRC)) < sizeof(buf)) {
  
  	(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.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: nslookup_vc22.mak
Only in m:\bind/tools/nslookup: nslookup_vc22.vcp
diff --context --recurs m:\bind495p1/tools/nslookup/pathnames.h m:\bind/tools/nslookup/pathnames.h
*** m:\bind495p1/tools/nslookup/pathnames.h	Thu Dec 19 02:24:24 1996
--- m:\bind/tools/nslookup/pathnames.h	Tue Oct 08 13:13:12 1996
***************
*** 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,81 ----
   */
  
  #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"
! #define _PATH_95HELPFILE        "%windir%\\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:\bind495p1/tools/nslookup/res.h m:\bind/tools/nslookup/res.h
*** m:\bind495p1/tools/nslookup/res.h	Thu Dec 19 02:24:24 1996
--- m:\bind/tools/nslookup/res.h	Thu Dec 19 02:31:16 1996
***************
*** 73,86 ****
   *******************************************************************************
   */
  
! #define TRUE	1
! #define FALSE	0
! typedef int Boolean;
  
! #define MAXALIASES	35
! #define MAXADDRS	35
! #define MAXDOMAINS	35
! #define MAXSERVERS	10
  
  /*
   *  Define return statuses in addtion to the ones defined in namserv.h
--- 73,95 ----
   *******************************************************************************
   */
  
! #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 MAXALIASES	35
! #define MAXADDRS	35
! #define MAXDOMAINS	35
! #define MAXSERVERS	10
  
  /*
   *  Define return statuses in addtion to the ones defined in namserv.h
***************
*** 160,171 ****
   */
  
  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 const char *DecodeType();	/* descriptive version of p_type */
  extern const char *DecodeError();
  extern char *Calloc();
  extern char *Malloc();
  extern void NsError();
--- 169,181 ----
   */
  
  extern Boolean IsAddr();
! extern void  Print_query();
  extern unsigned char *Print_cdname();
  extern unsigned char *Print_cdname2();	/* fixed width */
  extern unsigned char *Print_rr();
  extern const char *DecodeType();	/* descriptive version of p_type */
  extern const char *DecodeError();
+ 
  extern char *Calloc();
  extern char *Malloc();
  extern void NsError();
***************
*** 173,177 ****
--- 183,235 ----
  extern void PrintHostInfo();
  extern void ShowOptions();
  extern void FreeHostInfoPtr();
+ 
+ #ifndef WINNT
  extern FILE *OpenFile();
+ #endif
+ 
  extern char *res_skip();
+ 
+ #ifdef WINNT
+   
+ /*
+    * subr.c definitions
+ */
+   
+   FILE * AppOpenFile(char *string, char *file);
+   int StringToType(char *type, int dflt, FILE *errorfile);
+   int StringToClass(char *class, int dflt, FILE *errorfile);
+   
+ /*
+ * 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);
+   
+   /*
+    * 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 WINNT
+ 
+ #endif /* _RES_H_ */
+ 
Only in m:\bind/tools/nslookup: save1
diff --context --recurs m:\bind495p1/tools/nslookup/send.c m:\bind/tools/nslookup/send.c
*** m:\bind495p1/tools/nslookup/send.c	Thu Dec 19 02:24:24 1996
--- m:\bind/tools/nslookup/send.c	Fri Nov 22 18:15:16 1996
***************
*** 74,93 ****
  /*
   * 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,95 ----
  /*
   * 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 */
  
  
***************
*** 210,216 ****
--- 212,222 ----
  			 */
  			cp = answer;
  			len = INT16SZ;
+ #ifndef WINNT
  			while ((n = read(s, (char *)cp, (int)len)) > 0) {
+ #else
+ 			while ((n = recv(s, (char *)cp, (int)len,0)) > 0) {
+ #endif
  				cp += n;
  				if ((len -= n) <= 0)
  					break;
***************
*** 236,242 ****
  				continue;
  			}
  			cp = answer;
! 			if ((resplen = _getshort((u_char*)cp)) > anslen) {
  				if (_res.options & RES_DEBUG)
  					fprintf(stderr, "response truncated\n");
  				len = anslen;
--- 242,248 ----
  				continue;
  			}
  			cp = answer;
! 			if ( (u_int)(resplen = _getshort((u_char*)cp)) > anslen) {
  				if (_res.options & RES_DEBUG)
  					fprintf(stderr, "response truncated\n");
  				len = anslen;
***************
*** 244,250 ****
--- 250,260 ----
  			} else
  				len = resplen;
  			while (len != 0 &&
+ #ifndef WINNT
  			   (n = read(s, (char *)cp, (int)len)) > 0) {
+ #else
+ 			   (n = recv(s, (char *)cp, (int)len,0)) > 0) {
+ #endif
  				cp += n;
  				len -= n;
  			}
***************
*** 266,272 ****
--- 276,286 ----
  				while (len != 0) {
  					n = (len > sizeof(junk) ?
  					    sizeof(junk) : len);
+ #ifndef WINNT
  					if ((n = read(s, junk, n)) > 0)
+ #else
+ 					if ((n = recv(s, junk, n,0)) > 0)
+ #endif
  						len -= n;
  					else
  						break;
***************
*** 403,408 ****
--- 417,423 ----
   *
   * Called from the interrupt handler.
   */
+ void
  SendRequest_close()
  {
  	if (s != -1) {
diff --context --recurs m:\bind495p1/tools/nslookup/skip.c m:\bind/tools/nslookup/skip.c
*** m:\bind495p1/tools/nslookup/skip.c	Thu Dec 19 02:24:24 1996
--- m:\bind/tools/nslookup/skip.c	Tue Oct 08 13:13:12 1996
***************
*** 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);
Only in m:\bind/tools/nslookup: strip.bat
diff --context --recurs m:\bind495p1/tools/nslookup/subr.c m:\bind/tools/nslookup/subr.c
*** m:\bind495p1/tools/nslookup/subr.c	Thu Dec 19 02:24:24 1996
--- m:\bind/tools/nslookup/subr.c	Tue Oct 08 13:13:12 1996
***************
*** 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 "resolv.h"
  #include "res.h"
  #include "../../conf/portability.h"
--- 74,96 ----
   *******************************************************************************
   */
  
! 
! #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 "resolv.h"
  #include "res.h"
  #include "../../conf/portability.h"
***************
*** 113,118 ****
--- 120,126 ----
   *
   *******************************************************************************
   */
+  #ifndef WINNT
  
  SIG_FN
  IntrHandler()
***************
*** 136,142 ****
      longjmp(env, 1);
  }
  
! 
  /*
   *******************************************************************************
   *
--- 144,150 ----
      longjmp(env, 1);
  }
  
!  #endif
  /*
   *******************************************************************************
   *
***************
*** 187,196 ****
        sigprocmask(SIG_UNBLOCK,&sset,NULL);
      }
  #else
!     { int saveMask;
        saveMask = sigblock(sigmask(SIGINT));
        ptr = malloc((unsigned) size);
        (void) sigsetmask(saveMask);
      }
  #endif
  #endif
--- 195,209 ----
        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
***************
*** 317,323 ****
  /*
   *******************************************************************************
   *
!  *  OpenFile --
   *
   *	Parses a command string for a file name and opens
   *	the file.
--- 330,336 ----
  /*
   *******************************************************************************
   *
!  *  AppOpenFile --
   *
   *	Parses a command string for a file name and opens
   *	the file.
***************
*** 331,337 ****
   */
  
  FILE *
! OpenFile(string, file)
      char *string;
      char *file;
  {
--- 344,350 ----
   */
  
  FILE *
! AppOpenFile(string, file)
      char *string;
      char *file;
  {
Only in m:\bind/tools/nslookup: winntport.txt
Only in m:\bind/tools/nslookup: yylex.c
