about summary refs log tree commit diff stats
path: root/WWW/Library
diff options
context:
space:
mode:
Diffstat (limited to 'WWW/Library')
-rw-r--r--WWW/Library/Implementation/HTAnchor.c20
-rw-r--r--WWW/Library/Implementation/HTAnchor.h12
-rw-r--r--WWW/Library/Implementation/HTChunk.c19
-rw-r--r--WWW/Library/Implementation/HTChunk.h2
-rw-r--r--WWW/Library/Implementation/HTDOS.c2
-rw-r--r--WWW/Library/Implementation/HTDOS.h2
-rw-r--r--WWW/Library/Implementation/HTFile.c4
-rw-r--r--WWW/Library/Implementation/HTFormat.c179
-rw-r--r--WWW/Library/Implementation/HTFormat.h6
-rw-r--r--WWW/Library/Implementation/HTInit.h7
-rw-r--r--WWW/Library/Implementation/HTMIME.c23
-rw-r--r--WWW/Library/Implementation/HTRules.c2
-rw-r--r--WWW/Library/Implementation/HTString.c27
-rw-r--r--WWW/Library/Implementation/HTString.h11
-rw-r--r--WWW/Library/Implementation/HTTCP.c44
-rw-r--r--WWW/Library/Implementation/HTTP.c8
-rw-r--r--WWW/Library/Implementation/HTVMSUtils.c4
-rw-r--r--WWW/Library/Implementation/HTVMSUtils.h2
-rw-r--r--WWW/Library/Implementation/LYexit.h5
-rw-r--r--WWW/Library/Implementation/SGML.c34
-rw-r--r--WWW/Library/Implementation/www_tcp.h77
21 files changed, 280 insertions, 210 deletions
diff --git a/WWW/Library/Implementation/HTAnchor.c b/WWW/Library/Implementation/HTAnchor.c
index 9ca154d3..347c0f62 100644
--- a/WWW/Library/Implementation/HTAnchor.c
+++ b/WWW/Library/Implementation/HTAnchor.c
@@ -759,6 +759,10 @@ static void HTParentAnchor_free(HTParentAnchor *me)
     }
     FREE(me->SugFname);
     FREE(me->cache_control);
+#ifdef EXP_HTTP_HEADERS
+    HTChunkClear(&(me->http_headers));
+#endif
+    FREE(me->content_type_params);
     FREE(me->content_type);
     FREE(me->content_language);
     FREE(me->content_encoding);
@@ -1040,6 +1044,22 @@ const char *HTAnchor_SugFname(HTParentAnchor *me)
     return (me ? me->SugFname : NULL);
 }
 
+#ifdef EXP_HTTP_HEADERS
+/*	HTTP Headers.
+*/
+const char *HTAnchor_http_headers(HTParentAnchor *me)
+{
+    return (me ? me->http_headers.data : NULL);
+}
+#endif
+
+/*	Content-Type handling (parameter list).
+*/
+const char *HTAnchor_content_type_params(HTParentAnchor *me)
+{
+    return (me ? me->content_type_params : NULL);
+}
+
 /*	Content-Encoding handling. - FM
  *	(will be loaded if we had a Content-Encoding
  *	 header.)
diff --git a/WWW/Library/Implementation/HTAnchor.h b/WWW/Library/Implementation/HTAnchor.h
index 22a9c323..b7d4f760 100644
--- a/WWW/Library/Implementation/HTAnchor.h
+++ b/WWW/Library/Implementation/HTAnchor.h
@@ -100,6 +100,10 @@ struct _HTParentAnchor {
     char *cache_control;	/* Cache-Control */
     BOOL no_cache;		/* Cache-Control, Pragma or META "no-cache"? */
     BOOL inBASE;		/* duplicated from HTStructured (HTML.c/h) */
+#ifdef EXP_HTTP_HEADERS
+    HTChunk http_headers;
+#endif
+    char *content_type_params;	/* Content-Type (with parameters if any) */
     char *content_type;		/* Content-Type */
     char *content_language;	/* Content-Language */
     char *content_encoding;	/* Compression algorithm */
