2015-09-25  Juan Manuel Guerrero <juan.guerrero@gmx.de>
	I have taken all these changes from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master.
	I have kept only those ones that I have found usefull and liked.  I have no way to verify that the changes
	really work as they are intended.



	* wattcp.q2dos/inc/sys/cdefs.h: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/inc/sys/packoff.h: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/inc/sys/packon.h: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/inc/sys/socket.h: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/inc/sys/swap.h: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/inc/tcp.h: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/btree.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/config.h: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/cpumodel.asm: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/cpumodel.h: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/cpumodel.s: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/gethost.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/getnet.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/get_ai.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/ioport.h: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/ip4_frag.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/misc.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/misc.h: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/packet32.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/pcarp.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/pcconfig.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/pcdhcp.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/pctcp.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/ppp.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/presaddr.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/printk.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/tcp_fsm.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/timer.h: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/wattcp.h: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/src/winpcap.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master

	* wattcp.q2dos/util/errnos.c: Modifications taken from https://bitbucket.org/neozeed/q2dos/src/6a813a816943/wattcp/?at=master






diff -aprNU5 watt/inc/sys/cdefs.h wattcp.q2dos/inc/sys/cdefs.h
--- watt/inc/sys/cdefs.h	2005-12-29 23:14:10 +0100
+++ wattcp.q2dos/inc/sys/cdefs.h	2015-11-14 22:32:52 +0100
@@ -42,13 +42,12 @@
  */
 
 #ifndef __SYS_CDEFS_H
 #define __SYS_CDEFS_H
 
-#if defined(__DJGPP__) && !defined(djgpp_cdefs_incl)
-  #include "/dev/env/DJDIR/include/sys/cdefs.h"
-  #define djgpp_cdefs_incl
+#if defined(__DJGPP__)
+  #include_next <sys/cdefs.h>
 #endif
 
 #ifdef __cplusplus
   #define __BEGIN_DECLS  extern "C" {
   #define __END_DECLS    }
