about summary refs log tree commit diff stats
path: root/WWW/Library/Implementation
diff options
context:
space:
mode:
Diffstat (limited to 'WWW/Library/Implementation')
-rw-r--r--WWW/Library/Implementation/HTFTP.c89
-rw-r--r--WWW/Library/Implementation/HTFile.c189
-rw-r--r--WWW/Library/Implementation/HTFile.h15
-rw-r--r--WWW/Library/Implementation/HTTCP.c69
-rw-r--r--WWW/Library/Implementation/HTTCP.h28
-rw-r--r--WWW/Library/Implementation/www_tcp.h71
6 files changed, 253 insertions, 208 deletions
diff --git a/WWW/Library/Implementation/HTFTP.c b/WWW/Library/Implementation/HTFTP.c
index 5c3df4f0..91cbc282 100644
--- a/WWW/Library/Implementation/HTFTP.c
+++ b/WWW/Library/Implementation/HTFTP.c
@@ -908,8 +908,7 @@ PRIVATE int get_connection ARGS2(
 	status = response(command);
 	FREE(command);
 	if (status == HT_INTERRUPTED) {
-	    CTRACE((tfp,
-		       "HTFTP: Interrupted while sending password.\n"));
+	    CTRACE((tfp, "HTFTP: Interrupted while sending password.\n"));
 	    _HTProgress (CONNECTION_INTERRUPTED);
 	    NETCLOSE(control->socket);
 	    control->socket = -1;
@@ -997,10 +996,10 @@ PRIVATE int get_connection ARGS2(
 	    CTRACE((tfp, "HTFTP: Treating as Window_NT server.\n"));
 	    set_unix_dirstyle(&server_type, &use_list);
 
-        } else if (strncmp(response_text+4, "Windows2000", 11) == 0) {
-            server_type = WINDOWS_2K_SERVER;
-            CTRACE((tfp, "HTFTP: Treating as Window_2K server.\n"));
-            set_unix_dirstyle(&server_type, &use_list);
+	} else if (strncmp(response_text+4, "Windows2000", 11) == 0) {
+	    server_type = WINDOWS_2K_SERVER;
+	    CTRACE((tfp, "HTFTP: Treating as Window_2K server.\n"));
+	    set_unix_dirstyle(&server_type, &use_list);
 
 	} else if (strncmp(response_text+4, "MS Windows", 10) == 0) {
 	    server_type = MS_WINDOWS_SERVER;
@@ -1202,9 +1201,9 @@ PRIVATE int get_listen_socket NOARGS
 	if (status<0) return HTInetStatus("getsockname");
 #ifdef INET6
 	CTRACE((tfp, "HTFTP: This host is %s\n",
- 	    HTInetString((SockA *)soc_in)));
-  
- 	soc_in->sin_port = 0;	/* Unspecified: please allocate */
+	    HTInetString((SockA *)soc_in)));
+
+	soc_in->sin_port = 0;	/* Unspecified: please allocate */
 #else
 	CTRACE((tfp, "HTFTP: This host is %s\n",
 	    HTInetString(soc_in)));
@@ -1252,7 +1251,7 @@ PRIVATE int get_listen_socket NOARGS
 #ifdef INET6
     CTRACE((tfp, "HTFTP: bound to port %d on %s\n",
 		(int)ntohs(soc_in->sin_port),
- 		HTInetString((SockA *)soc_in)));
+		HTInetString((SockA *)soc_in)));
 #else
     CTRACE((tfp, "HTFTP: bound to port %d on %s\n",
 		(int)ntohs(soc_in->sin_port),
@@ -1572,16 +1571,16 @@ PRIVATE void parse_dls_line ARGS3(
     int    len;
     char *cps = NULL;
 
-    /* README              763  Information about this server\0
-       bin/                  -  \0
-       etc/                  =  \0
-       ls-lR                 0  \0
-       ls-lR.Z               3  \0
-       pub/                  =  Public area\0
-       usr/                  -  \0
-       morgan               14  -> ../real/morgan\0
+    /* README		   763	Information about this server\0
+       bin/		     -	\0
+       etc/		     =	\0
+       ls-lR		     0	\0
+       ls-lR.Z		     3	\0
+       pub/		     =	Public area\0
+       usr/		     -	\0
+       morgan		    14	-> ../real/morgan\0
        TIMIT.mostlikely.Z\0
-                         79215  \0
+			 79215	\0
 	*/
 
     len = strlen(line);
@@ -2202,7 +2201,7 @@ PRIVATE EntryInfo * parse_dir_entry ARGS3(
 	case MACHTEN_SERVER:
 	case MSDOS_SERVER:
 	case WINDOWS_NT_SERVER:
-        case WINDOWS_2K_SERVER:
+	case WINDOWS_2K_SERVER:
 	case APPLESHARE_SERVER:
 	case NETPRESENZ_SERVER:
 	    /*
@@ -2960,7 +2959,7 @@ PUBLIC int HTFTPLoad ARGS4(
 		NETCLOSE (control->socket);
 		control->socket = -1;
 #ifdef INET6
-	        if (master_socket >= 0)
+		if (master_socket >= 0)
 		    (void)close_master_socket ();
 #else
 		close_master_socket ();
@@ -3005,9 +3004,9 @@ PUBLIC int HTFTPLoad ARGS4(
 		if (status < 0)	/* retry or Bad return */
 		    continue;
 		else if (status != 2) {
-		    return -status; 	/* bad reply */
+		    return -status;	/* bad reply */
 		}
- 	    }
+	    }
 
 	    if (strncmp(command, "PASV", 4) == 0) {
 		for (p = response_text; *p && *p != ','; p++)
@@ -3042,7 +3041,7 @@ PUBLIC int HTFTPLoad ARGS4(
 		h2 = c2;
 		h3 = c3;
 		passive_port = p0;
- 	    }
+	    }
 #else
 	    status = send_cmd_1("PASV");
 	    if (status != 2) {
@@ -3566,7 +3565,7 @@ listen:
     if(!ftp_passive) {
 	/* Wait for the connection */
 #ifdef INET6
- 	struct sockaddr_storage soc_address;
+	struct sockaddr_storage soc_address;
 #else
 	struct sockaddr_in soc_address;
 #endif /* INET6 */
@@ -3626,7 +3625,6 @@ listen:
 	status = final_status;
     } else {
 	int rv;
-	int len;
 	char *FileName = HTParse(name, "", PARSE_PATH + PARSE_PUNCTUATION);
 
 	/** Clear any login messages **/
@@ -3644,29 +3642,29 @@ listen:
 	    StrAllocCopy(anchor->content_encoding, HTAtom_name(encoding));
 	    format = HTAtom_for("www/compressed");
 
-	} else if ((len = strlen(FileName)) > 2) {
-	    if ((FileName[len - 1] == 'Z') &&
-		(FileName[len - 2] == '.' ||
-		 FileName[len - 2] == '-' ||
-		 FileName[len - 2] == '_')) {
+	} else {
+	    char *dot;
+	    CompressFileType cft = HTCompressFileType(FileName, "._-", &dot);
 
-		FileName[len - 2] = '\0';
+	    if (cft != cftNone) {
+		*dot = '\0';
 		format = HTFileFormat(FileName, &encoding, NULL);
 		format = HTCharsetFormat(format, anchor, -1);
 		StrAllocCopy(anchor->content_type, format->name);
-		StrAllocCopy(anchor->content_encoding, "x-compress");
 		format = HTAtom_for("www/compressed");
-	    } else if ((len > 3) &&
-		       !strcasecomp((char *)&FileName[len - 2], "gz")) {
-		if (FileName[len - 3] == '.' ||
-		    FileName[len - 3] == '-' ||
-		    FileName[len - 3] == '_') {
-		    FileName[len - 3] = '\0';
-		    format = HTFileFormat(FileName, &encoding, NULL);
-		    format = HTCharsetFormat(format, anchor, -1);
-		    StrAllocCopy(anchor->content_type, format->name);
+
+		switch (cft) {
+		case cftCompress:
+		    StrAllocCopy(anchor->content_encoding, "x-compress");
+		    break;
+		case cftGzip:
 		    StrAllocCopy(anchor->content_encoding, "x-gzip");
-		    format = HTAtom_for("www/compressed");
+		    break;
+		case cftBzip2:
+		    StrAllocCopy(anchor->content_encoding, "x-bzip2");
+		    break;
+		default:
+		    break;
 		}
 	    }
 	}
@@ -3675,11 +3673,6 @@ listen:
 	_HTProgress (gettext("Receiving FTP file."));
 	rv = HTParseSocket(format, format_out, anchor, data_soc, sink);
 
-#if 0				/* already done in HTCopy - kw */
-	if (rv == HT_INTERRUPTED)
-	     _HTProgress(TRANSFER_INTERRUPTED);
-#endif
-
 	HTInitInput(control->socket);
 	/* Reset buffering to control connection DD 921208 */
 
diff --git a/WWW/Library/Implementation/HTFile.c b/WWW/Library/Implementation/HTFile.c
index 103b1651..c0a44bb3 100644
--- a/WWW/Library/Implementation/HTFile.c
+++ b/WWW/Library/Implementation/HTFile.c
@@ -46,7 +46,6 @@
 #include <GridText.h>
 #endif
 
-#define INFINITY 512		/* file name length @@ FIXME */
 #define MULTI_SUFFIX ".multi"	/* Extension for scanning formats */
 
 #include <HTParse.h>
@@ -1205,6 +1204,42 @@ PUBLIC float HTFileValue ARGS1(
     return (float)0.3;		/* Dunno! */
 }
 
+/*
+**  Determine compression type from file name, by looking at its suffix.
+**  Sets as side-effect a pointer to the "dot" that begins the suffix.
+*/
+PUBLIC CompressFileType HTCompressFileType ARGS3(
+	char *,		filename,
+	char *,		dots,
+	char **,	suffix)
+{
+    CompressFileType result = cftNone;
+    size_t len = strlen(filename);
+    char *ftype = filename + len;
+
+    if ((len > 4)
+     && !strcasecomp((ftype - 3), "bz2")
+     && strchr(dots, ftype[-4]) != 0) {
+	result = cftBzip2;
+	ftype -= 4;
+    } else if ((len > 3)
+     && !strcasecomp((ftype - 2), "gz")
+     && strchr(dots, ftype[-3]) != 0) {
+	result = cftGzip;
+	ftype -= 3;
+    } else if ((len > 2)
+     && !strcmp((ftype - 1), "Z")
+     && strchr(dots, ftype[-2]) != 0) {
+	result = cftCompress;
+	ftype -= 2;
+    }
+
+    *suffix = ftype;
+    CTRACE((tfp, "HTCompressFileType(%s) returns %d:%s\n",
+		 filename, result, *suffix));
+    return result;
+}
+
 /*	Determine write access to a file.
 **	---------------------------------
 **
@@ -2007,6 +2042,7 @@ PUBLIC int HTLoadFile ARGS4(
     HTAtom * encoding;		/* @@ not used yet */
     HTAtom * myEncoding = NULL; /* enc of this file, may be gzip etc. */
     int status;
+    char *dot;
 #ifdef VMS
     struct stat stat_info;
 #endif /* VMS */
@@ -2141,8 +2177,6 @@ PUBLIC int HTLoadFile ARGS4(
 	    FREE(ultrixname);
 	}
 	if (fp) {
-	    int len;
-	    char *cp = NULL;
 	    char *semicolon = NULL;
 
 	    if (HTEditable(vmsname)) {
@@ -2187,50 +2221,50 @@ PUBLIC int HTLoadFile ARGS4(
 		    StrAllocCopy(anchor->content_encoding, HTAtom_name(myEncoding));
 		    format = HTAtom_for("www/compressed");
 		}
-	    } else if ((len = strlen(vmsname)) > 2) {
-		if ((vmsname[len - 1] == 'Z') &&
-		    (vmsname[len - 2] == '.' ||
-		     vmsname[len - 2] == '-' ||
-		     vmsname[len - 2] == '_') &&
-		    vmsname[len - 3] != ']' &&
-		    vmsname[len - 3] != ':') {
+	    } else {
+		/* FIXME: should we check if suffix is after ']' or ':' ? */
+		CompressFileType cft = HTCompressFileType(vmsname, "._-", &dot);
+
+		if (cft != cftNone) {
+		    char *cp = NULL;
+
 		    StrAllocCopy(cp, vmsname);
-		    cp[len - 2] = '\0';
+		    cp[dot - vmsname] = '\0';
 		    format = HTFileFormat(cp, &encoding, NULL);
 		    FREE(cp);
 		    format = HTCharsetFormat(format, anchor,
 					     UCLYhndl_HTFile_for_unspec);
 		    StrAllocCopy(anchor->content_type, format->name);
+		}
+
+		switch (cft) {
+		case cftCompress:
 		    StrAllocCopy(anchor->content_encoding, "x-compress");
 		    format = HTAtom_for("www/compressed");
-		} else if ((len > 3) &&
-			   !strcasecomp(&vmsname[len - 2], "gz")) {
-		    if (vmsname[len - 3] == '.' ||
-			vmsname[len - 3] == '-' ||
-			vmsname[len - 3] == '_') {
-			StrAllocCopy(cp, vmsname);
-			cp[len - 3] = '\0';
-			format = HTFileFormat(cp, &encoding, NULL);
-			FREE(cp);
-			format = HTCharsetFormat(format, anchor,
-						 UCLYhndl_HTFile_for_unspec);
-			StrAllocCopy(anchor->content_type, format->name);
-			StrAllocCopy(anchor->content_encoding, "x-gzip");
+		    break;
+		case cftGzip:
+		    StrAllocCopy(anchor->content_encoding, "x-gzip");
 #ifdef USE_ZLIB
-			if (strcmp(format_out->name, "www/download") != 0) {
-			    fclose(fp);
-			    if (semicolon != NULL)
-				*semicolon = ';';
-			    gzfp = gzopen(vmsname, "rb");
+		    if (strcmp(format_out->name, "www/download") != 0) {
+			fclose(fp);
+			if (semicolon != NULL)
+			    *semicolon = ';';
+			gzfp = gzopen(vmsname, "rb");
 
-			    CTRACE((tfp, "HTLoadFile: gzopen of `%s' gives %p\n",
-					vmsname, (void*)gzfp));
-			    use_gzread = YES;
-			}
+			CTRACE((tfp, "HTLoadFile: gzopen of `%s' gives %p\n",
+				    vmsname, (void*)gzfp));
+			use_gzread = YES;
+		    }
 #else  /* USE_ZLIB */
-			format = HTAtom_for("www/compressed");
+		    format = HTAtom_for("www/compressed");
 #endif	/* USE_ZLIB */
-		    }
+		    break;
+		case cftBzip2:
+		    StrAllocCopy(anchor->content_encoding, "x-bzip2");
+		    format = HTAtom_for("www/compressed");
+		    break;
+		case cftNone:
+		    break;
 		}
 	    }
 	    if (semicolon != NULL)
@@ -2350,40 +2384,38 @@ PUBLIC int HTLoadFile ARGS4(
 						filevalue,
 						0L  /* @@@@@@ */);
 		    if (value <= 0.0) {
+			char *atomname = NULL;
+			CompressFileType cft = HTCompressFileType(dirbuf->d_name, ".", &dot);
 			char * cp = NULL;
-			int len = strlen(dirbuf->d_name);
+
 			enc = NULL;
-			if (len > 2 &&
-			    dirbuf->d_name[len - 1] == 'Z' &&
-			    dirbuf->d_name[len - 2] == '.') {
+			if (cft != cftNone) {
 			    StrAllocCopy(cp, dirbuf->d_name);
-			    cp[len - 2] = '\0';
+			    cp[dot - dirbuf->d_name] = '\0';
 			    format = HTFileFormat(cp, NULL, NULL);
 			    FREE(cp);
 			    value = HTStackValue(format, format_out,
 						 filevalue, 0);
-			    if (value <= 0.0) {
-				format = HTAtom_for("application/x-compressed");
-				value = HTStackValue(format, format_out,
-						     filevalue, 0);
-			    }
-			    if (value <= 0.0) {
-				format = HTAtom_for("www/compressed");
-				value = HTStackValue(format, format_out,
-						     filevalue, 0);
+			    switch (cft) {
+			    case cftCompress:
+				atomname = "application/x-compressed";
+				break;
+			    case cftGzip:
+				atomname = "application/x-gzip";
+				break;
+			    case cftBzip2:
+				atomname = "application/x-bzip2";
+				break;
+			    case cftNone:
+				break;
 			    }
-			} else if ((len > 3) &&
-				   !strcasecomp((char *)&dirbuf->d_name[len - 2],
-						"gz") &&
-				   dirbuf->d_name[len - 3] == '.') {
-			    StrAllocCopy(cp, dirbuf->d_name);
-			    cp[len - 3] = '\0';
-			    format = HTFileFormat(cp, NULL, NULL);
-			    FREE(cp);
+			}
+
+			if (atomname != NULL) {
 			    value = HTStackValue(format, format_out,
 						 filevalue, 0);
 			    if (value <= 0.0) {
-				format = HTAtom_for("application/x-gzip");
+				format = HTAtom_for(atomname);
 				value = HTStackValue(format, format_out,
 						     filevalue, 0);
 			    }
@@ -2515,8 +2547,7 @@ PUBLIC int HTLoadFile ARGS4(
 #endif /* HAVE_READDIR */
 	{
 #  if defined(__EMX__) || defined(WIN_EX)
-	    int len = strlen(localname);
-	    int bin = ((len > 3) && !strcasecomp(localname + len - 3, ".gz"));
+	    int bin = HTCompressFileType(localname, ".", &dot) != cftNone;
 	    FILE * fp = fopen(localname, (bin ? "rb" : "r"));
 #  else	/* !( defined __EMX__ ) */
 	    FILE * fp = fopen(localname, "r");
@@ -2525,9 +2556,6 @@ PUBLIC int HTLoadFile ARGS4(
 	    CTRACE((tfp, "HTLoadFile: Opening `%s' gives %p\n",
 				 localname, (void*)fp));
 	    if (fp) {		/* Good! */
-		int len2;
-		char *cp = NULL;
-
 		if (HTEditable(localname)) {
 		    HTAtom * put = HTAtom_for("PUT");
 		    HTList * methods = HTAnchor_methods(anchor);
@@ -2561,29 +2589,27 @@ PUBLIC int HTLoadFile ARGS4(
 			StrAllocCopy(anchor->content_encoding, HTAtom_name(myEncoding));
 			format = HTAtom_for("www/compressed");
 		    }
-		} else if ((len2 = strlen(localname)) > 2) {
-		    if (localname[len2 - 1] == 'Z' &&
-			localname[len2 - 2] == '.') {
+		} else {
+		    CompressFileType cft = HTCompressFileType(localname, ".", &dot);
+
+		    if (cft != cftNone) {
+			char *cp = NULL;
+
 			StrAllocCopy(cp, localname);
-			cp[len2 - 2] = '\0';
+			cp[dot - localname] = '\0';
 			format = HTFileFormat(cp, &encoding, NULL);
 			FREE(cp);
 			format = HTCharsetFormat(format, anchor,
 						 UCLYhndl_HTFile_for_unspec);
 			StrAllocCopy(anchor->content_type, format->name);
+		    }
+
+		    switch (cft) {
+		    case cftCompress:
 			StrAllocCopy(anchor->content_encoding, "x-compress");
 			format = HTAtom_for("www/compressed");
-		    } else if ((len2 > 3) &&
-			       !strcasecomp((char *)&localname[len2 - 2],
-					    "gz") &&
-			       localname[len2 - 3] == '.') {
-			StrAllocCopy(cp, localname);
-			cp[len2 - 3] = '\0';
-			format = HTFileFormat(cp, &encoding, NULL);
-			FREE(cp);
-			format = HTCharsetFormat(format, anchor,
-						 UCLYhndl_HTFile_for_unspec);
-			StrAllocCopy(anchor->content_type, format->name);
+			break;
+		    case cftGzip:
 			StrAllocCopy(anchor->content_encoding, "x-gzip");
 #ifdef USE_ZLIB
 			if (strcmp(format_out->name, "www/download") != 0) {
@@ -2597,6 +2623,13 @@ PUBLIC int HTLoadFile ARGS4(
 #else  /* USE_ZLIB */
 			format = HTAtom_for("www/compressed");
 #endif	/* USE_ZLIB */
+			break;
+		    case cftBzip2:
+			StrAllocCopy(anchor->content_encoding, "x-bzip2");
+			format = HTAtom_for("www/compressed");
+			break;
+		    case cftNone:
+			break;
 		    }
 		}
 		FREE(localname);
diff --git a/WWW/Library/Implementation/HTFile.h b/WWW/Library/Implementation/HTFile.h
index 2cb1d92a..f0a3178a 100644
--- a/WWW/Library/Implementation/HTFile.h
+++ b/WWW/Library/Implementation/HTFile.h
@@ -194,6 +194,21 @@ extern float HTFileValue PARAMS((
 	CONST char *	filename));
 
 /*
+**  Determine compression type from file name, by looking at its suffix.
+*/
+typedef enum {
+    cftNone
+    , cftCompress
+    , cftGzip
+    , cftBzip2
+} CompressFileType;
+
+extern CompressFileType HTCompressFileType PARAMS((
+	char *			filename,
+	char *			dots,
+	char **			suffix));
+
+/*
 **  Determine write access to a file.
 **
 **  ON EXIT,
diff --git a/WWW/Library/Implementation/HTTCP.c b/WWW/Library/Implementation/HTTCP.c
index 5b528bc2..bc696abd 100644
--- a/WWW/Library/Implementation/HTTCP.c
+++ b/WWW/Library/Implementation/HTTCP.c
@@ -306,7 +306,7 @@ PUBLIC CONST char * HTInetString ARGS1(
 	    hostbuf, sizeof(hostbuf), NULL, 0, NI_NUMERICHOST);
     return hostbuf;
 #else
-    static char string[16];
+    static char string[20];
     sprintf(string, "%d.%d.%d.%d",
 	    (int)*((unsigned char *)(&soc_in->sin_addr)+0),
 	    (int)*((unsigned char *)(&soc_in->sin_addr)+1),
@@ -687,7 +687,7 @@ PUBLIC struct hostent * LYGetHostByName ARGS1(
     }
 
 #ifdef _WINDOWS_NSL
-    strncpy(host, str, (size_t)512);
+    strncpy(host, str, sizeof(host));
 #endif /*  _WINDOWS_NSL */
 
     if (!valid_hostname(host)) {
@@ -1171,21 +1171,23 @@ failed:
 **		field is left unchanged in *soc_in.
 */
 #ifdef INET6
-PUBLIC int HTParseInet ARGS3(
- 	SockA *,	soc_in,
+PRIVATE int HTParseInet ARGS3(
+	SockA *,	soc_in,
 	CONST char *,	str,
-	int, default_port)
-{
-    char portstr[NI_MAXSERV];
+	int,		default_port)
 #else
-PUBLIC int HTParseInet ARGS2(
+PRIVATE int HTParseInet ARGS2(
 	SockA *,	soc_in,
 	CONST char *,	str)
-{
 #endif /* INET6 */
+{
     char *port;
+#ifdef INET6
+    char portstr[NI_MAXSERV];
+#else
     int dotcount_ip = 0;	/* for dotted decimal IP addr */
     char *strptr;
+#endif
 #ifndef _WINDOWS_NSL
     char *host = NULL;
 #endif /* _WINDOWS_NSL */
@@ -1200,7 +1202,7 @@ PUBLIC int HTParseInet ARGS2(
 	return -1;
     }
 #ifdef _WINDOWS_NSL
-    strncpy(host, str, (size_t)512);
+    strncpy(host, str, sizeof(host));
 #else
     StrAllocCopy(host, str);	/* Make a copy we can mutilate */
 #endif /*  _WINDOWS_NSL */
@@ -1214,11 +1216,12 @@ PUBLIC int HTParseInet ARGS2(
 	port = strrchr(strrchr(host, ']'), ':');
 
     if (port) {
-      *port++ = 0;            /* Chop off port */
+	*port++ = 0;		/* Chop off port */
     }
     else {
-      sprintf(portstr,"%d", default_port);
-      port = portstr;
+	sprintf(portstr,"%d", default_port);
+	port = portstr;
+    }
 #else
     if ((port = strchr(host, ':')) != NULL) {
 	*port++ = 0;		/* Chop off port */
@@ -1233,7 +1236,7 @@ PUBLIC int HTParseInet ARGS2(
 	    soc_in->sin_port = htons((unsigned short)strtol(port,&strptr,10));
 #endif /* Decnet */
 #endif /* Unix vs. VMS */
-#ifdef SUPPRESS 	/* 1. crashes!?!.  2. URL syntax has number not name */
+#ifdef SUPPRESS		/* 1. crashes!?!.  2. URL syntax has number not name */
 	} else {
 	    struct servent * serv = getservbyname(port, (char*)0);
 	    if (serv) {
@@ -1250,8 +1253,8 @@ PUBLIC int HTParseInet ARGS2(
 	    HTAlwaysAlert(NULL, gettext("Address has invalid port"));
 	    return -1;
 	}
-#endif /* INET6 */
     }
+#endif /* INET6 */
 
 #ifdef DECNET
     /*
@@ -1424,11 +1427,11 @@ failed:
     FREE(host);
 #endif /* _WINDOWS_NSL */
     switch (lynx_nsl_status) {
-        case HT_NOT_ACCEPTABLE:
-        case HT_INTERRUPTED:
+	case HT_NOT_ACCEPTABLE:
+	case HT_INTERRUPTED:
 	    return lynx_nsl_status;
-        default:
-        return -1;
+	default:
+	return -1;
     }
 }
 
@@ -1589,14 +1592,12 @@ PUBLIC int HTDoConnect ARGS4(
 	int,		default_port,
 	int *,		s)
 {
-    int status;
+    int status = 0;
     char *line = NULL;
     char *p1 = NULL;
     char *at_sign = NULL;
     char *host = NULL;
 #ifdef INET6
-    int error;
-    struct sockaddr *sa;
     struct addrinfo *res, *res0;
 #else
     struct sockaddr_in soc_address;
@@ -1631,11 +1632,12 @@ PUBLIC int HTDoConnect ARGS4(
     _HTProgress(host);
     res0 = HTGetAddrInfo(host, default_port);
     if (res0 == NULL) {
-	sprintf (line, "Unable to locate remote host %s.", host);
+	HTSprintf0 (&line, gettext("Unable to locate remote host %s."), host);
 	_HTProgress(line);
 	FREE(host);
 	FREE(line);
 	return HT_NO_DATA;
+    }
 #else
     status = HTParseInet(soc_in, host);
     if (status) {
@@ -1656,8 +1658,8 @@ PUBLIC int HTDoConnect ARGS4(
 	FREE(host);
 	FREE(line);
 	return status;
-#endif /* INET6 */
     }
+#endif /* INET6 */
 
     HTSprintf0 (&line, gettext("Making %s connection to %s"), protocol, host);
     _HTProgress (line);
@@ -1675,7 +1677,7 @@ PUBLIC int HTDoConnect ARGS4(
 	    getnameinfo(res->ai_addr, res->ai_addrlen,
 		    hostbuf, sizeof(hostbuf), portbuf, sizeof(portbuf),
 		    NI_NUMERICHOST|NI_NUMERICSERV);
-	    HTSprintf0 (&line, "socket failed: family %d addr %s port %s.",
+	    HTSprintf0 (&line, gettext("socket failed: family %d addr %s port %s."),
 		    res->ai_family, hostbuf, portbuf);
 	    _HTProgress (line);
 	    FREE(line);
@@ -1753,7 +1755,11 @@ PUBLIC int HTDoConnect ARGS4(
     **			       the normal case.
     */
     if ((status < 0) &&
-	(SOCKET_ERRNO == EINPROGRESS || SOCKET_ERRNO == EAGAIN)) {
+	(SOCKET_ERRNO == EINPROGRESS
+#ifdef EAGAIN
+	 || SOCKET_ERRNO == EAGAIN
+#endif
+	 )) {
 	struct timeval timeout;
 	int ret;
 	int tries=0;
@@ -1895,7 +1901,11 @@ PUBLIC int HTDoConnect ARGS4(
 				 sizeof(soc_address));
 #endif /* INET6 */
 		if ((status < 0) &&
-		    (SOCKET_ERRNO != EALREADY && SOCKET_ERRNO != EAGAIN) &&
+		    (SOCKET_ERRNO != EALREADY
+#ifdef EAGAIN
+		    && SOCKET_ERRNO != EAGAIN
+#endif
+		    ) &&
 #ifdef UCX
 		    (SOCKET_ERRNO != 18242) &&
 #endif /* UCX */
@@ -1934,10 +1944,11 @@ PUBLIC int HTDoConnect ARGS4(
 #endif /* INET6 */
 #endif /* !__DJGPP__ */
 #ifdef INET6
-    if (*s < 0) {
+    if (*s < 0)
 #else
-    if (status < 0) {
+    if (status < 0)
 #endif /* INET6 */
+    {
 	/*
 	**  The connect attempt failed or was interrupted,
 	**  so close up the socket.
diff --git a/WWW/Library/Implementation/HTTCP.h b/WWW/Library/Implementation/HTTCP.h
index 345f6077..91f98c80 100644
--- a/WWW/Library/Implementation/HTTCP.h
+++ b/WWW/Library/Implementation/HTTCP.h
@@ -93,34 +93,6 @@ extern int lynx_nsl_status;
 extern struct hostent * LYGetHostByName PARAMS((char * str));
 #endif
 
-
-/*      Parse an internet node address and port
-**      ---------------------------------------
-**
-** On entry:
-**               str points to a string with a node name or number,
-**               with optional trailing colon and port number.
-**               sin points to the binary internet or decnet address field.
-**
-** On exit:
-**         Regular case:
-**               *sin is filled in.  If no port is specified in str, that
-**               field is left unchanged in *sin.
-**         INET6 case:
-**               *sin is filled in.  If no port is specified in str,
-**               default_port is used
-*/
-#if defined(__STDC__) || defined(__BORLANDC__) || defined(_MSC_VER)
-#ifdef INET6
-        extern int HTParseInet(SockA * mysin, CONST char * str, int default_port);
-#else
-        extern int HTParseInet(struct sockaddr_in * mysin, CONST char * str);
-#endif /* INET6 */
-        /*!! had to change this to get it to compile. CTB */
-#else
-        extern int HTParseInet();
-#endif
-
 /*      Get Name of This Machine
 **      ------------------------
 **
diff --git a/WWW/Library/Implementation/www_tcp.h b/WWW/Library/Implementation/www_tcp.h
index d0ed557f..e808919b 100644
--- a/WWW/Library/Implementation/www_tcp.h
+++ b/WWW/Library/Implementation/www_tcp.h
@@ -56,29 +56,6 @@ Default values
 #define INVSOC (-1)             /* Unix invalid socket */
 		/* NB: newer libwww has something different for Windows */
 
-/* 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 */
-#endif
-
-#ifdef INET6
-#ifdef SIN6_LEN
-#define SOCKADDR_LEN(soc_address) ((struct sockaddr *)&soc_address)->sa_len
-#else
-#define SOCKADDR_LEN(soc_address) SA_LEN((struct sockaddr *)&soc_address)
-#endif /* SIN6_LEN */
-#else
-#define SOCKADDR_LEN(soc_address) sizeof(soc_address)
-#endif /* INET6 */
-
 #ifndef VMS
 
 #include <sys/types.h>
@@ -208,9 +185,29 @@ extern int ws_netread(int fd, char *buf, int len);
 #include <direct.h>
 
 /* FIXME: someone might consider porting to winsock2.h */
-#define USE_WINSOCK_H
+#ifdef USE_WINSOCK2_H
+#include <winsock.h>
+
+#undef EINPROGRESS
+#undef EALREADY
+#undef EISCONN
+#undef EINTR
+#undef EAGAIN
+#undef ENOTCONN
+#undef ECONNRESET
+#undef ETIMEDOUT
+
+#define EINPROGRESS  WSAEINPROGRESS
+#define EALREADY     WSAEALREADY
+#define EISCONN      WSAEISCONN
+#define EINTR        WSAEINTR
+/* fine EAGAIN       WSAEAGAIN */
+#define ENOTCONN     WSAENOTCONN
+#define ECONNRESET   WSAECONNRESET
+#define ETIMEDOUT    WSAETIMEDOUT
+
+#else /* USE_WINSOCK_H */
 
-#ifdef USE_WINSOCK_H
 #include <winsock.h>
 typedef struct sockaddr_in SockA;  /* See netinet/in.h */
 
@@ -230,6 +227,7 @@ typedef struct sockaddr_in SockA;  /* See netinet/in.h */
 
 #undef  SOCKET_ERRNO	/* 1997/10/19 (Sun) 18:01:46 */
 #define SOCKET_ERRNO          WSAGetLastError()
+
 #endif	/* USE_WINSOCK_H */
 
 #define INCLUDES_DONE
@@ -804,4 +802,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 */
+#endif
+
+#ifdef INET6
+#ifdef SIN6_LEN
+#define SOCKADDR_LEN(soc_address) ((struct sockaddr *)&soc_address)->sa_len
+#else
+#define SOCKADDR_LEN(soc_address) SA_LEN((struct sockaddr *)&soc_address)
+#endif /* SIN6_LEN */
+#else
+#define SOCKADDR_LEN(soc_address) sizeof(soc_address)
+#endif /* INET6 */
+
 #endif /* TCP_H */