@@ -284,6 +288,14 @@ extern void HTAnchor_setCitehost(HTParentAnchor *me,
  */
 extern const char *HTAnchor_SugFname(HTParentAnchor *me);
 
+/*	HTTP Headers.
+*/
+extern const char *HTAnchor_http_headers(HTParentAnchor *me);
+
+/*	Content-Type handling (parameter list).
+*/
+extern const char *HTAnchor_content_type_params(HTParentAnchor *me);
+
 /*	Content-Type handling. - FM
 */
 extern const char *HTAnchor_content_type(HTParentAnchor *me);
diff --git a/WWW/Library/Implementation/HTChunk.c b/WWW/Library/Implementation/HTChunk.c
index a0e1dc95..dc187c3f 100644
--- a/WWW/Library/Implementation/HTChunk.c
+++ b/WWW/Library/Implementation/HTChunk.c
@@ -101,8 +101,9 @@ BOOL HTChunkRealloc(HTChunk *ch, int growby)
 
     ch->allocated = ch->allocated + growby;
 
-    data = ch->data ? (char *) realloc(ch->data, ch->allocated)
-	: typecallocn(char, ch->allocated);
+    data = (ch->data
+	    ? (char *) realloc(ch->data, ch->allocated)
+	    : typecallocn(char, ch->allocated));
 
     if (data) {
 	ch->data = data;
@@ -159,7 +160,7 @@ void HTChunkPutb(HTChunk *ch, const char *b, int l)
     ch->size += l;
 }
 
-#define PUTC(code) ch->data[ch->size++] = (char)(code)
+#define PUTC(code)  ch->data[ch->size++] = (char)(code)
 #define PUTC2(code) ch->data[ch->size++] = (char)(0x80|(0x3f &(code)))
 
 void HTChunkPutUtf8Char(HTChunk *ch, UCode_t code)
@@ -244,11 +245,13 @@ void HTChunkPuts(HTChunk *ch, const char *s)
 {
     const char *p;
 
-    for (p = s; *p; p++) {
-	if (ch->size >= ch->allocated) {
-	    if (!HTChunkRealloc(ch, ch->growby))
-		return;
+    if (s != NULL) {
+	for (p = s; *p; p++) {
+	    if (ch->size >= ch->allocated) {
+		if (!HTChunkRealloc(ch, ch->growby))
+		    return;
+	    }
+	    ch->data[ch->size++] = *p;
 	}
-	ch->data[ch->size++] = *p;
     }
 }
diff --git a/WWW/Library/Implementation/HTChunk.h b/WWW/Library/Implementation/HTChunk.h
index 8c593bca..ba28c422 100644
--- a/WWW/Library/Implementation/HTChunk.h
+++ b/WWW/Library/Implementation/HTChunk.h
@@ -20,7 +20,7 @@ typedef struct {
     int size;			/* In bytes                     */
     int growby;			/* Allocation unit in bytes     */
     int allocated;		/* Current size of *data        */
-    char *data;			/* Pointer to malloced area or 0 */
+    char *data;			/* Pointer to malloc'd area or 0 */
     int failok;			/* allowed to fail without exiting program? */
 } HTChunk;
 
diff --git a/WWW/Library/Implementation/HTDOS.c b/WWW/Library/Implementation/HTDOS.c
index 8edb0e7c..4c98d5cf 100644
--- a/WWW/Library/Implementation/HTDOS.c
+++ b/WWW/Library/Implementation/HTDOS.c
@@ -31,7 +31,7 @@ static char *copy_plus(char **result, const char *source)
  *	returns		WWW file specification
  *
  */
-char *HTDOS_wwwName(const char *dosname)
+const char *HTDOS_wwwName(const char *dosname)
 {
     static char *wwwname = NULL;
     char *cp_url = copy_plus(&wwwname, dosname);
diff --git a/WWW/Library/Implementation/HTDOS.h b/WWW/Library/Implementation/HTDOS.h
index c25f510a..a0021d0a 100644
--- a/WWW/Library/Implementation/HTDOS.h
+++ b/WWW/Library/Implementation/HTDOS.h
@@ -16,7 +16,7 @@
  *	returns		WWW file specification
  *
  */
-char *HTDOS_wwwName(const char *dosname);
+const char *HTDOS_wwwName(const char *dosname);
 
 /*
  * Converts Unix slashes to DOS
diff --git a/WWW/Library/Implementation/HTFile.c b/WWW/Library/Implementation/HTFile.c
index bc2859f5..e5f6d77d 100644
--- a/WWW/Library/Implementation/HTFile.c
+++ b/WWW/Library/Implementation/HTFile.c
@@ -669,7 +669,7 @@ char *HTnameOfFile_WWW(const char *name,
     char *acc_method = HTParse(name, "", PARSE_ACCESS);
     char *host = HTParse(name, "", PARSE_HOST);
     char *path = HTParse(name, "", PARSE_PATH + PARSE_PUNCTUATION);
-    char *home;
+    const char *home;
     char *result = NULL;
 
     if (expand_all) {
@@ -697,7 +697,7 @@ char *HTnameOfFile_WWW(const char *name,
 	    home = HTVMS_wwwName(home);
 #else
 #if defined(_WINDOWS)		/* 1997/10/16 (Thu) 20:42:51 */
-	home = (char *) Home_Dir();
+	home = Home_Dir();
 #else
 	home = LYGetEnv("HOME");
 #endif
diff --git a/WWW/Library/Implementation/HTFormat.c b/WWW/Library/Implementation/HTFormat.c
index 855d1dc0..fa9bc045 100644
--- a/WWW/Library/Implementation/HTFormat.c
+++ b/WWW/Library/Implementation/HTFormat.c
@@ -88,6 +88,7 @@ static void HTFreePresentations(void);
  */
 void HTSetPresentation(const char *representation,
 		       const char *command,
+		       const char *testcommand,
 		       double quality,
 		       double secs,
 		       double secs_per_byte,
@@ -112,6 +113,9 @@ void HTSetPresentation(const char *representation,
     pres->command = NULL;
     StrAllocCopy(pres->command, command);
 
+    pres->testcommand = NULL;
+    StrAllocCopy(pres->testcommand, testcommand);
+
     /*
      * Memory leak fixed.
      * 05-28-94 Lynx 2-3-1 Garrett Arch Blythe
@@ -151,12 +155,12 @@ void HTSetConversion(const char *representation_in,
     pres->rep = HTAtom_for(representation_in);
     pres->rep_out = HTAtom_for(representation_out);
     pres->converter = converter;
-    pres->command = NULL;	/* Fixed */
+    pres->command = NULL;
+    pres->testcommand = NULL;
     pres->quality = quality;
     pres->secs = secs;
     pres->secs_per_byte = secs_per_byte;
     pres->maxbytes = maxbytes;
-    pres->command = NULL;
     pres->get_accept = TRUE;
     pres->accept_opt = media;
 
@@ -198,6 +202,7 @@ static void HTFreePresentations(void)
 	 */
 	pres = (HTPresentation *) HTList_removeLastObject(HTPresentations);
 	FREE(pres->command);
+	FREE(pres->testcommand);
 	FREE(pres);
     }
     /*
@@ -323,6 +328,20 @@ static int half_match(char *trial_type, char *target)
     return 0;
 }
 
+/*
+ * Evaluate a deferred mailcap test command, i.e.,. one that substitutes the
+ * document's charset or other values in %{name} format.
+ */
+static BOOL failsMailcap(HTPresentation *pres, HTParentAnchor *anchor)
+{
+    if (pres->testcommand != 0) {
+	if (LYTestMailcapCommand(pres->testcommand,
+				 anchor->content_type_params) != 0)
+	    return TRUE;
+    }
+    return FALSE;
+}
+
 #define WWW_WILDCARD_REP_OUT HTAtom_for("*")
 
 /*		Look up a presentation
@@ -338,96 +357,106 @@ static int half_match(char *trial_type, char *target)
  */
 static HTPresentation *HTFindPresentation(HTFormat rep_in,
 					  HTFormat rep_out,
-					  HTPresentation *fill_in)
+					  HTPresentation *fill_in,
+					  HTParentAnchor *anchor)
 {
     HTAtom *wildcard = NULL;	/* = HTAtom_for("*"); lookup when needed - kw */
+    int n;
+    int i;
+    HTPresentation *pres;
+    HTPresentation *match;
+    HTPresentation *strong_wildcard_match = 0;
+    HTPresentation *weak_wildcard_match = 0;
+    HTPresentation *last_default_match = 0;
+    HTPresentation *strong_subtype_wildcard_match = 0;
 
     CTRACE((tfp, "HTFormat: Looking up presentation for %s to %s\n",
 	    HTAtom_name(rep_in), HTAtom_name(rep_out)));
 
-    /* don't do anymore do it in the Lynx code at startup LJM */
-/* if (!HTPresentations) HTFormatInit(); *//* set up the list */
-
-    {
-	int n = HTList_count(HTPresentations);
-	int i;
-	HTPresentation *pres;
-	HTPresentation *match;
-	HTPresentation *strong_wildcard_match = 0;
-	HTPresentation *weak_wildcard_match = 0;
-	HTPresentation *last_default_match = 0;
-	HTPresentation *strong_subtype_wildcard_match = 0;
-
-	for (i = 0; i < n; i++) {
-	    pres = (HTPresentation *) HTList_objectAt(HTPresentations, i);
-	    if (pres->rep == rep_in) {
-		if (pres->rep_out == rep_out) {
-		    CTRACE((tfp, "FindPresentation: found exact match: %s\n",
-			    HTAtom_name(pres->rep)));
-		    return pres;
-
-		} else if (!fill_in) {
+    n = HTList_count(HTPresentations);
+    for (i = 0; i < n; i++) {
+	pres = (HTPresentation *) HTList_objectAt(HTPresentations, i);
+	if (pres->rep == rep_in) {
+	    if (pres->rep_out == rep_out) {
+		if (failsMailcap(pres, anchor))
 		    continue;
-		} else {
-		    if (!wildcard)
-			wildcard = WWW_WILDCARD_REP_OUT;
-		    if (pres->rep_out == wildcard) {
-			if (!strong_wildcard_match)
-			    strong_wildcard_match = pres;
-			/* otherwise use the first one */
-			CTRACE((tfp,
-				"StreamStack: found strong wildcard match: %s\n",
-				HTAtom_name(pres->rep)));
-		    }
-		}
+		CTRACE((tfp, "FindPresentation: found exact match: %s\n",
+			HTAtom_name(pres->rep)));
+		return pres;
 
 	    } else if (!fill_in) {
 		continue;
-
-	    } else if (half_match(HTAtom_name(pres->rep),
-				  HTAtom_name(rep_in))) {
-		if (pres->rep_out == rep_out) {
-		    if (!strong_subtype_wildcard_match)
-			strong_subtype_wildcard_match = pres;
+	    } else {
+		if (!wildcard)
+		    wildcard = WWW_WILDCARD_REP_OUT;
+		if (pres->rep_out == wildcard) {
+		    if (failsMailcap(pres, anchor))
+			continue;
+		    if (!strong_wildcard_match)
+			strong_wildcard_match = pres;
 		    /* otherwise use the first one */
 		    CTRACE((tfp,
-			    "StreamStack: found strong subtype wildcard match: %s\n",
+			    "StreamStack: found strong wildcard match: %s\n",
 			    HTAtom_name(pres->rep)));
 		}
 	    }
 
-	    if (pres->rep == WWW_SOURCE) {
-		if (pres->rep_out == rep_out) {
-		    if (!weak_wildcard_match)
-			weak_wildcard_match = pres;
-		    /* otherwise use the first one */
-		    CTRACE((tfp,
-			    "StreamStack: found weak wildcard match: %s\n",
-			    HTAtom_name(pres->rep_out)));
-
-		} else if (!last_default_match) {
-		    if (!wildcard)
-			wildcard = WWW_WILDCARD_REP_OUT;
-		    if (pres->rep_out == wildcard)
-			last_default_match = pres;
-		    /* otherwise use the first one */
-		}
+	} else if (!fill_in) {
+	    continue;
+
+	} else if (half_match(HTAtom_name(pres->rep),
+			      HTAtom_name(rep_in))) {
+	    if (pres->rep_out == rep_out) {
+		if (failsMailcap(pres, anchor))
+		    continue;
+		if (!strong_subtype_wildcard_match)
+		    strong_subtype_wildcard_match = pres;
+		/* otherwise use the first one */
+		CTRACE((tfp,
+			"StreamStack: found strong subtype wildcard match: %s\n",
+			HTAtom_name(pres->rep)));
 	    }
 	}
 
-	match = strong_subtype_wildcard_match ? strong_subtype_wildcard_match :
-	    strong_wildcard_match ? strong_wildcard_match :
-	    weak_wildcard_match ? weak_wildcard_match :
-	    last_default_match;
-
-	if (match) {
-	    *fill_in = *match;	/* Specific instance */
-	    fill_in->rep = rep_in;	/* yuk */
-	    fill_in->rep_out = rep_out;		/* yuk */
-	    return fill_in;
+	if (pres->rep == WWW_SOURCE) {
+	    if (pres->rep_out == rep_out) {
+		if (failsMailcap(pres, anchor))
+		    continue;
+		if (!weak_wildcard_match)
+		    weak_wildcard_match = pres;
+		/* otherwise use the first one */
+		CTRACE((tfp,
+			"StreamStack: found weak wildcard match: %s\n",
+			HTAtom_name(pres->rep_out)));
+
+	    } else if (!last_default_match) {
+		if (!wildcard)
+		    wildcard = WWW_WILDCARD_REP_OUT;
+		if (pres->rep_out == wildcard) {
+		    if (failsMailcap(pres, anchor))
+			continue;
+		    last_default_match = pres;
+		/* otherwise use the first one */
+		}
+	    }
 	}
     }
 
+    match = (strong_subtype_wildcard_match
+	     ? strong_subtype_wildcard_match
+	     : (strong_wildcard_match
+		? strong_wildcard_match
+		: (weak_wildcard_match
+		   ? weak_wildcard_match
+		   : last_default_match)));
+
+    if (match) {
+	*fill_in = *match;	/* Specific instance */
+	fill_in->rep = rep_in;	/* yuk */
+	fill_in->rep_out = rep_out;	/* yuk */
+	return fill_in;
+    }
+
     return NULL;
 }
 
@@ -450,8 +479,10 @@ HTStream *HTStreamStack(HTFormat rep_in,
     HTPresentation *match;
     HTStream *result;
 
-    CTRACE((tfp, "HTFormat: Constructing stream stack for %s to %s\n",
-	    HTAtom_name(rep_in), HTAtom_name(rep_out)));
+    CTRACE((tfp, "HTFormat: Constructing stream stack for %s to %s (%s)\n",
+	    HTAtom_name(rep_in),
+	    HTAtom_name(rep_out),
+	    NONNULL(anchor->content_type_params)));
 
     /* don't return on WWW_SOURCE some people might like
      * to make use of the source!!!!  LJM
@@ -464,7 +495,7 @@ HTStream *HTStreamStack(HTFormat rep_in,
     if (rep_out == rep_in) {
 	result = sink;
 
-    } else if ((match = HTFindPresentation(rep_in, rep_out, &temp))) {
+    } else if ((match = HTFindPresentation(rep_in, rep_out, &temp, anchor))) {
 	if (match == &temp) {
 	    CTRACE((tfp, "StreamStack: Using %s\n", HTAtom_name(temp.rep_out)));
 	} else {
@@ -499,7 +530,7 @@ void HTReorderPresentation(HTFormat rep_in,
 {
     HTPresentation *match;
 
-    if ((match = HTFindPresentation(rep_in, rep_out, NULL))) {
+    if ((match = HTFindPresentation(rep_in, rep_out, NULL, NULL))) {
 	HTList_removeObject(HTPresentations, match);
 	HTList_addObject(HTPresentations, match);
     }
diff --git a/WWW/Library/Implementation/HTFormat.h b/WWW/Library/Implementation/HTFormat.h
index b94cc413..ec51e7d6 100644
--- a/WWW/Library/Implementation/HTFormat.h
+++ b/WWW/Library/Implementation/HTFormat.h
@@ -168,7 +168,8 @@ struct _HTPresentation {
     HTAtom *rep;		/* representation name atomized */
     HTAtom *rep_out;		/* resulting representation */
     HTConverter *converter;	/* routine to gen the stream stack */
-    char *command;		/* MIME-format string */
+    char *command;		/* MIME-format command string */
+    char *testcommand;		/* MIME-format test string */
     float quality;		/* Between 0 (bad) and 1 (good) */
     float secs;
     float secs_per_byte;
@@ -232,6 +233,8 @@ HTSetPresentation: Register a system command to present a format
 
   command                 is the MAILCAP - style command template
 
+  testcommand             is the MAILCAP - style testcommand template
+
   quality                 A degradation faction 0..1.0
 
   secs                    A limit on the time user will wait (0.0 for infinity)
@@ -244,6 +247,7 @@ HTSetPresentation: Register a system command to present a format
  */
 extern void HTSetPresentation(const char *representation,
 			      const char *command,
+			      const char *testcommand,
 			      double quality,
 			      double secs,
 			      double secs_per_byte,
diff --git a/WWW/Library/Implementation/HTInit.h b/WWW/Library/Implementation/HTInit.h
index 3cd9cca6..81441421 100644
--- a/WWW/Library/Implementation/HTInit.h
+++ b/WWW/Library/Implementation/HTInit.h
@@ -1,10 +1,10 @@
 /*                   /Net/dxcern/userd/timbl/hypertext/WWW/Library/Implementation/HTInit.html
                                   INITIALISATION MODULE
                                              
-   This module resisters all the plug & play software modules which will be
+   This module registers all the plug & play software modules which will be
    used in the program.  This is for a browser.
    
-   To override this, just copy it and link in your version befoe you link with
+   To override this, just copy it and link in your version before you link with
    the library.
    
    Implemented by HTInit.c by default.
@@ -21,5 +21,8 @@
 extern void HTFormatInit(void);
 extern void HTPreparsedFormatInit(void);
 extern void HTFileInit(void);
+extern int LYTestMailcapCommand(const char *testcommand, const char *params);
+extern BOOL LYMailcapUsesPctS(const char *controlstring);
+extern char *LYMakeMailcapCommand(const char *command, const char *params, const char *filename);
 
 #endif /* HTINIT_H */
diff --git a/WWW/Library/Implementation/HTMIME.c b/WWW/Library/Implementation/HTMIME.c
index 259bab89..3ebd5c3b 100644
--- a/WWW/Library/Implementation/HTMIME.c
+++ b/WWW/Library/Implementation/HTMIME.c
@@ -489,6 +489,7 @@ static int dispatchField(HTStream *me)
     char *cp;
 
     *me->value_pointer = '\0';
+
     cp = me->value_pointer;
     while ((cp > me->value) && *(--cp) == ' ')	/* S/390 -- gil -- 0146 */
 	/*
@@ -754,6 +755,7 @@ static int dispatchField(HTStream *me)
 	}
 	me->value[j] = '\0';
 	me->format = HTAtom_for(me->value);
+	StrAllocCopy(me->anchor->content_type_params, me->value);
 	break;
     case miDATE:
 	HTMIME_TrimDoubleQuotes(me->value);
@@ -1853,6 +1855,17 @@ static void HTMIME_put_character(HTStream *me,
 
     }				/* switch on state */
 
+#ifdef EXP_HTTP_HEADERS
+    HTChunkPutc(&me->anchor->http_headers, c);
+    if (me->state == MIME_TRANSPARENT) {
+	HTChunkTerminate(&me->anchor->http_headers);
+	CTRACE((tfp, "Server Headers:\n%.*s\n",
+		me->anchor->http_headers.size,
+		me->anchor->http_headers.data));
+	CTRACE((tfp, "Server Content-Type:%s\n",
+		me->anchor->content_type_params));
+    }
+#endif
     return;
 
   value_too_long:
@@ -1860,6 +1873,11 @@ static void HTMIME_put_character(HTStream *me,
 
   bad_field_name:		/* Ignore it */
     me->state = miJUNK_LINE;
+
+#ifdef EXP_HTTP_HEADERS
+    HTChunkPutc(&me->anchor->http_headers, c);
+#endif
+
     return;
 
 }
@@ -1968,6 +1986,11 @@ HTStream *HTMIMEConvert(HTPresentation *pres,
     FREE(me->anchor->cache_control);
     FREE(me->anchor->SugFname);
     FREE(me->anchor->charset);
+#ifdef EXP_HTTP_HEADERS
+    HTChunkClear(&me->anchor->http_headers);
+    HTChunkInit(&me->anchor->http_headers, 128);
+#endif
+    FREE(me->anchor->content_type_params);
     FREE(me->anchor->content_language);
     FREE(me->anchor->content_encoding);
     FREE(me->anchor->content_base);
diff --git a/WWW/Library/Implementation/HTRules.c b/WWW/Library/Implementation/HTRules.c
index 34675104..c291bf4b 100644
--- a/WWW/Library/Implementation/HTRules.c
+++ b/WWW/Library/Implementation/HTRules.c
@@ -497,7 +497,7 @@ int HTSetConfiguration(char *config)
 			    &quality, &secs, &secs_per_byte, &maxbytes);
 	else
 	    status = 0;
-	HTSetPresentation(word2, word3,
+	HTSetPresentation(word2, word3, NULL,
 			  status >= 1 ? quality : 1.0,
 			  status >= 2 ? secs : 0.0,
 			  status >= 3 ? secs_per_byte : 0.0,
diff --git a/WWW/Library/Implementation/HTString.c b/WWW/Library/Implementation/HTString.c
index e7b3e2c0..2c6cee4f 100644
--- a/WWW/Library/Implementation/HTString.c
+++ b/WWW/Library/Implementation/HTString.c
@@ -822,12 +822,7 @@ PUBLIC_IF_FIND_LEAKS char *StrAllocVsprintf(char **pstr,
 #ifdef HTSprintf		/* if hidden by LYLeaks stuff */
 #undef HTSprintf
 #endif
-#if ANSI_VARARGS
 char *HTSprintf(char **pstr, const char *fmt,...)
-#else
-char *HTSprintf(va_alist)
-    va_dcl
-#endif
 {
     char *result = 0;
     size_t inuse = 0;
@@ -835,10 +830,6 @@ char *HTSprintf(va_alist)
 
     LYva_start(ap, fmt);
     {
-#if !ANSI_VARARGS
-	char **pstr = va_arg(ap, char **);
-	const char *fmt = va_arg(ap, const char *);
-#endif
 	if (pstr != 0 && *pstr != 0)
 	    inuse = strlen(*pstr);
 	result = StrAllocVsprintf(pstr, inuse, fmt, &ap);
@@ -858,22 +849,13 @@ char *HTSprintf(va_alist)
 #ifdef HTSprintf0		/* if hidden by LYLeaks stuff */
 #undef HTSprintf0
 #endif
-#if ANSI_VARARGS
 char *HTSprintf0(char **pstr, const char *fmt,...)
-#else
-char *HTSprintf0(va_alist)
-    va_dcl
-#endif
 {
     char *result = 0;
     va_list ap;
 
     LYva_start(ap, fmt);
     {
-#if !ANSI_VARARGS
-	char **pstr = va_arg(ap, char **);
-	const char *fmt = va_arg(ap, const char *);
-#endif
 #ifdef USE_VASPRINTF
 	if (pstr) {
 	    if (*pstr)
@@ -1238,12 +1220,7 @@ void HTSABFree(bstring **ptr)
  * Use this function to perform formatted sprintf's onto the end of a bstring.
  * The bstring may contain embedded nulls; the formatted portions must not.
  */
-#ifdef ANSI_VARARGS
 bstring *HTBprintf(bstring **pstr, const char *fmt,...)
-#else
-bstring *HTBprintf(va_alist)
-    va_dcl
-#endif
 {
     bstring *result = 0;
     char *temp = 0;
@@ -1251,10 +1228,6 @@ bstring *HTBprintf(va_alist)
 
     LYva_start(ap, fmt);
     {
-#if !ANSI_VARARGS
-	bstring **pstr = va_arg(ap, char **);
-	const char *fmt = va_arg(ap, const char *);
-#endif
 	temp = StrAllocVsprintf(&temp, 0, fmt, &ap);
 	if (!isEmpty(temp)) {
 	    HTSABCat(pstr, temp, strlen(temp));
diff --git a/WWW/Library/Implementation/HTString.h b/WWW/Library/Implementation/HTString.h
index 6e5bcc2c..63b193ae 100644
--- a/WWW/Library/Implementation/HTString.h
+++ b/WWW/Library/Implementation/HTString.h
@@ -78,15 +78,9 @@ extern char *HTNextField(char **pstr);
 extern char *HTNextTok(char **pstr,
 		       const char *delims, const char *bracks, char *found);
 
-#ifdef ANSI_VARARGS
 extern char *HTSprintf(char **pstr, const char *fmt,...) GCC_PRINTFLIKE(2,3);
 extern char *HTSprintf0(char **pstr, const char *fmt,...) GCC_PRINTFLIKE(2,3);
 
-#else
-extern char *HTSprintf() GCC_PRINTFLIKE(2,3);
-extern char *HTSprintf0() GCC_PRINTFLIKE(2,3);
-#endif
-
 #if defined(LY_FIND_LEAKS)	/* private otherwise */
 extern char *StrAllocVsprintf(char **pstr,
 			      size_t len,
@@ -143,13 +137,8 @@ extern void HTSABFree(bstring **ptr);
 #define BStrCat0(d,s)  HTSABCat0(  &(d), s)
 #define BStrFree(d)    HTSABFree(  &(d))
 
-#ifdef ANSI_VARARGS
 extern bstring *HTBprintf(bstring **pstr, const char *fmt,...) GCC_PRINTFLIKE(2,3);
 
-#else
-extern bstring *HTBprintf() GCC_PRINTFLIKE(2,3);
-#endif
-
 extern void trace_bstring(bstring *data);
 extern void trace_bstring2(const char *text, int size);
 
diff --git a/WWW/Library/Implementation/HTTCP.c b/WWW/Library/Implementation/HTTCP.c
index 707863e9..b5574926 100644
--- a/WWW/Library/Implementation/HTTCP.c
+++ b/WWW/Library/Implementation/HTTCP.c
@@ -104,17 +104,18 @@ static int ResolveYield(void)
  * This chunk of code is used in both win32 and cygwin.
  */
 #if defined(_WINDOWS_NSL)
-static char host[512];
 static LYNX_HOSTENT *phost;	/* Pointer to host - See netdb.h */
 static int donelookup;
 
-static unsigned long _fork_func(void *arglist GCC_UNUSED)
+static unsigned long __stdcall _fork_func(void *arg)
 {
+    const char *host = (const char *) arg;
+
 #ifdef SH_EX
     unsigned long addr;
 
     addr = (unsigned long) inet_addr(host);
-    if ((int) addr != -1)
+    if (addr != INADDR_NONE)
 	phost = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
     else
 	phost = gethostbyname(host);
@@ -643,9 +644,7 @@ extern int h_errno;
  */
 LYNX_HOSTENT *LYGetHostByName(char *str)
 {
-#ifndef _WINDOWS_NSL
     char *host = str;
-#endif
 
 #ifdef NSL_FORK
     /* for transfer of result between from child to parent: */
@@ -696,9 +695,6 @@ LYNX_HOSTENT *LYGetHostByName(char *str)
 	lynx_nsl_status = HT_INTERRUPTED;
 	return NULL;
     }
-#ifdef _WINDOWS_NSL
-    strncpy(host, str, sizeof(host));
-#endif /*  _WINDOWS_NSL */
 
     if (!valid_hostname(host)) {
 	lynx_nsl_status = HT_NOT_ACCEPTABLE;
@@ -1102,7 +1098,7 @@ LYNX_HOSTENT *LYGetHostByName(char *str)
 	    unsigned long t;
 
 	    t = (unsigned long) inet_addr(host);
-	    if ((int) t != -1)
+	    if (t != INADDR_NONE)
 		phost = gethostbyaddr((char *) &t, sizeof(t), AF_INET);
 	    else
 		phost = gethostbyname(host);
@@ -1110,11 +1106,12 @@ LYNX_HOSTENT *LYGetHostByName(char *str)
 #endif /* !__CYGWIN__ */
 	    phost = (LYNX_HOSTENT *) NULL;
 	    donelookup = FALSE;
-	    hThread = CreateThread((void *) NULL, 4096UL,
-				   (LPTHREAD_START_ROUTINE) _fork_func,
-				   (void *) NULL, 0UL, (unsigned long *) &dwThreadID);
+	    WSASetLastError(WSAHOST_NOT_FOUND);
+
+	    hThread = CreateThread(NULL, 4096UL, _fork_func, host, 0UL,
+				   (unsigned long *) &dwThreadID);
 	    if (!hThread)
-		MessageBox((void *) NULL, "CreateThread",
+		MessageBox(NULL, "CreateThread",
 			   "CreateThread Failed", 0L);
 
 	    while (!donelookup) {
@@ -1191,10 +1188,7 @@ static int HTParseInet(SockA * soc_in, const char *str)
     char *port;
     int dotcount_ip = 0;	/* for dotted decimal IP addr */
     char *strptr;
-
-#ifndef _WINDOWS_NSL
     char *host = NULL;
-#endif /* _WINDOWS_NSL */
 
     if (!str) {
 	CTRACE((tfp, "HTParseInet: Can't parse `NULL'.\n"));
@@ -1205,11 +1199,7 @@ static int HTParseInet(SockA * soc_in, const char *str)
 	CTRACE((tfp, "HTParseInet: INTERRUPTED for '%s'.\n", str));
 	return -1;
     }
-#ifdef _WINDOWS_NSL
-    strncpy(host, str, sizeof(host));
-#else
     StrAllocCopy(host, str);	/* Make a copy we can mutilate */
-#endif /*  _WINDOWS_NSL */
     /*
      * Parse port number if present.
      */
@@ -1238,9 +1228,7 @@ static int HTParseInet(SockA * soc_in, const char *str)
 #endif /* SUPPRESS */
 	}
 	if (strptr && *strptr != '\0') {
-#ifndef _WINDOWS_NSL
 	    FREE(host);
-#endif /* _WINDOWS_NSL */
 	    HTAlwaysAlert(NULL, gettext("Address has invalid port"));
 	    return -1;
 	}
@@ -1286,9 +1274,7 @@ static int HTParseInet(SockA * soc_in, const char *str)
 #ifdef HAVE_INET_ATON
 	if (!inet_aton(host, &(soc_in->sin_addr))) {
 	    CTRACE((tfp, "inet_aton(%s) returns error\n", host));
-#ifndef _WINDOWS_NSL
 	    FREE(host);
-#endif /* _WINDOWS_NSL */
 	    return -1;
 	}
 #else
@@ -1296,9 +1282,7 @@ static int HTParseInet(SockA * soc_in, const char *str)
 #endif /* HAVE_INET_ATON */
 #endif /* GUSI */
 #endif /* DGUX_OLD */
-#ifndef _WINDOWS_NSL
 	FREE(host);
-#endif /* _WINDOWS_NSL */
     } else {			/* Alphanumeric node name: */
 
 #ifdef MVS			/* Outstanding problem with crash in MVS gethostbyname */
@@ -1340,10 +1324,7 @@ static int HTParseInet(SockA * soc_in, const char *str)
 	}
 #endif /* _WINDOWS_NSL */
 
-#ifndef _WINDOWS_NSL
 	FREE(host);
-#endif /* _WINDOWS_NSL */
-
     }				/* Alphanumeric node name */
 
     CTRACE((tfp,
@@ -1360,9 +1341,7 @@ static int HTParseInet(SockA * soc_in, const char *str)
   failed:
     CTRACE((tfp, "HTParseInet: Can't find internet node name `%s'.\n",
 	    host));
-#ifndef _WINDOWS_NSL
     FREE(host);
-#endif /* _WINDOWS_NSL */
     switch (lynx_nsl_status) {
     case HT_NOT_ACCEPTABLE:
     case HT_INTERRUPTED:
@@ -1612,8 +1591,7 @@ int HTDoConnect(const char *url,
 	HTAlert(gettext("socket failed."));
 	return HT_NO_DATA;
     }
-#endif /* INET6 */
-#ifdef INET6
+#else
     for (res = res0; res; res = res->ai_next) {
 	*s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
 	if (*s == -1) {
diff --git a/WWW/Library/Implementation/HTTP.c b/WWW/Library/Implementation/HTTP.c
index 0328b319..7aa30de8 100644
--- a/WWW/Library/Implementation/HTTP.c
+++ b/WWW/Library/Implementation/HTTP.c
@@ -209,7 +209,7 @@ static int ws_read(int fd, char *buf, int len)
     return res;
 }
 
-static void _thread_func(void *p)
+static DWORD __stdcall _thread_func(void *p)
 {
     int i, val, ret;
     recv_data_t *q = (recv_data_t *) p;
@@ -232,7 +232,7 @@ static void _thread_func(void *p)
 	ret = val;
     }
 
-    ExitThread((DWORD) ret);
+    return ((DWORD) ret);
 }
 
 /* The same like read, but takes care of EINTR and uses select to
@@ -267,8 +267,8 @@ int ws_netread(int fd, char *buf, int len)
     ws_read_per_sec = 0;
     save_TickCount = GetTickCount();
 
-    hThread = CreateThread((void *) NULL, STACK_SIZE,
-			   (LPTHREAD_START_ROUTINE) _thread_func,
+    hThread = CreateThread(NULL, STACK_SIZE,
+			   _thread_func,
 			   (void *) &para, 0UL, &dwThreadID);
 
     if (hThread == 0) {
diff --git a/WWW/Library/Implementation/HTVMSUtils.c b/WWW/Library/Implementation/HTVMSUtils.c
index 64319071..7b609eb3 100644
--- a/WWW/Library/Implementation/HTVMSUtils.c
+++ b/WWW/Library/Implementation/HTVMSUtils.c
@@ -233,7 +233,7 @@ BOOL HTVMS_checkAccess(const char *FileName,
  *
  *
  */
-char *HTVMS_wwwName(const char *vmsname)
+const char *HTVMS_wwwName(const char *vmsname)
 {
     static char wwwname[LY_MAXPATH];
     const char *src;
@@ -508,7 +508,7 @@ static struct dirent *HTVMSreaddir(DIR *dirp)
     struct dsc$descriptor_s entryname_desc;
     char *space, *slash;
     char VMSentry[256];
-    char *UnixEntry;
+    const char *UnixEntry;
 
     entryname_desc.dsc$w_length = 255;
     entryname_desc.dsc$b_dtype = DSC$K_DTYPE_T;
diff --git a/WWW/Library/Implementation/HTVMSUtils.h b/WWW/Library/Implementation/HTVMSUtils.h
index 78e26dae..d7e61de3 100644
--- a/WWW/Library/Implementation/HTVMSUtils.h
+++ b/WWW/Library/Implementation/HTVMSUtils.h
@@ -82,7 +82,7 @@ extern BOOL HTVMS_checkAccess(const char *FileName,
  *
  *
  */
-extern char *HTVMS_wwwName(const char *vmsname);
+const extern char *HTVMS_wwwName(const char *vmsname);
 
 extern int HTVMSBrowseDir(const char *address,
 			  HTParentAnchor *anchor,
diff --git a/WWW/Library/Implementation/LYexit.h b/WWW/Library/Implementation/LYexit.h
index 212aa95b..21d8a11b 100644
--- a/WWW/Library/Implementation/LYexit.h
+++ b/WWW/Library/Implementation/LYexit.h
@@ -19,6 +19,9 @@
 /*
  *	Required includes
  */
+#ifdef _WINDOWS
+#include <process.h>		/* declares exit() */
+#endif
 
 #ifndef HTUTILS_H
 #include <HTUtils.h>
@@ -29,7 +32,7 @@
  */
 #ifdef exit
 #undef exit
-#endif /* _WINDOWS */
+#endif
 
 #define exit(code) LYexit(code)
 
diff --git a/WWW/Library/Implementation/SGML.c b/WWW/Library/Implementation/SGML.c
index 0d498bad..54910903 100644
--- a/WWW/Library/Implementation/SGML.c
+++ b/WWW/Library/Implementation/SGML.c
@@ -322,11 +322,11 @@ static void HTMLSRC_apply_markup(HTStream *context, HTlexeme lexeme, BOOL start)
 						ts->present,
 						(const char **) ts->value,
 						context->current_tag_charset,
-						(char **) &context->include);
+						&context->include);
 	else
 	    (*context->actions->end_element) (context->target,
 					      ts->element,
-					      (char **) &context->include);
+					      &context->include);
 	ts = ts->next;
     }
 }
@@ -800,8 +800,8 @@ static void handle_comment(HTStream *context)
 
     if (context->csi == NULL &&
 	strncmp(s, "!--#", 4) == 0 &&
-	LYCheckForCSI(context->node_anchor, (char **) &context->url) == TRUE) {
-	LYDoCSI(context->url, s, (char **) &context->csi);
+	LYCheckForCSI(context->node_anchor, &context->url) == TRUE) {
+	LYDoCSI(context->url, s, &context->csi);
     } else {
 	LYCommentHacks(context->node_anchor, context->string->data);
     }
@@ -978,7 +978,7 @@ static void do_close_stacked(HTStream *context)
 #endif
 	(*context->actions->end_element) (context->target,
 					  e,
-					  (char **) &context->include);
+					  &context->include);
     context->element_stack = stacked->next;
     pool_free(stacked);
     context->no_lynx_specialcodes = context->element_stack ?
@@ -1111,7 +1111,7 @@ static void end_element(HTStream *context, HTTag * old_tag)
 	if (!psrc_view)		/* Don't actually pass call on if viewing psrc - kw */
 #endif
 	    status = (*context->actions->end_element) (context->target,
-						       e, (char **) &context->include);
+						       e, &context->include);
 	if (status == HT_PARSER_REOPEN_ELT) {
 	    CTRACE((tfp, "SGML: Restart <%s>\n", t->name));
 	    (*context->actions->start_element) (context->target,
@@ -1119,7 +1119,7 @@ static void end_element(HTStream *context, HTTag * old_tag)
 						NULL,
 						NULL,
 						context->current_tag_charset,
-						(char **) &context->include);
+						&context->include);
 	} else if (status == HT_PARSER_OTHER_CONTENT) {
 	    CTRACE((tfp, "SGML: Continue with other content model for <%s>\n", t->name));
 	    context->element_stack->tag = ALT_TAGP_OF_TAGNUM(e);
@@ -1298,7 +1298,7 @@ static void start_element(HTStream *context)
 						 context->present,
 						 (const char **) context->value,	/* coerce type for think c */
 						 context->current_tag_charset,
-						 (char **) &context->include);
+						 &context->include);
     if (status == HT_PARSER_OTHER_CONTENT)
 	new_tag = ALT_TAGP(new_tag);	/* this is only returned for OBJECT */
     if (new_tag->contents != SGML_EMPTY) {	/* i.e., tag not empty */
@@ -1397,7 +1397,7 @@ static void SGML_free(HTStream *context)
 #endif
 	    (*context->actions->end_element) (context->target,
 					      NORMAL_TAGNUM(TAGNUM_OF_TAGP(t)),
-					      (char **) &context->include);
+					      &context->include);
 	FREE(context->include);
     }
 
@@ -3592,7 +3592,7 @@ static void SGML_character(HTStream *context, char c_in)
 		    HTStartAnchor(context->target, string->data, NULL);
 		    (*context->actions->end_element) (context->target,
 						      HTML_A,
-						      (char **) &context->include);
+						      &context->include);
 		} else if (attr_is_href) {
 		    PSRCSTART(href);
 		    HTStartAnchor(context->target, NULL, string->data);
@@ -3601,7 +3601,7 @@ static void SGML_character(HTStream *context, char c_in)
 		if (attr_is_href) {
 		    (*context->actions->end_element) (context->target,
 						      HTML_A,
-						      (char **) &context->include);
+						      &context->include);
 		    PSRCSTOP(href);
 		}
 		PSRCSTOP(attrval);
@@ -3671,7 +3671,7 @@ static void SGML_character(HTStream *context, char c_in)
 		    HTStartAnchor(context->target, string->data, NULL);
 		    (*context->actions->end_element) (context->target,
 						      HTML_A,
-						      (char **) &context->include);
+						      &context->include);
 		} else if (attr_is_href) {
 		    PSRCSTART(href);
 		    HTStartAnchor(context->target, NULL, string->data);
@@ -3680,7 +3680,7 @@ static void SGML_character(HTStream *context, char c_in)
 		if (attr_is_href) {
 		    (*context->actions->end_element) (context->target,
 						      HTML_A,
-						      (char **) &context->include);
+						      &context->include);
 		    PSRCSTOP(href);
 		}
 		PUTC('\'');
@@ -3733,7 +3733,7 @@ static void SGML_character(HTStream *context, char c_in)
 		    HTStartAnchor(context->target, string->data, NULL);
 		    (*context->actions->end_element) (context->target,
 						      HTML_A,
-						      (char **) &context->include);
+						      &context->include);
 		} else if (attr_is_href) {
 		    PSRCSTART(href);
 		    HTStartAnchor(context->target, NULL, string->data);
@@ -3742,7 +3742,7 @@ static void SGML_character(HTStream *context, char c_in)
 		if (attr_is_href) {
 		    (*context->actions->end_element) (context->target,
 						      HTML_A,
-						      (char **) &context->include);
+						      &context->include);
 		    PSRCSTOP(href);
 		}
 		PUTC(c);
@@ -3979,7 +3979,7 @@ static void SGML_character(HTStream *context, char c_in)
 				(*context->actions->end_element)
 				    (context->target,
 				     TAGNUM_OF_TAGP(context->current_tag),
-				     (char **) &context->include);
+				     &context->include);
 			}
 		    } else if (!strcasecomp(string->data, "P")) {
 			/*
@@ -4009,7 +4009,7 @@ static void SGML_character(HTStream *context, char c_in)
 			    (*context->actions->end_element)
 				(context->target,
 				 TAGNUM_OF_TAGP(context->current_tag),
-				 (char **) &context->include);
+				 &context->include);
 		    }
 		    string->size = 0;
 		    context->current_attribute_number = INVALID;
diff --git a/WWW/Library/Implementation/www_tcp.h b/WWW/Library/Implementation/www_tcp.h
index 750239b7..25a48776 100644
--- a/WWW/Library/Implementation/www_tcp.h
+++ b/WWW/Library/Implementation/www_tcp.h
@@ -176,8 +176,8 @@ IBM-PC running Windows NT
 #endif
 
 #include <fcntl.h>		/* For HTFile.c */
-#include <sys\types.h>		/* For HTFile.c */
-#include <sys\stat.h>		/* For HTFile.c */
+#include <sys/types.h>		/* For HTFile.c */
+#include <sys/stat.h>		/* For HTFile.c */
 #undef NETREAD
 #undef NETWRITE
 #undef NETCLOSE
@@ -195,9 +195,33 @@ extern int ws_netread(int fd, char *buf, int len);
 #include <errno.h>
 #include <direct.h>
 
+#ifdef ENABLE_IPV6
+#undef  USE_WINSOCK2_H
+#define USE_WINSOCK2_H
+
+/* Avoid including <winsock*.h> in <windows.h> */
+#ifndef WIN32_LEAN_AND_MEAN
+#error Define "WIN32_LEAN_AND_MEAN" in your makefile
+#endif
+
+#if defined(_MSC_VER) && (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0501)
+/*
+ * Needed to pull in the real getaddrinfo() and not the inline version
+ * in <wspiAPI.H> which doesn't support IPv6 (IPv4 only). <wspiAPI.H> is
+ * included from <ws2tcpip.h> for <= 0x0500 SDKs.
+ */
+#undef  _WIN32_WINNT
+#define _WIN32_WINNT 0x0501
+#endif
+#endif /* ENABLE_IPV6 */
+
 #ifdef USE_WINSOCK2_H
 #include <winsock2.h>		/* normally included in windows.h */
 
+#ifdef ENABLE_IPV6
+#include <ws2tcpip.h>
+#endif
+
 #undef EINPROGRESS
 #undef EALREADY
 #undef EISCONN
@@ -216,10 +240,9 @@ extern int ws_netread(int fd, char *buf, int len);
 #define ECONNRESET   WSAECONNRESET
 #define ETIMEDOUT    WSAETIMEDOUT
 
-#else /* USE_WINSOCK_H */
+#else /* USE_WINSOCK2_H */
 
 #include <winsock.h>
-typedef struct sockaddr_in SockA;	/* See netinet/in.h */
 
 #if defined(_MSC_VER) || defined(__MINGW32__)
 #undef EINTR
@@ -233,12 +256,12 @@ typedef struct sockaddr_in SockA;	/* See netinet/in.h */
 #define EAGAIN               (WSABASEERR+1002)
 #define ENOTCONN             (WSABASEERR+57)
 #define ECONNRESET           (WSABASEERR+54)
-#define ETIMEDOUT             WSAETIMEDOUT	/* 1997/11/10 (Mon) */
+#define ETIMEDOUT             WSAETIMEDOUT
 
-#undef  SOCKET_ERRNO		/* 1997/10/19 (Sun) 18:01:46 */
-#define SOCKET_ERRNO          WSAGetLastError()
+#endif /* USE_WINSOCK2_H */
 
-#endif /* USE_WINSOCK_H */
+#undef  SOCKET_ERRNO
+#define SOCKET_ERRNO          WSAGetLastError()
 
 #define INCLUDES_DONE
 #define TCP_INCLUDES_DONE
@@ -669,7 +692,7 @@ typedef unsigned short mode_t;
 
 #else
 
-#if !(defined(VM) || defined(VMS) || defined(THINK_C) || defined(PCNFS) || defined(__MINGW32__))
+#if !(defined(VM) || defined(VMS) || defined(THINK_C) || defined(PCNFS) || defined(_WINDOWS))
 #define DECL_SYS_ERRLIST 1
 #endif
 
@@ -817,21 +840,27 @@ typedef unsigned int fd_set;
 #define set_errno(value)	/* we do not know how */
 #endif
 
-/* IPv6 support */
-#if defined(HAVE_GETADDRINFO) && defined(HAVE_GAI_STRERROR) && defined(ENABLE_IPV6)
-#	define INET6
-#endif /* HAVE_GETADDRINFO && HAVE_GAI_STRERROR && ENABLE_IPV6 */
-
-#if !defined(__MINGW32__)
-#ifdef INET6
-typedef struct sockaddr_storage SockA;	/* See netinet/in.h */
-
-#else
-typedef struct sockaddr_in SockA;	/* See netinet/in.h */
-#endif /* INET6 */
+/*
+ * IPv6 support
+ */
+#if defined(HAVE_GETADDRINFO) && defined(ENABLE_IPV6)
+#if defined(HAVE_GAI_STRERROR)
+#define INET6
+#elif defined(_WINDOWS)
+#define INET6
+#ifndef WIN_EX
+#error Define "WIN_EX" in your makefile.
+#endif
+#ifndef _MSC_VER		/* MSVC has this inlined in <ws2tcpip.h> */
+#undef  gai_strerror
+#define gai_strerror(err) w32_strerror (err)
+#endif
 #endif
+#endif /* HAVE_GETADDRINFO && ENABLE_IPV6 */
 
 #ifdef INET6
+typedef struct sockaddr_storage SockA;
+
 #ifdef SIN6_LEN
 #define SOCKADDR_LEN(soc_address) ((struct sockaddr *)&soc_address)->sa_len
 #else
@@ -840,16 +869,18 @@ typedef struct sockaddr_in SockA;	/* See netinet/in.h */
 		   ? sizeof(struct sockaddr_in6) \
 		   : (((x)->sa_family == AF_INET) \
 		      ? sizeof(struct sockaddr_in) \
-		      : sizeof(struct sockaddr)))
+		      : sizeof(struct sockaddr)))	/* AF_UNSPEC? */
 #endif
 #define SOCKADDR_LEN(soc_address) SA_LEN((struct sockaddr *)&soc_address)
 #endif /* SIN6_LEN */
 #else
+typedef struct sockaddr_in SockA;
+
 #define SOCKADDR_LEN(soc_address) sizeof(soc_address)
 #endif /* INET6 */
 
 #ifndef MAXHOSTNAMELEN
-#define MAXHOSTNAMELEN 64	/* Arbitrary limit */
+#define MAXHOSTNAMELEN 128	/* Max label is 63. Should handle 2 of those */
 #endif /* MAXHOSTNAMELEN */
 
 #endif /* TCP_H */