@@ -186,10 +185,20 @@ struct mbuf {
     #undef  __dead2
     #define __dead2
   #endif
 #endif
 
+#if defined(__GNUC__)  /* from djgpp-2.04 sys/cdefs.h : */
+/* Ensure that always traditional GNU extern inline semantics are used
+   (aka -fgnu89-inline) even if ISO C99 semantics have been specified.  */
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
+# define _W32_EXTERN_INLINE  extern __inline__ __attribute__ ((__gnu_inline__))
+#else
+# define _W32_EXTERN_INLINE  extern __inline__
+#endif
+#endif /* _W32_EXTERN_INLINE */
+
 /*
  * Delete pseudo-keywords wherever they are not available or needed.
  * This seems to break MingW in mysterious ways, so leave it,
  */
 #ifndef __dead
diff -aprNU5 watt/inc/sys/packoff.h wattcp.q2dos/inc/sys/packoff.h
--- watt/inc/sys/packoff.h	2006-01-15 01:33:18 +0100
+++ wattcp.q2dos/inc/sys/packoff.h	2015-11-14 22:32:52 +0100
@@ -55,10 +55,12 @@ Revision History:
   #elif defined(__HIGHC__)
     #pragma pop_align_members();
   #elif defined(__WATCOMC__) && (__WATCOMC__ >= 1000)
     #pragma pack(__pop);
   #elif (defined(_MSC_VER) && (_MSC_VER > 800)) || \
+        (defined(__GNUC__) && ((__GNUC__ > 2) || \
+              (__GNUC__ == 2 && __GNUC_MINOR__ > 95))) || \
         (defined(__BORLANDC__) && (__BORLANDC__ >= 0x500)) || \
          defined(__POCC__) || defined(__LCC__)
     #pragma pack(pop)
   #else
     #pragma pack()
diff -aprNU5 watt/inc/sys/packon.h wattcp.q2dos/inc/sys/packon.h
--- watt/inc/sys/packon.h	2006-01-15 01:33:12 +0100
+++ wattcp.q2dos/inc/sys/packon.h	2015-11-14 22:32:52 +0100
@@ -51,10 +51,12 @@ Revision History:
   #if defined(__HIGHC__)
     #pragma push_align_members(1);
   #elif defined(__WATCOMC__) && (__WATCOMC__ >= 1000)
     #pragma pack(__push,1);
   #elif (defined(_MSC_VER) && (_MSC_VER > 800)) || \
+        (defined(__GNUC__) && ((__GNUC__ > 2) || \
+              (__GNUC__ == 2 && __GNUC_MINOR__ > 95))) || \
         (defined(__BORLANDC__) && (__BORLANDC__ >= 0x500)) || \
          defined(__POCC__) || defined(__LCC__)
     #pragma pack(push,1)
   #else
     #pragma pack(1)
diff -aprNU5 watt/inc/sys/socket.h wattcp.q2dos/inc/sys/socket.h
--- watt/inc/sys/socket.h	2005-12-13 22:18:14 +0100
+++ wattcp.q2dos/inc/sys/socket.h	2015-11-14 22:32:52 +0100
@@ -211,20 +211,20 @@ struct sockproto {
 #define PF_MAX          AF_MAX
 
 /*
  * Maximum queue length specifiable by listen.
  */
-#define SOMAXCONN       32
+#define SOMAXCONN       1024 // FS: Was 32
 #define MSG_OOB         0x1             /* process out-of-band data */
 #define MSG_PEEK        0x2             /* peek at incoming message */
 #define MSG_DONTROUTE   0x4             /* send without using routing tables */
 #define MSG_EOR         0x8             /* data completes record */
 #define MSG_TRUNC       0x10            /* data discarded before delivery */
 #define MSG_CTRUNC      0x20            /* control data lost before delivery */
 #define MSG_WAITALL     0x40            /* wait for full request or error */
 
-#define MSG_MAXIOVLEN   16
+#define MSG_MAXIOVLEN   256 // FS: Was 16
 
 
 /*
  * Header for ancillary data objects in msg_control buffer.
  * Used for additional information with/about a datagram
diff -aprNU5 watt/inc/sys/swap.h wattcp.q2dos/inc/sys/swap.h
--- watt/inc/sys/swap.h	2005-12-29 23:02:44 +0100
+++ wattcp.q2dos/inc/sys/swap.h	2015-11-14 22:32:52 +0100
@@ -56,21 +56,21 @@ __BEGIN_DECLS
   #define intel16(x) __ntohs(x)
 
   /*
    * Ripped (and adapted) from <linux/include/asm-386/byteorder.h>
    */
-  /*@unused@*/ extern __inline__ unsigned long __ntohl (unsigned long x)
+  /*@unused@*/ _W32_EXTERN_INLINE unsigned long __ntohl (unsigned long x)
   {
     __asm__ __volatile (
              "xchgb %b0, %h0\n\t"   /* swap lower bytes  */
              "rorl  $16, %0\n\t"    /* swap words        */
              "xchgb %b0, %h0"       /* swap higher bytes */
             : "=q" (x) : "0" (x));
     return (x);
   }
 
-  /*@unused@*/ extern __inline__ unsigned short __ntohs (unsigned short x)
+  /*@unused@*/ _W32_EXTERN_INLINE unsigned short __ntohs (unsigned short x)
   {
     __asm__ __volatile__ (
               "xchgb %b0, %h0"       /* swap bytes */
             : "=q" (x) : "0" (x));
     return (x);
diff -aprNU5 watt/inc/tcp.h wattcp.q2dos/inc/tcp.h
--- watt/inc/tcp.h	2006-01-09 09:34:26 +0100
+++ wattcp.q2dos/inc/tcp.h	2015-11-14 22:32:52 +0100
@@ -47,13 +47,10 @@
   #pragma read_only_directory;
 #endif
 
 #ifdef __cplusplus
   extern "C" {
-  #if 0  /* keep Emacs's auto-indent happy */
-  }
-  #endif
 #endif
 
 W32_DATA const char *wattcpCopyright;  /* "See COPYRIGHT.H for details" */
 
 W32_FUNC const char *wattcpVersion (void);      /* WatTCP target version/date */
@@ -85,10 +82,11 @@ W32_FUNC const char *wattcpCapabilities
 #endif
 
 /*
  * Old compatibility
  */
+#ifndef WATT32_NO_OLDIES
 #ifndef byte
 #define byte  unsigned char
 #endif
 
 #ifndef word
@@ -100,10 +98,11 @@ W32_FUNC const char *wattcpCapabilities
 #endif
 
 #ifndef longword
 #define longword unsigned long
 #endif
+#endif
 
 /*
  * Basic typedefs
  */
 typedef BYTE  eth_address[6];
diff -aprNU5 watt/src/btree.c wattcp.q2dos/src/btree.c
--- watt/src/btree.c	2003-07-16 20:34:10 +0200
+++ wattcp.q2dos/src/btree.c	2015-11-14 22:32:52 +0100
@@ -211,11 +211,11 @@ tree_order t_order = IN_ORDER;
 typedef struct {
         char key[KEYSIZE];
         int  id;
       } record;
 
-record rec;
+static record rec;
 
 
 void prompt (const char *verb)
 {
   printf ("\nEnter String to %s\t( <Enter> for none )\n>", verb);
diff -aprNU5 watt/src/config.h wattcp.q2dos/src/config.h
--- watt/src/config.h	2006-01-15 01:07:18 +0100
+++ wattcp.q2dos/src/config.h	2015-11-14 22:32:52 +0100
@@ -98,54 +98,54 @@
 
 /*
  * Else, for all targets define these options:
  */
 #if !defined(OPT_DEFINED)
-  #define USE_DEBUG
+/*#define USE_DEBUG */
   #define USE_BOOTP
   #define USE_DHCP
-  #define USE_LANGUAGE
+/*#define USE_LANGUAGE */
   #define USE_FRAGMENTS
-  #define USE_STATISTICS
-  #define USE_BIND
+/*#define USE_STATISTICS*/
+/*#define USE_BIND */
   #define USE_BSD_API
   #define USE_BSD_FATAL
   #define USE_LOOPBACK
   #define USE_BUFFERED_IO
-  #define USE_TFTP
-  #define USE_MULTICAST
-  #define USE_PPPOE
+/*#define USE_TFTP */
+/*#define USE_MULTICAST*/
+/*#define USE_PPPOE */		/* no longer enabled by default in 2.2.11: G.V. says it never worked. */
   #define OPT_DEFINED
 #endif
 
 /*
  * Add some more options for djgpp, HighC, 32-bit Watcom/DMC and Win32
  */
 #if defined(__DJGPP__) || defined(__HIGHC__) || defined(WATCOM386) || \
     defined(DMC386) || defined(WIN32)
-  #define USE_ECHO_DISC
+/*#define USE_ECHO_DISC */
   #define USE_RARP
-  #define USE_IPV6
-  #define USE_IDNA
-  #define USE_TCP_MD5
-  #define USE_GZIP_COMPR
-  #define USE_DYNIP_CLI
+/*#define USE_IPV6 */
+/*#define USE_IDNA */
+/*#define USE_TCP_MD5*/
+/*#define USE_GZIP_COMPR */
+/*#define USE_DYNIP_CLI */
 #endif
 
 #if defined(__DJGPP__)
   #define USE_FSEXT
-  #define USE_RS232_DBG
-  #define USE_FORTIFY
+/*#define USE_RS232_DBG*/
+/*#define USE_FORTIFY */
 /*#define USE_SECURE_ARP */
 #endif
 
 #if (DOSX && DOSX != WINWATT)
   #define USE_FAST_PKT
 #endif
 
 #if (DOSX) && defined(HAVE_UINT64)
-  #define USE_PROFILER
+/*#define USE_PROFILER */
 #endif
 
 #if defined(__POCC__)
   #undef USE_IDNA    /* PunyCode.c causes crsh in pocc */
 #endif
diff -aprNU5 watt/src/cpumodel.asm wattcp.q2dos/src/cpumodel.asm
--- watt/src/cpumodel.asm	2005-12-29 22:10:20 +0100
+++ wattcp.q2dos/src/cpumodel.asm	2015-11-14 22:32:52 +0100
@@ -2,19 +2,19 @@
 ;
 ;  This file contains all assembly code for the Intel CPU identification.
 ;  It is based on linux cpu detection code.
 ;
 ;  Intel also provides public similar code in the book
-;  called :
+;  called:
 ;
 ;  Pentium Processor Family
 ;      Developer Family
-;  Volume  3 : Architecture and Programming Manual
+;  Volume 3: Architecture and Programming Manual
 ;
 ;  At the following place :
 ;
-;  Chapter 5 : Feature determination
+;  Chapter 5:  Feature determination
 ;  Chapter 25: CPUID instruction
 ;
 ;  COPYRIGHT (c) 1998 valette@crf.canon.fr
 ;
 ;  The license and distribution terms for this file may be
@@ -27,11 +27,11 @@
 ;  the Watt-32 tcp/ip stack.
 ;
 
 PAGE 66, 132
 
-ifdef DOSX  ; only for 32-bit target (including WIN32)
+ifdef DOSX  ; only for 32-bit targets (including WIN32)
 
 ;
 ; All '__w32_' and '_x86' symbols are only needed for Borland and
 ; Digital Mars (until it fixes it's bug in the "pragma alias" handling).
 ;
@@ -59,16 +59,16 @@ PUBLIC _w32_SelReadable , __w32_SelReada
 PUBLIC _w32_SelWriteable, __w32_SelWriteable
 
 ifdef ??version   ; Turbo Assembler
   .486p
   .487
-else
+else              ; MASM, ML or WASM
   .586p
   .387
 endif
 
-ifdef X32VM       ; FlashTek's X32 isn't flat-model, but SMALL
+ifdef X32VM       ; FlashTek's X32 isn't FLAT model, but SMALL
   .MODEL SMALL,C
 else
   .MODEL FLAT,C
 endif
 
@@ -151,11 +151,10 @@ __w32_CheckCpuType:
     pop  eax
 
     xor  eax, ecx                   ; check if ID bit changed
     and  eax, EFLAGS_ID
 
-    ;
     ; If we are on a straight 486DX, SX, or 487SX we can't
     ; change it. OTOH 6x86MXs and MIIs check OK.
     ; Also if we are on a Cyrix 6x86(L)
 
     je is486x
@@ -173,13 +172,12 @@ isnew:
     mov  eax, 1
    _CPUID
 
     mov  cl, al                     ; save reg for future use
 
-    and  ah, 0Fh                    ; mask processor family
+    and  ah, 0Fh                    ; mask processor family (bit 8-11)
     mov  x86_type, ah               ; put result in x86_type (0..15)
-    and  x86_type, 7
 
     and  al, 0F0h                   ; get model
     shr  al, 4
     mov  x86_model, al              ; store it in x86_model
 
@@ -224,11 +222,11 @@ is486x:
     mov ax, 5
     mov bx, 2
     div bl
     lahf
     cmp ah, 2
-    jne ncyrix
+    jne is386
 
     ;
     ; N.B. The pattern of accesses to 0x22 and 0x23 is *essential*
     ;      so do not try to "optimize" it! For the same reason we
     ;      do all this with interrupts off.
@@ -257,32 +255,28 @@ getCx86 MACRO reg
     getCx86 0E8h             ; now we can get CCR4
     or ax, 80h               ; and set bit 7 (CPUIDEN)
     mov bx, ax               ; to enable CPUID execution
     setCx86 0E8h, bx
 
-    getCx86 0FEh             ; DIR0 : let's check this is a 6x86(L)
-    and ax, 0F0h             ; should be 3xh
-    cmp ax, 30h
-    jne n6x86
+; Must check cpu id regs here and not after trying to set CCR3
+; to avoid failure when testing SG Microelectronic STPCs, which
+; lock up if you try to enable cpuid execution
+
+    getCx86 0FEh             ; DIR0 : let's check if this is a 6x86(L)
+    and  ax, 0F0h            ; should be 3xh
+    cmp  ax, 30h             ; STPCs return 0x80, 0x1a, 0x1b or 0x1f
+    jne  is386
+
     getCx86 0E9h             ; CCR5 : we reset the SLOP bit
     and ax, 0FDh             ; so that udelay calculation
     mov bx, ax               ; is correct on 6x86(L) CPUs
     setCx86 0E9h, bx
 
     setCx86 0C3h, cx         ; Restore old CCR3
     sti
     jmp isnew                ; We enabled CPUID now
 
-n6x86:
-    setCx86 0C3h, cx         ; Restore old CCR3
-    sti
-
-ncyrix:
-    popfd                    ; restore original EFLAGS
-    call check_x87
-    jmp  end_CheckCpuType
-
 is386:
     popfd                    ; restore original EFLAGS
     call check_x87
 
 end_CheckCpuType:
@@ -402,11 +396,11 @@ __w32_MY_SS:
     ret
 
 ;
 ; DWORD cdecl Get_CR4 (void);
 ;
-; Is virtualised under Win32 (always returns 0), hence of no use.
+; This is virtualised under Win32 (always returns 0), hence of no use.
 ; Don't call this function w/o checking for a true Pentium first
 ; (see RDTSC_enabled() in misc.c). Returns 0 if CPL != 0.
 ;
  _w32_Get_CR4:
 __w32_Get_CR4:
diff -aprNU5 watt/src/cpumodel.h wattcp.q2dos/src/cpumodel.h
--- watt/src/cpumodel.h	2005-12-29 22:47:56 +0100
+++ wattcp.q2dos/src/cpumodel.h	2015-11-14 22:32:52 +0100
@@ -154,13 +154,13 @@ extern CONST char  DATA_DECL x86_vendor_
 
 #if defined(__GNUC__)
   /*
    * Call this only if x86_have_cpuid == TRUE.
    */
-  /*@unused@*/ extern __inline__ void get_cpuid (DWORD val, DWORD *eax,
-                                                 DWORD *ebx,DWORD *ecx,
-                                                 DWORD *edx)
+  /*@unused@*/ _W32_EXTERN_INLINE void get_cpuid(DWORD val, DWORD *eax,
+                                                DWORD *ebx,DWORD *ecx,
+                                                DWORD *edx)
   {
     __asm__ __volatile__ (
               ".byte 0x0F,0xA2;"   /* cpuid opcode */
             : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
             : "0" (val));
@@ -175,20 +175,20 @@ extern CONST char  DATA_DECL x86_vendor_
    * Return CPU timestamp value. Don't call unless 'has_rdtsc'
    * is TRUE. This code is originally by
    *   Tom Burgess <Tom_Burgess@bc.sympatico.ca> and
    *   Douglas Eleveld <deleveld@dds.nl>
    */
-  extern __inline__ uint64 get_rdtsc (void)
+  _W32_EXTERN_INLINE uint64 get_rdtsc (void)
   {
     register uint64 tsc;
     __asm__ __volatile__ (
               ".byte 0x0F, 0x31;"   /* rdtsc opcode */
             : "=A" (tsc) );
     return (tsc);
   }
 
-  extern __inline__ void get_rdtsc2 (struct ulong_long *tsc)
+  _W32_EXTERN_INLINE void get_rdtsc2 (struct ulong_long *tsc)
   {
     __asm__ __volatile__ (
               ".byte 0x0F, 0x31;"
             : "=a" (tsc->lo), "=d" (tsc->hi) : );
   }
@@ -289,11 +289,11 @@ static void pkt_restore_fpu (char far *s
 /*
  * Check if a CPUID instruction is available on this CPU.
  * Note used at the moment. See cpumodel.asm instead.
  */
 #if defined(__GNUC__)
-extern __inline__ BOOL have_cpuid (void)
+_W32_EXTERN_INLINE BOOL have_cpuid (void)
 {
   int result = -1;
 
   /* We're checking if the bit #21 of EFLAGS
    * can be toggled. If yes = CPUID is available.
diff -aprNU5 watt/src/cpumodel.s wattcp.q2dos/src/cpumodel.s
--- watt/src/cpumodel.s	2005-12-29 22:10:34 +0100
+++ wattcp.q2dos/src/cpumodel.s	2015-11-14 22:32:52 +0100
@@ -37,12 +37,12 @@ DATA (x86_have_cpuid, .long 0)
 DATA (x86_capability, .long 0)
 DATA (x86_vendor_id,  .zero 13)
 
 .text
 
-/* 
- * check Processor type: 386, 486, 6x86(L) or CPUID capable processor 
+/*
+ * check Processor type: 386, 486, 6x86(L) or CPUID capable processor
  */
 ENTRY (_w32_CheckCpuType)
     pushl %ebp
     movl  %esp, %ebp
     pushl %ebx
@@ -55,43 +55,43 @@ ENTRY (_w32_CheckCpuType)
      * bit can be set we have a 486 or above.
      */
     pushfl                          /* save EFLAGS */
     pushfl                          /* Get EFLAGS in EAX */
     popl %eax
-    
+
     movl  %eax, %ecx                /* save original EFLAGS in ECX */
     xorl  $EFLAGS_ALIGN_CHECK, %eax /* flip AC bit in EAX */
     pushl %eax                      /* set EAX as EFLAGS */
-    popfl           
+    popfl
     pushfl                          /* Get new EFLAGS in EAX */
     popl  %eax
-    
+
     xorl  %ecx, %eax                /* check if AC bit changed */
     andl  $EFLAGS_ALIGN_CHECK,%eax
     je is386                        /* If not : we have a 386 */
 
     /* Assume 486 for now
      */
     movl  $4, _C_LABEL(x86_type)
     movl  %ecx, %eax                /* Restore orig EFLAGS in EAX */
     xorl  $EFLAGS_ID, %eax          /* flip  ID flag */
     pushl %eax                      /* set EAX as EFLAGS */
-    popfl               
+    popfl
     pushfl                          /* Get new EFLAGS in EAX */
     popl  %eax
-            
+
     xorl  %ecx, %eax                /* check if ID bit changed */
     andl  $EFLAGS_ID, %eax
 
-    /* 
+    /*
      * if we are on a straight 486DX, SX, or 487SX we can't
      * change it. OTOH 6x86MXs and MIIs check OK.
      * Also if we are on a Cyrix 6x86(L)
      */
     je is486x
 
-isnew:  
+isnew:
     /* restore original EFLAGS
      */
     popfl
     incl _C_LABEL(x86_have_cpuid)   /* we have CPUID instruction */
 
@@ -100,26 +100,26 @@ isnew:
      *  processor model,
      *  processor mask,
      * by using it with EAX = 1
      */
     movl $1, %eax
-    cpuid           
+    cpuid
 
     movb %al, %cl                 /* save reg for future use */
-    
+
     andb $0x0F, %ah               /* mask processor family (bit 8-11) */
     movb %ah, _C_LABEL(x86_type)  /* put result in x86_type (0..15) */
 
     andb $0xF0, %al               /* get model (bit 4-7) */
     shrb $4, %al
     movb %al, _C_LABEL(x86_model) /* store it in x86_model */
-    
+
     andb $0x0F, %cl               /* get mask revision */
     movb %cl, _C_LABEL(x86_mask)  /* store it in x86_mask */
-    
+
     movl %edx, _C_LABEL(x86_capability) /* store feature flags */
-    
+
     /* get vendor info by using CPUID with EAX = 0
      */
     xorl %eax, %eax
     cpuid
 
@@ -151,11 +151,11 @@ is486x:
     movw $5, %ax
     movw $2, %bx
     div  %bl
     lahf
     cmpb $2, %ah
-    jne  ncyrix
+    jne  is386
 
     /*
      * N.B. The pattern of accesses to 0x22 and 0x23 is *essential*
      *      so do not try to "optimize" it! For the same reason we
      *      do all this with interrupts off.
@@ -182,33 +182,29 @@ is486x:
     getCx86 ($0xE8)         /* now we can get CCR4 */
     orw $0x80, %ax          /* and set bit 7 (CPUIDEN) */
     movw %ax, %bx           /* to enable CPUID execution */
     setCx86 ($0xE8, %bx)
 
-    getCx86 ($0xFE)         /* DIR0 : let's check this is a 6x86(L) */
+    /* Must check cpu id regs here and not after trying to set CCR3
+     * to avoid failure when testing SG Microelectronic STPCs, which
+     * lock up if you try to enable cpuid execution
+     */
+
+    getCx86 ($0xFE)         /* DIR0 : let's check if this is a 6x86(L) */
     andw $0xF0, %ax         /* should be 3xh */
-    cmpw $0x30, %ax
-    jne n6x86
+    cmpw $0x30, %ax         /* STPCs return 0x80, 0x1a, 0x1b or 0x1f */
+    jne  is386
+
     getCx86 ($0xE9)         /* CCR5 : we reset the SLOP bit */
     andw $0xFD, %ax         /* so that udelay calculation */
     movw %ax, %bx           /* is correct on 6x86(L) CPUs */
     setCx86 ($0xE9, %bx)
 
     setCx86 ($0xC3, %cx)    /* Restore old CCR3 */
     sti
     jmp isnew               /* We enabled CPUID now */
 
-n6x86:
-    setCx86 ($0xC3, %cx)    /* Restore old CCR3 */
-    sti
-
-ncyrix:
-    popfl                   /* restore original EFLAGS */
-    call check_x87
-    popl %ebx
-    jmp  end_CheckCpuType
-
 is386:
     popfl                   /* restore original EFLAGS */
     call check_x87
 
 end_CheckCpuType:
diff -aprNU5 watt/src/djimport.c wattcp.q2dos/src/djimport.c
--- watt/src/djimport.c	2004-11-17 19:08:02 +0100
+++ wattcp.q2dos/src/djimport.c	2015-11-14 22:32:52 +0100
@@ -422,11 +422,11 @@ static void *open_module (const char *mo
   sym->_go32_dpmi_lock_code                        = _go32_dpmi_lock_code;
   sym->_go32_dpmi_lock_data                        = _go32_dpmi_lock_data;
   sym->_go32_info_block                            = _go32_info_block;
   sym->_go32_want_ctrl_break                       = _go32_want_ctrl_break;
   sym->_write                                      = _write;
-  sym->access                                      = access;
+  sym->_chmod                                      = _chmod;
   sym->atexit                                      = atexit;
   sym->atoi                                        = atoi;
   sym->atol                                        = atol;
   sym->bsearch                                     = bsearch;
   sym->calloc                                      = calloc;
diff -aprNU5 watt/src/dxe_sym.h wattcp.q2dos/src/dxe_sym.h
--- watt/src/dxe_sym.h	2004-07-25 20:14:06 +0200
+++ wattcp.q2dos/src/dxe_sym.h	2015-11-14 22:32:52 +0100
@@ -120,11 +120,11 @@ struct st_symbol
   int            (*_go32_dpmi_free_real_mode_callback) (_go32_dpmi_seginfo *);
   int            (*_go32_dpmi_lock_code) (void *, unsigned long);
   int            (*_go32_dpmi_lock_data) (void *, unsigned long);
   void           (*_go32_want_ctrl_break) (int);
   ssize_t        (*_write) (int, const void *, size_t);
-  int            (*access) (const char *, int);
+  int            (*_chmod) (const char *, int, ...);
   int            (*atexit) (void (*func)(void));
   int            (*atoi) (const char *);
   long           (*atol) (const char *);
   void          *(*bsearch) (const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
   void          *(*calloc) (size_t, size_t);
@@ -284,11 +284,11 @@ extern struct st_symbol_t import_export;
 #define _go32_dpmi_lock_code                        import_export._go32_dpmi_lock_code
 #define _go32_dpmi_lock_data                        import_export._go32_dpmi_lock_data
 #define _go32_info_block                            import_export._go32_info_block
 #define _go32_want_ctrl_break                       import_export._go32_want_ctrl_break
 #define _write                                      import_export._write
-#define access                                      import_export.access
+#define _chmod                                      import_export._chmod
 #define atexit                                      import_export.atexit
 #define atoi                                        import_export.atoi
 #define atol                                        import_export.atol
 #define bsearch                                     import_export.bsearch
 #define calloc                                      import_export.calloc
diff -aprNU5 watt/src/gethost.c wattcp.q2dos/src/gethost.c
--- watt/src/gethost.c	2005-11-30 22:33:30 +0100
+++ wattcp.q2dos/src/gethost.c	2015-11-14 22:32:52 +0100
@@ -560,11 +560,11 @@ static BOOL gethostbyaddr_internal (cons
 
   for (h = host0; h; h = h->h_next)
   {
     int i;
 
-    for (i = 0; h->h_address[i] != INADDR_NONE && i < h->h_num_addr; i++)
+    for (i = 0; i < h->h_num_addr && h->h_address[i] != INADDR_NONE; i++)
     {
       if (addr == h->h_address[i])
       {
         /* if cached entry expired, do a new reverse lookup
          */
diff -aprNU5 watt/src/getnet.c wattcp.q2dos/src/getnet.c
--- watt/src/getnet.c	2005-10-11 23:17:18 +0200
+++ wattcp.q2dos/src/getnet.c	2015-11-14 22:32:52 +0100
@@ -177,11 +177,11 @@ struct netent * W32_CALL getnetent (void
   struct _netent n;
   char  *name, *net, *alias;
   char   buf [2*MAX_NAMELEN], *tok;
   int    i;
 
-  if (!netdb_init())
+  if (!netdb_init() || !networkFile)
      return (NULL);
 
   while (1)
   {
     if (!fgets(buf,sizeof(buf),networkFile))
diff -aprNU5 watt/src/get_ai.c wattcp.q2dos/src/get_ai.c
--- watt/src/get_ai.c	2006-01-06 23:42:12 +0100
+++ wattcp.q2dos/src/get_ai.c	2015-11-14 22:32:52 +0100
@@ -520,14 +520,15 @@ bad:
  */
 static int explore_fqdn (const struct addrinfo *pai, const char *hostname,
                          const char *servname, struct addrinfo **res)
 {
   const struct afd *afd;
-  struct hostent   *hp;
+  struct hostent  copy, *hp;
   struct addrinfo sentinel, *cur;
-  int    error, af, i;
-  char  *ap;
+  struct in6_addr addr [MAX_ADDRESSES+1];
+  char           *list [MAX_ADDRESSES+1], *ap;
+  int             af, i, error;
 
 #ifdef TEST_PROG
   SOCK_DEBUGF (("\nexplore_fqdn"));
 #endif
 
@@ -586,27 +587,21 @@ static int explore_fqdn (const struct ad
 
   /* Perform a shallow copy of 'hp'. Since 'hp' is returned from
    * fill_hostent(), the contents will be destroyed in below
    * get_name() otherwise.
    */
+  copy = *hp;
+  memset (&addr, 0, sizeof(addr));
+  memset (&list, 0, sizeof(list));
+  for (i = 0; hp->h_addr_list[i]; i++)
   {
-    struct hostent copy;
-    struct in6_addr addr [MAX_ADDRESSES+1];
-    char           *list [MAX_ADDRESSES+1];
-
-    copy = *hp;
-    memset (&addr, 0, sizeof(addr));
-    memset (&list, 0, sizeof(list));
-    for (i = 0; hp->h_addr_list[i]; i++)
-    {
-      memcpy (&addr[i], hp->h_addr_list[i], hp->h_length);
-      list[i] = (char*) &addr[i];
-    }
-    list[i]          = NULL;
-    copy.h_addr_list = list;
-    hp = &copy;
+    memcpy (&addr[i], hp->h_addr_list[i], hp->h_length);
+    list[i] = (char*) &addr[i];
   }
+  list[i]          = NULL;
+  copy.h_addr_list = list;
+  hp = &copy;
 
   for (i = 0; hp->h_addr_list[i]; i++)
   {
     af = hp->h_addrtype;
     ap = hp->h_addr_list[i];
diff -aprNU5 watt/src/ioport.h wattcp.q2dos/src/ioport.h
--- watt/src/ioport.h	2003-11-13 23:57:54 +0100
+++ wattcp.q2dos/src/ioport.h	2015-11-14 22:32:52 +0100
@@ -59,39 +59,39 @@
 
 #if defined (__EMX__)
 
 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
 
-extern __inline__ unsigned char inportb (unsigned short port)
+_W32_EXTERN_INLINE unsigned char inportb (unsigned short port)
 {
   unsigned char rc;
   __asm__ __volatile__ (
             "inb %1, %0"
           : "=a" (rc)
           : "dN" (port));
   return (rc);
 }
 
-extern __inline__ unsigned short inportw (unsigned short port)
+_W32_EXTERN_INLINE unsigned short inportw (unsigned short port)
 {
   unsigned short rc;
   __asm__ __volatile__ (
             "inw %1, %0"
           : "=a" (rc)
           : "dN" (port));
   return (rc);
 }
 
-extern __inline__ void outportb (unsigned short port, unsigned char data)
+_W32_EXTERN_INLINE void outportb (unsigned short port, unsigned char data)
 {
   __asm__ __volatile__ (
              "outb %1, %0"
           :: "dN" (port),
              "a" (data));
 }
 
-extern __inline__ void outportw (unsigned short port, unsigned short data)
+_W32_EXTERN_INLINE void outportw (unsigned short port, unsigned short data)
 {
   __asm__ __volatile__ (
              "outw %1, %0"
           :: "dN" (port),
              "a" (data));
diff -aprNU5 watt/src/ip4_frag.c wattcp.q2dos/src/ip4_frag.c
--- watt/src/ip4_frag.c	2005-05-14 14:37:20 +0200
+++ wattcp.q2dos/src/ip4_frag.c	2015-11-14 22:32:52 +0100
@@ -49,12 +49,12 @@
 #include "netaddr.h"
 #include "ip4_in.h"
 #include "ip4_out.h"
 #include "ip4_frag.h"
 
-#define MAX_IP_FRAGS     2   /* max # of fragmented IP-packets */
-#define MAX_IP_HOLDTIME  15  /* time (in sec) to hold before discarding */
+#define MAX_IP_FRAGS     64 // FS: Was 2   /* max # of fragmented IP-packets */
+#define MAX_IP_HOLDTIME  120 // FS: Was 15  /* time (in sec) to hold before discarding */
 
 int _ip4_frag_reasm = MAX_IP_HOLDTIME;
 
 #if defined(USE_FRAGMENTS)
 
diff -aprNU5 watt/src/misc.c wattcp.q2dos/src/misc.c
--- watt/src/misc.c	2006-01-15 05:27:48 +0100
+++ wattcp.q2dos/src/misc.c	2015-11-14 22:32:52 +0100
@@ -1638,14 +1638,16 @@ static void stk_overflow (void _far *whe
 #undef _w32_CPUMODEL_H
 #undef _w32_MISC_H
 #undef _w32_IOPORT_H
 #undef BEEP
 #undef WIN_ASSERT
+#undef _W32_EXTERN_INLINE
 
 #define extern
 #define __inline__
 #define __inline
+#define _W32_EXTERN_INLINE
 
 #if defined(__MINGW32__) || defined(__CYGWIN__)
   #undef intel
   #undef intel16
   #define __NO_INLINE__  /* emulate -O0 */
diff -aprNU5 watt/src/misc.h wattcp.q2dos/src/misc.h
--- watt/src/misc.h	2006-01-12 23:06:34 +0100
+++ wattcp.q2dos/src/misc.h	2015-11-14 22:32:52 +0100
@@ -728,33 +728,33 @@ extern const char *short_strerror (int e
   /* Borrowed from djgpp's <sys/farptr.h>
    * Needed in pkt_receiver_pm() because djgpp 2.03 doesn't
    * save/restore FS/GS registers in the rmode callback stub.
    * Not needed if 'USE_FAST_PKT' is used.
    */
-  extern __inline__ WORD get_fs_reg (void)
+  _W32_EXTERN_INLINE WORD get_fs_reg (void)
   {
      WORD sel;
      __asm__ __volatile__ (
              "movw %%fs, %w0"
            : "=r" (sel) : );
      return (sel);
   }
-  extern __inline__ WORD get_gs_reg (void)
+  _W32_EXTERN_INLINE WORD get_gs_reg (void)
   {
      WORD sel;
      __asm__ __volatile__ (
              "movw %%gs, %w0"
            : "=r" (sel) : );
      return (sel);
   }
-  extern __inline__ void set_fs_reg (WORD sel)
+  _W32_EXTERN_INLINE void set_fs_reg (WORD sel)
   {
     __asm__ __volatile__ (
             "movw %w0, %%fs"
          :: "rm" (sel));
   }
-  extern __inline__ void set_gs_reg (WORD sel)
+  _W32_EXTERN_INLINE void set_gs_reg (WORD sel)
   {
     __asm__ __volatile__ (
             "movw %w0, %%gs"
          :: "rm" (sel));
   }
diff -aprNU5 watt/src/netaddr.c wattcp.q2dos/src/netaddr.c
--- watt/src/netaddr.c	2005-12-14 00:18:58 +0100
+++ wattcp.q2dos/src/netaddr.c	2015-11-14 22:32:52 +0100
@@ -203,11 +203,11 @@ const char *_inet_atoeth (const char *sr
   BYTE *eth = (BYTE*)p_eth;
 
 #if (DOSX)
   int tmp [sizeof(eth_address)];
 
-  if (!sscanf(src,"%02x:%02x:%02x:%02x:%02x:%02x",
+  if (sscanf(src,"%02x:%02x:%02x:%02x:%02x:%02x",
               &tmp[0], &tmp[1], &tmp[2],
               &tmp[3], &tmp[4], &tmp[5]) != DIM(tmp))
      return (NULL);
 
   eth [0] = tmp [0];
diff -aprNU5 watt/src/packet32.c wattcp.q2dos/src/packet32.c
--- watt/src/packet32.c	2005-02-19 18:05:50 +0100
+++ wattcp.q2dos/src/packet32.c	2015-11-14 22:32:52 +0100
@@ -45,11 +45,11 @@
 #include "misc.h"
 #include "timer.h"
 #include "strings.h"
 #include "pcconfig.h"
 #include "pcdbug.h"
-#include "NtddNdis.h"
+#include "ntddndis.h"
 #include "cpumodel.h"
 #include "packet32.h"
 
 #if defined(USE_DYN_PACKET)
 struct dyn_table dyn_funcs;
diff -aprNU5 watt/src/pcarp.c wattcp.q2dos/src/pcarp.c
--- watt/src/pcarp.c	2005-10-13 21:17:12 +0200
+++ wattcp.q2dos/src/pcarp.c	2015-11-14 22:32:52 +0100
@@ -657,11 +657,11 @@ static void arp_check_timeouts (BOOL che
 struct route_entry  {
        DWORD  host_ip; /* when connection to this host ... */
        DWORD  gate_ip; /* ... we use this gateway */
      };
 
-#define route_top_of_cache    32
+#define route_top_of_cache    1024 // FS: Was 32
 #define route_top_pending     route_top_of_cache
 #define route_top_free        route_first_pending
 #define route_top_dynamic     route_first_free
 #define route_first_dynamic   0
 
diff -aprNU5 watt/src/pcconfig.c wattcp.q2dos/src/pcconfig.c
--- watt/src/pcconfig.c	2005-10-01 19:10:54 +0200
+++ wattcp.q2dos/src/pcconfig.c	2015-11-14 22:32:52 +0100
@@ -582,11 +582,15 @@ static long do_include_file (const char
   {
     CONFIG_DBG_MSG (2, ("Skipping include file `%s'\n", p));
     return (0);
   }
 
+#ifdef __DJGPP__
+  if (_chmod(p, 0) != -1)
+#else
   if (access(p, 0) == 0)
+#endif
   {
     /* Recursion, but we're reentrant.
      * !!Fix-me: recursion depth should be limited.
      */
     UINT  tmp_line = current_line;
@@ -1063,12 +1067,16 @@ int tcp_config_name (char *name, int max
     {
       *temp++ = '\\';
       *temp = '\0';
     }
   }
-  else if (access(config_name,0) == 0)  /* found in current directory */
-  {
+#ifdef __DJGPP__
+  else if (_chmod(config_name,0) != -1)
+#else
+  else if (access(config_name,0) == 0)
+#endif
+  { /* found in current directory */
     strcpy (name, ".\\");
     path = name;
   }
   else if (_watt_os_ver >= 0x300)  /* not found, get path from argv[0] */
   {
@@ -1131,11 +1139,15 @@ long tcp_config (const char *path)
   }
   else
   {
     fname = name;
     StrLcpy (name, path, sizeof(name));
+#ifdef __DJGPP__
+    if (_chmod(fname,0) == -1)
+#else
     if (access(fname,0) != 0)
+#endif
        goto not_found;
   }
 
   if (!FOPEN(file,fname))  /* shouldn't happen */
      goto not_found;
diff -aprNU5 watt/src/pcdhcp.c wattcp.q2dos/src/pcdhcp.c
--- watt/src/pcdhcp.c	2005-06-30 22:47:22 +0200
+++ wattcp.q2dos/src/pcdhcp.c	2015-11-14 22:32:52 +0100
@@ -58,10 +58,15 @@
  *    Riccardo De Agostini contibuted changes for application hooking of
  *    transient configuration; dhcp_set_config_func() etc.
  *
  *  \version 0.93: Jul 2, 2004:
  *    Fixed logic around reading transient config.
+ *
+ *  \version 0.94: Oct 22, 2007:
+ *    Fixes for Linux dhcp servers: parse dhcp options in ACK msgs.
+ *    Changed DHCP_do_boot() to handle renew and rebind as well as init.
+ *    Renegotiate lease if past the renew or rebind times.
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -329,17 +334,22 @@ static int DHCP_request (BOOL renew)
 
   /* Some DHCP-daemons require this tag in a REQUEST.
    */
   opt = put_hardware_opt (opt);
 
+/* ... don't know why we would ever renew a lease
+ * for the time remaining on our current lease...
+ */
+#if 0
   if (dhcp_iplease && dhcp_iplease < (DWORD)-1)
   {
     *opt++ = DHCP_OPT_IP_ADDR_LEASE_TIME;
     *opt++ = sizeof (dhcp_iplease);
     *(DWORD*)opt = intel (dhcp_iplease);
     opt += sizeof (dhcp_iplease);
   }
+#endif
 
   if (user_class.data)
   {
     *opt++ = DHCP_OPT_USER_CLASS;
     *opt++ = user_class.size;
@@ -689,11 +699,11 @@ static int DHCP_is_nack (void)
  */
 void DHCP_release (BOOL force)
 {
   if (force)
   {
-    TRACE (("Sending DHCP release\n"));
+    TRACE (("Sending DHCP release 01\n"));
     DHCP_release_decline (DHCP_RELEASE, NULL);
   }
   else if (configured)
   {
     /* Don't release if:
@@ -701,11 +711,11 @@ void DHCP_release (BOOL force)
      *   above minimum.
      */
     if (!(cfg_saved &&
           (lease_timeout && (lease_timeout - time(NULL) > DHCP_MIN_LEASE))))
     {
-      TRACE (("Sending DHCP release\n"));
+      TRACE (("Sending DHCP release 02\n"));
       DHCP_release_decline (DHCP_RELEASE, NULL);
     }
   }
   delwattcpd (dhcp_fsm);
   if (sock)
@@ -780,11 +790,11 @@ static void DHCP_state_BOUND (int event)
   if (event == EVENT_T1_TIMEOUT) /* renewal timeout */
   {
     old_ip_addr = my_ip_addr;    /* remember current address */
     got_offer   = FALSE;
 
-    TRACE (("Sending DHCP request\n"));
+    TRACE (("Sending DHCP request 01\n"));
     DHCP_request (1);
     DHCP_state = DHCP_state_RENEWING;
   }
 }
 
@@ -796,27 +806,37 @@ static void DHCP_state_BOUND (int event)
  */
 static void DHCP_state_REQUESTING (int event)
 {
   if (event == EVENT_SEND_TIMEOUT)
   {
-    TRACE (("Sending DHCP request\n"));
+    TRACE (("Sending DHCP request 00\n"));
     DHCP_request (0);
+
+    /*UPDATE: 05MAR2006 paul.suggs@vgt.net
+     *  There is a timing condition within the FSM where the state has changed
+     *  to REQUESTING but in dhcp_fsm(), chk_timeout() will be evaluated true
+     *  which sets send_timeout to 0 before the first execution of this state
+     *  handler. Once set to 0, we have to wait for rollover to resend the
+     *  above request if it is lost for some reason
+     */
+    send_timeout = set_timeout (Random(4000,6000));
   }
   else if (event == EVENT_ACK)
   {
-    TRACE (("Got DHCP ack\n"));
+    TRACE (("Got DHCP ack while requesting\n"));
 
     if (!DHCP_arp_check(my_ip_addr))
     {
       my_ip_addr = 0;     /* decline from 0.0.0.0 */
       DHCP_release_decline (DHCP_DECLINE, "IP is not free");
       send_timeout = set_timeout (Random(4000,6000));
       DHCP_state   = DHCP_state_INIT;
     }
     else
     {
-      configured = 1;     /* we are (re)configured */
+      DHCP_offer (&dhcp_in);  /* parse options in the ack too */
+      configured = 1;         /* we are (re)configured */
       if (dhcp_server)
          arp_add_server();
       dhcp_set_timers();
       send_timeout = 0UL;
       DHCP_state   = DHCP_state_BOUND;
@@ -837,12 +857,13 @@ static void DHCP_state_REQUESTING (int e
  */
 static void DHCP_state_REBINDING (int event)
 {
   if (event == EVENT_ACK)
   {
-    TRACE (("Got DHCP ack\n"));
+    TRACE (("Got DHCP ack while rebinding\n"));
     dhcp_set_timers();
+    DHCP_offer (&dhcp_in);
     change_ip_addr();
     DHCP_state = DHCP_state_BOUND;
   }
   else if (event == EVENT_NAK)
   {
@@ -861,30 +882,31 @@ static void DHCP_state_REBINDING (int ev
  */
 static void DHCP_state_RENEWING (int event)
 {
   if (event == EVENT_SEND_TIMEOUT)
   {
-    TRACE (("Sending DHCP request\n"));
+    TRACE (("Sending DHCP request for renew\n"));
     DHCP_request (1);
   }
   else if (event == EVENT_T2_TIMEOUT)
   {
-    TRACE (("Sending DHCP request\n"));
+    TRACE (("Sending DHCP request for rebind\n"));
     bcast_flag = TRUE;
     DHCP_request (1);
     DHCP_state = DHCP_state_REBINDING;
   }
   else if (event == EVENT_ACK)
   {
-    TRACE (("Got DHCP ack\n"));
+    TRACE (("Got DHCP ack while renewing\n"));
     dhcp_set_timers();
+    DHCP_offer (&dhcp_in);
     change_ip_addr();
     DHCP_state = DHCP_state_BOUND;
   }
   else if (event == EVENT_NAK)
   {
-    TRACE (("Got DHCP nack\n"));
+    TRACE (("Got DHCP nack while renewing\n"));
     send_timeout = set_timeout (Random(4000,6000));
     my_ip_addr = 0;
     DHCP_state = DHCP_state_INIT;
   }
 }
@@ -1012,16 +1034,16 @@ static void dhcp_fsm (void)
     (*DHCP_state) (EVENT_T2_TIMEOUT);
   }
 }
 
 /**
- * Our first time (booting) DHCP handler.
- * Only called if:
+ * Our first time DHCP handler.
+ * Called if:
  *  - we don't have a WATTCP.CFG file
  *  - or we specified "MY_IP = DHCP".
  *  - or reading a previous W32DHCP.TMP file with transient config failed.
- *
+ *  - or lease times call for a renew or rebind.
  * It doesn't hurt that it is blocking.
  */
 int DHCP_do_boot (void)
 {
   int save_mtu = _mtu;
@@ -1033,22 +1055,30 @@ int DHCP_do_boot (void)
   if (!sock)
      sock = dhcp_open (NULL, bcast_flag);
   if (!sock)
      return (0);
 
+  if (DHCP_state != DHCP_state_RENEWING &&
+      DHCP_state != DHCP_state_REBINDING)
+  {
+    my_ip_addr = 0;
+    sin_mask   = 0;
+  }
+
   _mtu = ETH_MAX_DATA;
-  my_ip_addr = 0;
-  sin_mask   = 0;
   discover_loops = 0;
 
   erase_config();         /* delete old configuration */
   addwattcpd (dhcp_fsm);  /* add "background" daemon */
 
   /* kick start DISCOVER message
    */
   send_timeout = set_timeout (100);
-  DHCP_state = DHCP_state_INIT;
+
+  if (DHCP_state != DHCP_state_RENEWING &&
+      DHCP_state != DHCP_state_REBINDING)
+     DHCP_state = DHCP_state_INIT;
 
   while (DHCP_state != DHCP_state_BOUND)
   {
     tcp_tick (NULL);
     if (discover_loops >= max_retries)  /* retries exhaused */
@@ -1449,19 +1479,21 @@ static BOOL eval_timers (void)
   }
 
   if (now >= cfg_dhcp_renewal && now < cfg_dhcp_rebind)
   {
     TRACE (("DHCP: RENEWING\n"));
-    DHCP_state_BOUND (EVENT_T1_TIMEOUT);    /* goto RENEWING */
-    return (TRUE);
+    DHCP_state = DHCP_state_BOUND;
+    (*DHCP_state) (EVENT_T1_TIMEOUT);       /* goto RENEWING */
+    return (FALSE);
   }
 
   if (now >= cfg_dhcp_rebind && now < cfg_dhcp_iplease)
   {
     TRACE (("DHCP: REBINDING\n"));
-    DHCP_state_RENEWING (EVENT_T2_TIMEOUT); /* goto REBINDING */
-    return (TRUE);
+    DHCP_state = DHCP_state_RENEWING;
+    (*DHCP_state) (EVENT_T2_TIMEOUT);       /* goto REBINDING */
+    return (FALSE);
   }
   return (FALSE);
 }
 
 /**
@@ -1541,12 +1573,16 @@ static int std_write_config (void)
   FILE  *file;
   time_t tim, now = time (NULL);
   int    rc  = 0;
   const  char *fname = get_config_file();
 
-  if (access(fname,0))  /* file not found, create */
-  {
+#ifdef __DJGPP__
+  if (_chmod(fname,0) == -1)
+#else
+  if (access(fname,0) != 0)
+#endif
+  { /* file not found, create */
     file = fopen (fname, "w+t");
     if (!file)
        goto fail;
 
     rc = fprintf (file,
diff -aprNU5 watt/src/pcsarp.c wattcp.q2dos/src/pcsarp.c
--- watt/src/pcsarp.c	2005-10-01 19:18:34 +0200
+++ wattcp.q2dos/src/pcsarp.c	2015-11-14 22:32:52 +0100
@@ -83,11 +83,15 @@ int sarp_init (void)
   prev_cfg_hook   = usr_init;
   usr_init        = sarp_parse;
   _sarp_recv_hook = sarp_receive;
   _sarp_xmit_hook = sarp_transmit;
 
+#ifdef __DJGPP__
+  if (rand && _chmod(rand,0) !=-1)
+#else
   if (rand && access(rand,0) == 0)
+#endif
        RAND_load_file (rand, -1);
   else SARP_DEBUG (0, ("Warning: No random seed file found\n"));
   return (0);
 }
 
diff -aprNU5 watt/src/pctcp.c wattcp.q2dos/src/pctcp.c
--- watt/src/pctcp.c	2005-12-05 00:32:06 +0100
+++ wattcp.q2dos/src/pctcp.c	2015-11-14 22:32:52 +0100
@@ -1637,14 +1637,13 @@ static void sock_reduce_mss (sock_type *
  * or host/port UNREACH. See icmp_redirect() or icmp_handler().
  */
 void _udp_cancel (const in_Header *ip, int icmp_type, int icmp_code,
                   const char *msg, const void *arg) /* use a var-arg here ? */
 {
-  WORD         src_port, dst_port, next_mtu;
-  DWORD        gateway;
-  int          len     = in_GetHdrLen (ip);
+  WORD         src_port, dst_port;
   BOOL         passive = FALSE;
+  int          len     = in_GetHdrLen (ip);
   udp_Header  *udp     = (udp_Header*) ((BYTE*)ip + len);
   _udp_Socket *s;
 
   SIO_TRACE (("_udp_cancel"));
 
@@ -1669,28 +1668,31 @@ void _udp_cancel (const in_Header *ip, i
 
   if (s)
   {
     SET_ERR_MSG (s, msg);
 
-    /* handle redirect on active sockets
+    /* handle ICMP-errors on active sockets
      */
     if (icmp_type == ICMP_REDIRECT && !passive)
     {
+      DWORD gateway;
+
       WATT_ASSERT (arg != NULL);
       gateway = *(DWORD*)arg;
       _ip_recursion = 1;
       _arp_resolve (gateway, &s->his_ethaddr);
       _ip_recursion = 0;
     }
-    else if (icmp_type == ICMP_UNREACH && icmp_code == ICMP_UNREACH_NEEDFRAG)
+    else if (icmp_type == ICMP_UNREACH && icmp_code == ICMP_UNREACH_NEEDFRAG && !passive)
     {
+      WORD next_mtu;
+
       WATT_ASSERT (arg != NULL);
       next_mtu = *(WORD*) arg;
-      if (!passive)
-         sock_reduce_mss ((sock_type*)s, next_mtu);
+      sock_reduce_mss ((sock_type*)s, next_mtu);
     }
-    else if (icmp_type != ICMP_TIMXCEED)
+    else if (icmp_type != ICMP_TIMXCEED && !passive)
     {
       /* UDP isn't sturdy, close it on 1st ICMP error
        */
       SET_ERR_MSG (s, _LANG("Port unreachable"));
       s->ip_type   = 0;
diff -aprNU5 watt/src/ppp.c wattcp.q2dos/src/ppp.c
--- watt/src/ppp.c	2004-11-17 20:59:54 +0100
+++ wattcp.q2dos/src/ppp.c	2015-11-14 22:32:52 +0100
@@ -1091,11 +1091,11 @@ static void std_negotiation (struct ppp_
     return;
   }
 
   code   = *state->bp++;
   id     = *state->bp++;
-  length = intel16 (*(WORD*)&state->bp);
+  length = intel16 (*(WORD*)state->bp);  /* !! */
   if (length > state->mlen)
   {
     PRINTF (0, ("Truncated negotiation message; %d > %d\n",
                 length, state->mlen));
     return;
@@ -1172,11 +1172,11 @@ static void std_negotiation (struct ppp_
          else
            send_event (state, xcp, evRXJp);
          break;
 
     case CODE_PROTO_REJ:
-         proto = intel16 (*(WORD*)&state->bp);
+         proto = intel16 (*(WORD*)state->bp);  /* !! */
 
          /* Peer cannot reject LCP!
           */
          if (proto == state->xcps[XCP_LCP].proto)
          {
diff -aprNU5 watt/src/presaddr.c wattcp.q2dos/src/presaddr.c
--- watt/src/presaddr.c	2005-05-07 00:43:18 +0200
+++ wattcp.q2dos/src/presaddr.c	2015-11-14 22:32:52 +0100
@@ -325,11 +325,11 @@ static int inet_pton6 (const char *src,
       }
       if (tp + INT16SZ > endp)
          return (0);
 
       *tp++ = (u_char) (val >> 8) & 0xff;
-      *tp++ = (u_char) val & 0xff;
+      *tp++ = (u_char) (val & 0xff);
       saw_xdigit = 0;
       val = 0;
       continue;
     }
     if (ch == '.' && ((tp + INADDRSZ) <= endp) && inet_pton4(curtok,tp) > 0)
diff -aprNU5 watt/src/printk.c wattcp.q2dos/src/printk.c
--- watt/src/printk.c	2004-08-24 09:18:36 +0200
+++ wattcp.q2dos/src/printk.c	2015-11-14 22:32:54 +0100
@@ -126,14 +126,16 @@ void _printk_flush (void)
 
 static void printk_exit (void)
 {
   _printk_flush();
   if (_printk_file && _printk_file != stderr && _printk_file != stdout)
-  {
     fclose (_printk_file);
-    _printk_file = NULL;
-  }
+  _printk_file = NULL;
+
+  if (printk_buf)
+     free (printk_buf);  /* Reclaim memory allocated in _printk_init() */
+  printk_buf = NULL;
 }
 
 /*
  * Called from openlog() to allocate print-buffer and
  * optionally open a file. If file == NULL, print to stderr.
diff -aprNU5 watt/src/tcp_fsm.c wattcp.q2dos/src/tcp_fsm.c
--- watt/src/tcp_fsm.c	2005-10-20 23:04:18 +0200
+++ wattcp.q2dos/src/tcp_fsm.c	2015-11-14 22:32:54 +0100
@@ -1058,11 +1058,11 @@ static int tcp_process_data (_tcp_Socket
 
   /* Check that _end_ of packet is valid, i.e. will fit in advertised window.
    * If it's before recv_next, we've seen it all before; if it's after
    * then the peer (or someone else) sent more than we said we could take.
    */
-  if ((unsigned)len - ldiff > s->adv_win)
+  if ((unsigned)len - ldiff > s->max_rx_data - s->rx_datalen)
   {
     TCP_TRACE (("tcp_ProcessData (%u): packet ends outside %lu/%lu\n",
                 __LINE__, s->recv_next, s->recv_next + s->adv_win));
     return (0);
   }
@@ -1208,11 +1208,11 @@ static int tcp_reassemble (_tcp_Socket *
     /* normal enqueue */
     return (0);
   }
 
   left_edge  = s->recv_next - s->rx_datalen;
-  right_edge = s->recv_next + s->adv_win;
+  right_edge = s->recv_next + s->max_rx_data - s->rx_datalen;
 
   /* segment is left of expected recv-window
    */
   if(SEQ_LEQ(seqnum, left_edge) &&
      SEQ_LEQ(seqnum + len, left_edge))
diff -aprNU5 watt/src/timer.h wattcp.q2dos/src/timer.h
--- watt/src/timer.h	2004-09-02 15:55:22 +0200
+++ wattcp.q2dos/src/timer.h	2015-11-14 22:32:54 +0100
@@ -78,16 +78,18 @@ W32_FUNC void init_timer_isr (void);
 W32_FUNC void exit_timer_isr (void);
 
 W32_FUNC void init_userSuppliedTimerTick (void);
 W32_FUNC void userTimerTick (DWORD elapsedTimeMs);
 
+#if (DOSX) && defined(HAVE_UINT64)
+  extern uint64 get_cpu_speed (void);
+#endif
 
 #if defined(USE_PROFILER)
   extern BOOL   profile_enable;
   extern char   profile_file [MAX_PATHLEN+1];
 
-  extern uint64 get_cpu_speed (void);
   extern void   profile_start (const char *where);
   extern void   profile_stop  (void);
   extern int    profile_init  (void);
   extern int    profile_on    (void);
   extern void   profile_dump  (const uint64 *data, size_t num_elem);
diff -aprNU5 watt/src/wattcp.h wattcp.q2dos/src/wattcp.h
--- watt/src/wattcp.h	2006-01-12 23:05:08 +0100
+++ wattcp.q2dos/src/wattcp.h	2015-11-14 22:32:54 +0100
@@ -129,10 +129,11 @@ struct ulong_long {
 #include "target.h"          /**< portability macros & defines. */
 #include "config.h"          /**< options & features to include. */
 
 #include <sys/w32api.h>      /**< export/import decorations */
 #include <sys/werrno.h>      /**< errno stuff */
+#include <sys/cdefs.h>       /**< _EXTERN_INLINE  */
 
 #if defined(USE_CRTDBG)      /**< use CrtDebug in MSVC debug-mode */
   #define _CRTDBG_MAP_ALLOC
   #include <crtdbg.h>
 
@@ -245,11 +246,11 @@ struct ulong_long {
 #define MAX_VALUELEN      80           /**< max length of a wattcp.cfg value */
 #define MAX_PATHLEN       256          /**< should be enough for most... */
 
 #define MAX_COOKIES       10
 #define MAX_HOSTLEN       80           /**< most strings are limited */
-#define MAX_ADDRESSES     10           /**< # of addresses in resolvers */
+#define MAX_ADDRESSES     1024 // FS: Was 10           /**< # of addresses in resolvers */
 
 #define SAFETY_TCP        0x538F25A3L  /**< marker signatures */
 #define SAFETY_UDP        0x3E45E154L
 
 /**
diff -aprNU5 watt/src/winpcap.c wattcp.q2dos/src/winpcap.c
--- watt/src/winpcap.c	2006-01-25 04:07:12 +0100
+++ wattcp.q2dos/src/winpcap.c	2015-11-14 22:32:54 +0100
@@ -46,12 +46,12 @@
 #include "pcdbug.h"
 #include "pcstat.h"
 #include "pcpkt.h"
 
 #include "winpcap.h"
-#include "NtddNdis.h"
-#include "Packet32.h"
+#include "ntddndis.h"
+#include "packet32.h"
 
 #if (defined(_DLL) && !defined(_MT)) && !defined(__LCC__)
 #error This file must be compiled for threads
 #endif
 
diff -aprNU5 watt/util/errnos.c wattcp.q2dos/util/errnos.c
--- watt/util/errnos.c	2005-12-19 03:02:20 +0100
+++ wattcp.q2dos/util/errnos.c	2015-11-14 22:32:54 +0100
@@ -317,16 +317,10 @@ static const char *err_tab[] = {
 #define ADD_ERRNO(err_num)  add_errno (err_num, #err_num, strerror(err_num))
 #define NEW_ERRNO(tab_num)  add_errno (-1, NULL, err_tab[tab_num])
 
 static void process (void)
 {
-#ifdef EWOULDBLOCK
-  ADD_ERRNO (EWOULDBLOCK);
-#else
-  NEW_ERRNO (0);
-#endif
-
 #ifdef EDOM
   ADD_ERRNO (EDOM);
 #else
   NEW_ERRNO (1);
 #endif
@@ -551,10 +545,34 @@ static void process (void)
   ADD_ERRNO (ENMFILE);
 #else
   NEW_ERRNO (38);
 #endif
 
+#ifdef ELOOP
+  ADD_ERRNO (ELOOP);
+#else
+  NEW_ERRNO (89);
+#endif
+
+#ifdef EOVERFLOW
+  ADD_ERRNO (EOVERFLOW);
+#else
+  NEW_ERRNO (95);
+#endif
+
+#ifdef EILSEQ
+  ADD_ERRNO (EILSEQ);
+#else
+  NEW_ERRNO (73);
+#endif
+
+#ifdef EWOULDBLOCK
+  ADD_ERRNO (EWOULDBLOCK);
+#else
+  NEW_ERRNO (0);
+#endif
+
 #ifdef EINPROGRESS
   ADD_ERRNO (EINPROGRESS);
 #else
   NEW_ERRNO (39);
 #endif
@@ -755,16 +773,10 @@ static void process (void)
   ADD_ERRNO (EPROCUNAVAIL);
 #else
   NEW_ERRNO (72);
 #endif
 
-#ifdef EILSEQ
-  ADD_ERRNO (EILSEQ);
-#else
-  NEW_ERRNO (73);
-#endif
-
 #ifdef EINVFNC
   ADD_ERRNO (EINVFNC);
 #else
   NEW_ERRNO (74);
 #endif
@@ -851,16 +863,10 @@ static void process (void)
   ADD_ERRNO (ETOOMANYREFS);
 #else
   NEW_ERRNO (88);
 #endif
 
-#ifdef ELOOP
-  ADD_ERRNO (ELOOP);
-#else
-  NEW_ERRNO (89);
-#endif
-
 #ifdef EPROCLIM
   ADD_ERRNO (EPROCLIM);
 #else
   NEW_ERRNO (90);
 #endif
@@ -886,16 +892,10 @@ static void process (void)
 #ifdef ENORMTWD
   ADD_ERRNO (ENORMTWD);
 #else
   NEW_ERRNO (94);
 #endif
-
-#ifdef EOVERFLOW
-  ADD_ERRNO (EOVERFLOW);
-#else
-  NEW_ERRNO (95);
-#endif
 }
 
 /*
  * rip off newlines
  */
