Some patches to enable IPv6 on Windows (tested with MingW
and MSVC6). Some minor cleanups also:
* LYutils.c; fixed extraction of module/system error strings.
* Xsystem.c; use <io.h> for mktemp() prototype.
* HTTCP.c; don't use global host[], fixed call-convention of thread-
function (must be __stdcall). Sets pending WSAHOST_NOT_FOUND
error status.
* HTTP.c; _thread_func() wasn't __stdcall.
* LYexit.c; avoid redeclaring error of exit() in <process.h>.
IMHO it's very bad to shadow ANSI functions like this.
Should call LYexit() explicitly.
* www_tcp.h; cleanup for MSVC and IPv6 headers and macros.
Increase MAXHOSTNAMELEN to 128. Hopefully the indenting
makes it more readable.
Now for the weird problem; I cannot make S-Lang 1.4.9 work with
MSVC. It works fine with MingW. Anybody been able to use that
combo (MSVC6+S-Lang)?
--gv
--- orig/lynx2-8-6/src/LYUtils.c Mon May 24 00:59:56 2004
+++ src/LYUtils.c Tue May 25 17:44:22 2004
@@ -7557,6 +7557,12 @@
#define WSABASEERR 10000
#endif
+#ifdef ENABLE_IPV6
+#define WSOCK_NAME "ws2_32"
+#else
+#define WSOCK_NAME "wsock32"
+#endif
+
/*
* Description: the windows32 version of perror()
*
@@ -7570,13 +7576,13 @@
/* __declspec(thread) necessary if you will use multiple threads */
#ifdef __CYGWIN__
static char msg_buff[256];
-
#else
__declspec(thread) static char msg_buff[256];
#endif
HMODULE hModule;
int i, msg_type;
unsigned char *p, *q, tmp_buff[256];
+ DWORD rc;
hModule = NULL;
msg_type = FORMAT_MESSAGE_FROM_SYSTEM;
@@ -7589,22 +7595,20 @@
* Special code for winsock error handling.
*/
if (ercode > WSABASEERR) {
- hModule = GetModuleHandle("wsock32");
- if (hModule == NULL)
- ercode = GetLastError();
- else
+ hModule = GetModuleHandle(WSOCK_NAME);
+ if (hModule)
msg_type = FORMAT_MESSAGE_FROM_HMODULE;
}
/*
- * message handling
+ * message handling. If not found in module, retry from system.
*/
- FormatMessage(msg_type,
- hModule,
- ercode,
- LANG_NEUTRAL,
- msg_buff,
- sizeof(msg_buff),
- NULL);
+ rc = FormatMessage(msg_type, hModule, ercode, LANG_NEUTRAL,
+ msg_buff, sizeof(msg_buff), NULL);
+
+ if (rc == 0 && msg_type == FORMAT_MESSAGE_FROM_HMODULE) {
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, ercode,
+ LANG_NEUTRAL, msg_buff, sizeof(msg_buff), NULL);
+ }
strcpy(tmp_buff, msg_buff);
p = q = tmp_buff;
--- orig/lynx2-8-6/src/Xsystem.c Fri May 07 02:31:33 2004
+++ src/Xsystem.c Tue May 25 21:04:25 2004
@@ -25,21 +25,14 @@
*
*/
#include <LYUtils.h>
+#include <LYStrings.h>
-#if 0
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
+#ifdef DOSPATH
#include <io.h>
-#include <process.h>
-#ifndef __CYGWIN__
-#include <dos.h>
-#endif
+#else
+extern char *mktemp(char *);
#endif
-#include <LYStrings.h>
-
#ifndef USECMDLINE
#define USECMDLINE 0
#endif
@@ -52,8 +45,6 @@
#define TABLESIZE(v) (sizeof(v)/sizeof(v[0]))
#define STR_MAX 512 /* MAX command line */
-
-extern char *mktemp(char *);
#define isk1(c) ((0x81 <= UCH(c) && UCH(c) <= 0x9F) || (0xE0 <= UCH(c) && UCH(c) <=
0xFC))
#define isq(c) ((c) == '"')
--- orig/lynx2-8-6/WWW/Library/Implementation/HTTCP.c Fri May 07 02:31:33 2004
+++ WWW/Library/Implementation/HTTCP.c Tue May 25 21:38:25 2004
@@ -104,17 +104,17 @@
* 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 +643,7 @@
*/
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 +694,6 @@
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 +1097,7 @@
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 +1105,12 @@
#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 +1187,7 @@
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 +1198,7 @@
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 +1227,7 @@
#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 +1273,7 @@
#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 +1281,7 @@
#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 +1323,7 @@
}
#endif /* _WINDOWS_NSL */
-#ifndef _WINDOWS_NSL
FREE(host);
-#endif /* _WINDOWS_NSL */
-
} /* Alphanumeric node name */
CTRACE((tfp,
@@ -1360,9 +1340,7 @@
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 +1590,7 @@
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) {
--- orig/lynx2-8-6/WWW/Library/Implementation/HTTP.c Mon May 24 00:59:56 2004
+++ WWW/Library/Implementation/HTTP.c Tue May 25 21:00:23 2004
@@ -209,7 +209,7 @@
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 @@
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 @@
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 *) ¶, 0UL, &dwThreadID);
if (hThread == 0) {
--- orig/lynx2-8-6/WWW/Library/Implementation/LYexit.h Fri May 07 02:31:33 2004
+++ WWW/Library/Implementation/LYexit.h Tue May 25 18:06:01 2004
@@ -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)
--- orig/lynx2-8-6/WWW/Library/Implementation/www_tcp.h Mon May 24 00:59:56 2004
+++ WWW/Library/Implementation/www_tcp.h Tue May 25 21:06:59 2004
@@ -176,8 +176,8 @@
#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 @@
#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 @@
#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 @@
#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 @@
#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,39 +840,45 @@
#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
+/*
+ * 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
-#ifdef SIN6_LEN
-#define SOCKADDR_LEN(soc_address) ((struct sockaddr *)&soc_address)->sa_len
-#else
-#ifndef SA_LEN
-#define SA_LEN(x) (((x)->sa_family == AF_INET6) \
+ typedef struct sockaddr_storage SockA;
+ #ifdef SIN6_LEN
+ #define SOCKADDR_LEN(soc_address) ((struct sockaddr *)&soc_address)->sa_len
+ #else
+ #ifndef SA_LEN
+ #define SA_LEN(x) (((x)->sa_family == AF_INET6) \
? sizeof(struct sockaddr_in6) \
: (((x)->sa_family == AF_INET) \
? sizeof(struct sockaddr_in) \
- : sizeof(struct sockaddr)))
-#endif
-#define SOCKADDR_LEN(soc_address) SA_LEN((struct sockaddr *)&soc_address)
-#endif /* SIN6_LEN */
+ : sizeof(struct sockaddr))) /* AF_UNSPEC? */
+ #endif
+ #define SOCKADDR_LEN(soc_address) SA_LEN((struct sockaddr *)&soc_address)
+ #endif /* SIN6_LEN */
#else
-#define SOCKADDR_LEN(soc_address) sizeof(soc_address)
+ 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 */
_______________________________________________
Lynx-dev mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/lynx-dev