File wpcap-w2k.patch of Package mingw64-wpcap
--- wpcap/libpcap/Makefile.in.w2k 2011-11-30 22:32:31.263582325 +0100
+++ wpcap/libpcap/Makefile.in 2011-11-30 22:35:42.844865268 +0100
@@ -86,13 +86,27 @@
etherent.c savefile.c bpf_filter.c bpf_image.c bpf_dump.c
GENSRC = scanner.c grammar.c version.c
# HAVE_REMOTE
-REMOTESRC = @V_REMOTE_FILES@
+REMOTESRC = @V_REMOTE_FILES@ \
+ WspiapiClone.c \
+ WspiapiFreeAddrInfo.c \
+ WspiapiGetAddrInfo.c \
+ WspiapiGetNameInfo.c \
+ WspiapiLegacyFreeAddrInfo.c \
+ WspiapiLegacyGetAddrInfo.c \
+ WspiapiLegacyGetNameInfo.c \
+ WspiapiLoad.c \
+ WspiapiLookupNode.c \
+ WspiapiNewAddrInfo.c \
+ WspiapiParseV4Address.c \
+ WspiapiQueryDNS.c \
+ WspiapiStrdup.c
TCSRC = @V_TC_FILES@
LIBOBJS = @LIBOBJS@
# HAVE_REMOTE
SRC = $(PSRC) $(FSRC) $(CSRC) $(SSRC) $(GENSRC) $(TCSRC) $(REMOTESRC)
+
# We would like to say "OBJ = $(SRC:.c=.o)" but Ultrix's make cannot
# hack the extra indirection
# HAVE_REMOTE
@@ -118,7 +132,8 @@
pcap-namedb.h \
pcap-stdinc.h \
ppp.h \
- sunatmpos.h
+ sunatmpos.h \
+ wspiapi.h
GENHDR = \
scanner.h tokdefs.h version.h
--- wpcap/libpcap/WspiapiClone.c.w2k 2011-11-30 22:31:14.690287820 +0100
+++ wpcap/libpcap/WspiapiClone.c 2011-11-30 22:31:14.690287820 +0100
@@ -0,0 +1,28 @@
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#undef __CRT__NO_INLINE
+#define __CRT__NO_INLINE
+#include <winsock2.h>
+#include <wspiapi.h>
+
+int WINAPI
+WspiapiClone (WORD wPort, struct addrinfo *ptResult)
+{
+ struct addrinfo *p = NULL;
+ struct addrinfo *n = NULL;
+
+ for (p = ptResult; p != NULL;)
+ {
+ n = WspiapiNewAddrInfo (SOCK_DGRAM, p->ai_protocol, wPort,
+ ((struct sockaddr_in *) p->ai_addr)->sin_addr.s_addr);
+ if (!n)
+ break;
+ n->ai_next = p->ai_next;
+ p->ai_next = n;
+ p = n->ai_next;
+ }
+ if (p != NULL)
+ return EAI_MEMORY;
+ return 0;
+}
--- wpcap/libpcap/WspiapiFreeAddrInfo.c.w2k 2011-11-30 22:31:14.690287820 +0100
+++ wpcap/libpcap/WspiapiFreeAddrInfo.c 2011-11-30 22:31:14.690287820 +0100
@@ -0,0 +1,17 @@
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#undef __CRT__NO_INLINE
+#define __CRT__NO_INLINE
+#include <winsock2.h>
+#include <wspiapi.h>
+
+void WINAPI
+WspiapiFreeAddrInfo (struct addrinfo *ai)
+{
+ static WSPIAPI_PFREEADDRINFO pfFreeAddrInfo = NULL;
+
+ if (!pfFreeAddrInfo)
+ pfFreeAddrInfo = (WSPIAPI_PFREEADDRINFO) WspiapiLoad(2);
+ (*pfFreeAddrInfo) (ai);
+}
--- wpcap/libpcap/WspiapiGetAddrInfo.c.w2k 2011-11-30 22:31:14.691287837 +0100
+++ wpcap/libpcap/WspiapiGetAddrInfo.c 2011-11-30 22:31:14.691287837 +0100
@@ -0,0 +1,21 @@
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#undef __CRT__NO_INLINE
+#define __CRT__NO_INLINE
+#include <winsock2.h>
+#include <wspiapi.h>
+
+int WINAPI
+WspiapiGetAddrInfo(const char *nodename, const char *servname,
+ const struct addrinfo *hints, struct addrinfo **res)
+{
+ static WSPIAPI_PGETADDRINFO pfGetAddrInfo = NULL;
+ int err;
+
+ if (!pfGetAddrInfo)
+ pfGetAddrInfo = (WSPIAPI_PGETADDRINFO) WspiapiLoad (0);
+ err = (*pfGetAddrInfo) (nodename, servname, hints, res);
+ WSASetLastError (err);
+ return err;
+}
--- wpcap/libpcap/WspiapiGetNameInfo.c.w2k 2011-11-30 22:31:14.691287837 +0100
+++ wpcap/libpcap/WspiapiGetNameInfo.c 2011-11-30 22:31:14.691287837 +0100
@@ -0,0 +1,22 @@
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#undef __CRT__NO_INLINE
+#define __CRT__NO_INLINE
+#include <winsock2.h>
+#include <wspiapi.h>
+
+int WINAPI
+WspiapiGetNameInfo (const struct sockaddr *sa, socklen_t salen,
+ char *host, size_t hostlen,
+ char *serv, size_t servlen, int flags)
+{
+ static WSPIAPI_PGETNAMEINFO pfGetNameInfo = NULL;
+ int err;
+
+ if (!pfGetNameInfo)
+ pfGetNameInfo = (WSPIAPI_PGETNAMEINFO) WspiapiLoad(1);
+ err = (*pfGetNameInfo) (sa, salen, host, hostlen, serv, servlen, flags);
+ WSASetLastError (err);
+ return err;
+}
--- wpcap/libpcap/WspiapiLegacyFreeAddrInfo.c.w2k 2011-11-30 22:31:14.691287837 +0100
+++ wpcap/libpcap/WspiapiLegacyFreeAddrInfo.c 2011-11-30 22:31:14.691287837 +0100
@@ -0,0 +1,23 @@
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#undef __CRT__NO_INLINE
+#define __CRT__NO_INLINE
+#include <winsock2.h>
+#include <wspiapi.h>
+
+void WINAPI
+WspiapiLegacyFreeAddrInfo (struct addrinfo *ptHead)
+{
+ struct addrinfo *p;
+
+ for (p = ptHead; p != NULL; p = ptHead)
+ {
+ if (p->ai_canonname)
+ WspiapiFree (p->ai_canonname);
+ if (p->ai_addr)
+ WspiapiFree (p->ai_addr);
+ ptHead = p->ai_next;
+ WspiapiFree (p);
+ }
+}
--- wpcap/libpcap/WspiapiLegacyGetAddrInfo.c.w2k 2011-11-30 22:31:14.691287837 +0100
+++ wpcap/libpcap/WspiapiLegacyGetAddrInfo.c 2011-11-30 22:31:14.691287837 +0100
@@ -0,0 +1,112 @@
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#undef __CRT__NO_INLINE
+#define __CRT__NO_INLINE
+#include <winsock2.h>
+#include <wspiapi.h>
+
+int WINAPI
+WspiapiLegacyGetAddrInfo(const char *pszNodeName,
+ const char *pszServiceName,
+ const struct addrinfo *ptHints,
+ struct addrinfo **pptResult)
+{
+ int err = 0, iFlags = 0, iFamily = PF_UNSPEC, iSocketType = 0, iProtocol = 0;
+ struct in_addr inAddress;
+ struct servent *svc = NULL;
+ char *pc = NULL;
+ WINBOOL isCloned = FALSE;
+ WORD tcpPort = 0, udpPort = 0, port = 0;
+
+ *pptResult = NULL;
+ if (!pszNodeName && !pszServiceName)
+ return EAI_NONAME;
+ if (ptHints)
+ {
+ if (ptHints->ai_addrlen != 0 || ptHints->ai_canonname != NULL
+ || ptHints->ai_addr!=NULL || ptHints->ai_next != NULL)
+ return EAI_FAIL;
+ iFlags = ptHints->ai_flags;
+ if ((iFlags & AI_CANONNAME) != 0 && !pszNodeName)
+ return EAI_BADFLAGS;
+ iFamily = ptHints->ai_family;
+ if (iFamily != PF_UNSPEC && iFamily != PF_INET)
+ return EAI_FAMILY;
+ iSocketType = ptHints->ai_socktype;
+ if (iSocketType != 0 && iSocketType != SOCK_STREAM && iSocketType != SOCK_DGRAM
+ && iSocketType != SOCK_RAW)
+ return EAI_SOCKTYPE;
+ iProtocol = ptHints->ai_protocol;
+ }
+
+ if (pszServiceName)
+ {
+ port = (WORD) strtoul (pszServiceName, &pc, 10);
+ if(*pc == 0)
+ {
+ port = tcpPort = udpPort = htons (port);
+ if (iSocketType == 0)
+ {
+ isCloned = TRUE;
+ iSocketType = SOCK_STREAM;
+ }
+ }
+ else
+ {
+ if (iSocketType == 0 || iSocketType == SOCK_DGRAM)
+ {
+ svc = getservbyname(pszServiceName, "udp");
+ if (svc)
+ port = udpPort = svc->s_port;
+ }
+ if (iSocketType == 0 || iSocketType == SOCK_STREAM)
+ {
+ svc = getservbyname(pszServiceName, "tcp");
+ if (svc)
+ port = tcpPort = svc->s_port;
+ }
+ if (port == 0)
+ return (iSocketType ? EAI_SERVICE : EAI_NONAME);
+ if (iSocketType==0)
+ {
+ iSocketType = (tcpPort) ? SOCK_STREAM : SOCK_DGRAM;
+ isCloned = (tcpPort && udpPort);
+ }
+ }
+ }
+ if (!pszNodeName || WspiapiParseV4Address(pszNodeName,&inAddress.s_addr))
+ {
+ if (!pszNodeName)
+ {
+ inAddress.s_addr = htonl ((iFlags & AI_PASSIVE) ? INADDR_ANY : INADDR_LOOPBACK);
+ }
+ *pptResult = WspiapiNewAddrInfo(iSocketType, iProtocol, port, inAddress.s_addr);
+ if (!(*pptResult))
+ err = EAI_MEMORY;
+ if (!err && pszNodeName)
+ {
+ (*pptResult)->ai_flags |= AI_NUMERICHOST;
+ if (iFlags & AI_CANONNAME)
+ {
+ (*pptResult)->ai_canonname =
+ WspiapiStrdup (inet_ntoa (inAddress));
+ if (!(*pptResult)->ai_canonname)
+ err = EAI_MEMORY;
+ }
+ }
+ }
+ else if (iFlags & AI_NUMERICHOST)
+ err = EAI_NONAME;
+ else
+ err = WspiapiLookupNode (pszNodeName, iSocketType, iProtocol, port,
+ (iFlags & AI_CANONNAME), pptResult);
+ if (!err && isCloned)
+ err = WspiapiClone(udpPort, *pptResult);
+ if (err)
+ {
+ WspiapiLegacyFreeAddrInfo (*pptResult);
+ *pptResult = NULL;
+ }
+ return err;
+}
--- wpcap/libpcap/WspiapiLegacyGetNameInfo.c.w2k 2011-11-30 22:31:14.691287837 +0100
+++ wpcap/libpcap/WspiapiLegacyGetNameInfo.c 2011-11-30 22:31:14.691287837 +0100
@@ -0,0 +1,88 @@
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#undef __CRT__NO_INLINE
+#define __CRT__NO_INLINE
+#include <winsock2.h>
+#include <wspiapi.h>
+
+int WINAPI
+WspiapiLegacyGetNameInfo (const struct sockaddr *ptSocketAddress,
+ socklen_t tSocketLength,
+ char *pszNodeName, size_t tNodeLength,
+ char *pszServiceName, size_t tServiceLength,
+ int iFlags)
+{
+ struct servent *svc;
+ WORD port;
+ char str[] = "65535";
+ char *pstr = str;
+ struct hostent *phost;
+ struct in_addr l_inaddr;
+ char *pnode = NULL, *pc = NULL;
+
+ if (!ptSocketAddress || tSocketLength < (int) sizeof (struct sockaddr))
+ return EAI_FAIL;
+ if (ptSocketAddress->sa_family != AF_INET)
+ return EAI_FAMILY;
+ if (tSocketLength < (int) sizeof (struct sockaddr_in))
+ return EAI_FAIL;
+ if (!(pszNodeName && tNodeLength) && !(pszServiceName && tServiceLength))
+ return EAI_NONAME;
+ if ((iFlags & NI_NUMERICHOST) != 0 && (iFlags & NI_NAMEREQD) != 0)
+ return EAI_BADFLAGS;
+ if (pszServiceName && tServiceLength)
+ {
+ port = ((struct sockaddr_in *) ptSocketAddress)->sin_port;
+ if (iFlags & NI_NUMERICSERV)
+ sprintf (str, "%u", ntohs (port));
+ else
+ {
+ svc = getservbyport(port, (iFlags & NI_DGRAM) ? "udp" : NULL);
+ if (svc && svc->s_name)
+ pstr = svc->s_name;
+ else
+ sprintf (str, "%u", ntohs (port));
+ }
+ if (tServiceLength > strlen (pstr))
+ strcpy (pszServiceName, pstr);
+ else
+ return EAI_FAIL;
+ }
+ if (pszNodeName && tNodeLength)
+ {
+ l_inaddr = ((struct sockaddr_in *) ptSocketAddress)->sin_addr;
+ if (iFlags & NI_NUMERICHOST)
+ pnode = inet_ntoa (l_inaddr);
+ else
+ {
+ phost = gethostbyaddr ((char *) &l_inaddr, sizeof (struct in_addr), AF_INET);
+ if (phost && phost->h_name)
+ {
+ pnode = phost->h_name;
+ if ((iFlags & NI_NOFQDN) != 0 && ((pc = strchr (pnode,'.')) != NULL))
+ *pc = 0;
+ }
+ else
+ {
+ if ((iFlags & NI_NAMEREQD) != 0)
+ {
+ switch(WSAGetLastError())
+ {
+ case WSAHOST_NOT_FOUND: return EAI_NONAME;
+ case WSATRY_AGAIN: return EAI_AGAIN;
+ case WSANO_RECOVERY: return EAI_FAIL;
+ default: return EAI_NONAME;
+ }
+ }
+ else
+ pnode = inet_ntoa (l_inaddr);
+ }
+ }
+ if (tNodeLength > strlen (pnode))
+ strcpy (pszNodeName, pnode);
+ else
+ return EAI_FAIL;
+ }
+ return 0;
+}
--- wpcap/libpcap/WspiapiLoad.c.w2k 2011-11-30 22:31:14.691287837 +0100
+++ wpcap/libpcap/WspiapiLoad.c 2011-11-30 22:31:14.691287837 +0100
@@ -0,0 +1,75 @@
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#undef __CRT__NO_INLINE
+#define __CRT__NO_INLINE
+#include <winsock2.h>
+#include <wspiapi.h>
+
+FARPROC WINAPI
+WspiapiLoad (WORD wFunction)
+{
+ static WINBOOL isinit = FALSE;
+ static WSPIAPI_FUNCTION rgtGlobal[] = WSPIAPI_FUNCTION_ARRAY;
+ static const int iNumGlobal = (sizeof(rgtGlobal) / sizeof(WSPIAPI_FUNCTION));
+ HMODULE hlib = NULL;
+ WSPIAPI_FUNCTION rgtLocal[] = WSPIAPI_FUNCTION_ARRAY;
+ FARPROC fScratch = NULL;
+ int i = 0;
+
+ if (isinit)
+ return rgtGlobal[wFunction].pfAddress;
+
+ for (;;)
+ {
+ CHAR systemdir[MAX_PATH + 1], path[MAX_PATH + 8];
+
+ if (GetSystemDirectoryA (systemdir, MAX_PATH) == 0)
+ break;
+ strcpy (path, systemdir);
+ strcat (path, "\\ws2_32");
+ hlib = LoadLibraryA (path);
+ if(hlib != NULL)
+ {
+ fScratch = GetProcAddress (hlib, "getaddrinfo");
+ if (!fScratch)
+ {
+ FreeLibrary (hlib);
+ hlib = NULL;
+ }
+ }
+ if (hlib != NULL)
+ break;
+ strcpy (path, systemdir);
+ strcat (path, "\\wship6");
+ hlib = LoadLibraryA (path);
+ if (hlib != NULL)
+ {
+ if ((fScratch = GetProcAddress (hlib, "getaddrinfo")) == NULL)
+ {
+ FreeLibrary (hlib);
+ hlib = NULL;
+ }
+ }
+ break;
+ }
+ if (hlib != NULL)
+ {
+ for (i = 0; i < iNumGlobal; i++)
+ {
+ if ((rgtLocal[i].pfAddress = GetProcAddress (hlib, rgtLocal[i].pszName)) == NULL)
+ {
+ FreeLibrary (hlib);
+ hlib = NULL;
+ break;
+ }
+ }
+ if (hlib != NULL)
+ {
+ for (i = 0; i < iNumGlobal; i++)
+ rgtGlobal[i].pfAddress = rgtLocal[i].pfAddress;
+ }
+ }
+ isinit = TRUE;
+ return rgtGlobal[wFunction].pfAddress;
+}
--- wpcap/libpcap/WspiapiLookupNode.c.w2k 2011-11-30 22:31:14.691287837 +0100
+++ wpcap/libpcap/WspiapiLookupNode.c 2011-11-30 22:31:14.691287837 +0100
@@ -0,0 +1,44 @@
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#undef __CRT__NO_INLINE
+#define __CRT__NO_INLINE
+#include <winsock2.h>
+#include <wspiapi.h>
+
+int WINAPI
+WspiapiLookupNode (const char *pszNodeName,
+ int iSocketType, int iProtocol,
+ WORD wPort, WINBOOL bAI_CANONNAME,
+ struct addrinfo **pptResult)
+{
+ int err = 0, cntAlias = 0;
+ char name[NI_MAXHOST] = "";
+ char alias[NI_MAXHOST] = "";
+ char *pname = name, *palias = alias, *tmp = NULL;
+
+ strncpy (pname, pszNodeName, NI_MAXHOST - 1);
+ pname[NI_MAXHOST - 1] = 0;
+ for (;;)
+ {
+ err = WspiapiQueryDNS (pszNodeName, iSocketType, iProtocol, wPort, palias, pptResult);
+ if (err)
+ break;
+ if (*pptResult)
+ break;
+ ++cntAlias;
+ if (strlen (palias) == 0 || !strcmp (pname, palias) || cntAlias == 16)
+ {
+ err = EAI_FAIL;
+ break;
+ }
+ WspiapiSwap(pname, palias, tmp);
+ }
+ if (!err && bAI_CANONNAME)
+ {
+ (*pptResult)->ai_canonname = WspiapiStrdup (palias);
+ if (!(*pptResult)->ai_canonname)
+ err = EAI_MEMORY;
+ }
+ return err;
+}
--- wpcap/libpcap/WspiapiNewAddrInfo.c.w2k 2011-11-30 22:31:14.691287837 +0100
+++ wpcap/libpcap/WspiapiNewAddrInfo.c 2011-11-30 22:31:14.691287837 +0100
@@ -0,0 +1,31 @@
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#undef __CRT__NO_INLINE
+#define __CRT__NO_INLINE
+#include <winsock2.h>
+#include <wspiapi.h>
+
+struct addrinfo * WINAPI
+WspiapiNewAddrInfo (int iSocketType, int iProtocol, WORD wPort, DWORD dwAddress)
+{
+ struct addrinfo *n;
+ struct sockaddr_in *pa;
+
+ if ((n = (struct addrinfo *) WspiapiMalloc (sizeof (struct addrinfo))) == NULL)
+ return NULL;
+ if ((pa = (struct sockaddr_in *) WspiapiMalloc (sizeof(struct sockaddr_in))) == NULL)
+ {
+ WspiapiFree(n);
+ return NULL;
+ }
+ pa->sin_family = AF_INET;
+ pa->sin_port = wPort;
+ pa->sin_addr.s_addr = dwAddress;
+ n->ai_family = PF_INET;
+ n->ai_socktype = iSocketType;
+ n->ai_protocol = iProtocol;
+ n->ai_addrlen = sizeof (struct sockaddr_in);
+ n->ai_addr = (struct sockaddr *) pa;
+ return n;
+}
--- wpcap/libpcap/WspiapiParseV4Address.c.w2k 2011-11-30 22:31:14.692287854 +0100
+++ wpcap/libpcap/WspiapiParseV4Address.c 2011-11-30 22:31:14.692287854 +0100
@@ -0,0 +1,26 @@
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#undef __CRT__NO_INLINE
+#define __CRT__NO_INLINE
+#include <winsock2.h>
+#include <wspiapi.h>
+
+WINBOOL WINAPI
+WspiapiParseV4Address (const char *pszAddress, PDWORD pdwAddress)
+{
+ DWORD dwAddress = 0;
+ const char *h = NULL;
+ int cnt;
+
+ for (cnt = 0,h = pszAddress; *h != 0; h++)
+ if (h[0] == '.')
+ cnt++;
+ if (cnt != 3)
+ return FALSE;
+ dwAddress = inet_addr (pszAddress);
+ if (dwAddress == INADDR_NONE)
+ return FALSE;
+ *pdwAddress = dwAddress;
+ return TRUE;
+}
--- wpcap/libpcap/WspiapiQueryDNS.c.w2k 2011-11-30 22:31:14.692287854 +0100
+++ wpcap/libpcap/WspiapiQueryDNS.c 2011-11-30 22:31:14.692287854 +0100
@@ -0,0 +1,48 @@
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#undef __CRT__NO_INLINE
+#define __CRT__NO_INLINE
+#include <winsock2.h>
+#include <wspiapi.h>
+
+int WINAPI
+WspiapiQueryDNS(const char *pszNodeName,
+ int iSocketType, int iProtocol,
+ WORD wPort, char pszAlias[NI_MAXHOST],
+ struct addrinfo **pptResult)
+{
+ struct addrinfo **paddrinfo = pptResult;
+ struct hostent *phost = NULL;
+ char **h;
+
+ *paddrinfo = NULL;
+ pszAlias[0] = 0;
+ phost = gethostbyname (pszNodeName);
+ if (phost)
+ {
+ if (phost->h_addrtype == AF_INET && phost->h_length == sizeof(struct in_addr))
+ {
+ for (h = phost->h_addr_list; *h != NULL; h++)
+ {
+ *paddrinfo = WspiapiNewAddrInfo (iSocketType, iProtocol, wPort,
+ ((struct in_addr *) *h)->s_addr);
+ if (!*paddrinfo)
+ return EAI_MEMORY;
+ paddrinfo = &((*paddrinfo)->ai_next);
+ }
+ }
+ strncpy (pszAlias, phost->h_name, NI_MAXHOST - 1);
+ pszAlias[NI_MAXHOST - 1] = 0;
+ return 0;
+ }
+ switch(WSAGetLastError())
+ {
+ case WSAHOST_NOT_FOUND: break;
+ case WSATRY_AGAIN: return EAI_AGAIN;
+ case WSANO_RECOVERY: return EAI_FAIL;
+ case WSANO_DATA: return EAI_NODATA;
+ default: break;
+ }
+ return EAI_NONAME;
+}
--- wpcap/libpcap/WspiapiStrdup.c.w2k 2011-11-30 22:31:14.692287854 +0100
+++ wpcap/libpcap/WspiapiStrdup.c 2011-11-30 22:31:14.692287854 +0100
@@ -0,0 +1,23 @@
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#undef __CRT__NO_INLINE
+#define __CRT__NO_INLINE
+#include <winsock2.h>
+#include <wspiapi.h>
+
+char * WINAPI
+WspiapiStrdup (const char *pszString)
+{
+ char *rstr;
+ size_t szlen;
+
+ if(!pszString)
+ return NULL;
+ szlen = strlen(pszString) + 1;
+ rstr = (char *) WspiapiMalloc (szlen);
+ if (!rstr)
+ return NULL;
+ strcpy (rstr, pszString);
+ return rstr;
+}
--- wpcap/libpcap/wspiapi.h.w2k 2011-11-30 22:31:22.016411156 +0100
+++ wpcap/libpcap/wspiapi.h 2011-11-30 22:31:22.016411156 +0100
@@ -0,0 +1,207 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the w64 mingw-runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#ifndef _WSPIAPI_H_
+#define _WSPIAPI_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <string.h>
+#include <ws2tcpip.h>
+
+//#include <_mingw_print_push.h>
+
+#define _WSPIAPI_STRCPY_S(_Dst,_Size,_Src) strcpy((_Dst),(_Src))
+#define _WSPIAPI_STRCAT_S(_Dst,_Size,_Src) strcat((_Dst),(_Src))
+#define _WSPIAPI_STRNCPY_S(_Dst,_Size,_Src,_Count) strncpy((_Dst),(_Src),(_Count)); (_Dst)[(_Size) - 1] = 0
+#define _WSPIAPI_SPRINTF_S_1(_Dst,_Size,_Format,_Arg1) sprintf((_Dst),(_Format),(_Arg1))
+
+#ifndef _WSPIAPI_COUNTOF
+#ifndef __cplusplus
+#define _WSPIAPI_COUNTOF(_Array) (sizeof(_Array) / sizeof(_Array[0]))
+#else
+template <typename __CountofType,size_t _N> char (&__wspiapi_countof_helper(__CountofType (&_Array)[_N]))[_N];
+#define _WSPIAPI_COUNTOF(_Array) sizeof(__wspiapi_countof_helper(_Array))
+#endif
+#endif
+
+#define WspiapiMalloc(tSize) calloc(1,(tSize))
+#define WspiapiFree(p) free(p)
+#define WspiapiSwap(a,b,c) { (c) = (a); (a) = (b); (b) = (c); }
+#define getaddrinfo WspiapiGetAddrInfo
+#define getnameinfo WspiapiGetNameInfo
+#define freeaddrinfo WspiapiFreeAddrInfo
+
+typedef int (WINAPI *WSPIAPI_PGETADDRINFO)(const char *nodename,const char *servname,const struct addrinfo *hints,struct addrinfo **res);
+typedef int (WINAPI *WSPIAPI_PGETNAMEINFO)(const struct sockaddr *sa,socklen_t salen,char *host,size_t hostlen,char *serv,size_t servlen,int flags);
+typedef void (WINAPI *WSPIAPI_PFREEADDRINFO)(struct addrinfo *ai);
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ typedef struct {
+ char const *pszName;
+ FARPROC pfAddress;
+ } WSPIAPI_FUNCTION;
+
+#define WSPIAPI_FUNCTION_ARRAY { { "getaddrinfo",(FARPROC) WspiapiLegacyGetAddrInfo }, \
+ { "getnameinfo",(FARPROC) WspiapiLegacyGetNameInfo }, \
+ { "freeaddrinfo",(FARPROC) WspiapiLegacyFreeAddrInfo } }
+
+ char *WINAPI WspiapiStrdup (const char *pszString);
+ WINBOOL WINAPI WspiapiParseV4Address (const char *pszAddress,PDWORD pdwAddress);
+ struct addrinfo * WINAPI WspiapiNewAddrInfo (int iSocketType,int iProtocol,WORD wPort,DWORD dwAddress);
+ int WINAPI WspiapiQueryDNS (const char *pszNodeName,int iSocketType,int iProtocol,WORD wPort,char pszAlias[NI_MAXHOST],struct addrinfo **pptResult);
+ int WINAPI WspiapiLookupNode (const char *pszNodeName,int iSocketType,int iProtocol,WORD wPort,WINBOOL bAI_CANONNAME,struct addrinfo **pptResult);
+ int WINAPI WspiapiClone (WORD wPort,struct addrinfo *ptResult);
+ void WINAPI WspiapiLegacyFreeAddrInfo (struct addrinfo *ptHead);
+ int WINAPI WspiapiLegacyGetAddrInfo(const char *pszNodeName,const char *pszServiceName,const struct addrinfo *ptHints,struct addrinfo **pptResult);
+ int WINAPI WspiapiLegacyGetNameInfo(const struct sockaddr *ptSocketAddress,socklen_t tSocketLength,char *pszNodeName,size_t tNodeLength,char *pszServiceName,size_t tServiceLength,int iFlags);
+ FARPROC WINAPI WspiapiLoad(WORD wFunction);
+ int WINAPI WspiapiGetAddrInfo(const char *nodename,const char *servname,const struct addrinfo *hints,struct addrinfo **res);
+ int WINAPI WspiapiGetNameInfo (const struct sockaddr *sa,socklen_t salen,char *host,size_t hostlen,char *serv,size_t servlen,int flags);
+ void WINAPI WspiapiFreeAddrInfo (struct addrinfo *ai);
+
+#ifndef __CRT__NO_INLINE
+ __CRT_INLINE char * WINAPI
+ WspiapiStrdup (const char *pszString)
+ {
+ char *rstr;
+ size_t szlen;
+
+ if(!pszString)
+ return NULL;
+ szlen = strlen(pszString) + 1;
+ rstr = (char *) WspiapiMalloc (szlen);
+ if (!rstr)
+ return NULL;
+ strcpy (rstr, pszString);
+ return rstr;
+ }
+
+ __CRT_INLINE WINBOOL WINAPI
+ WspiapiParseV4Address (const char *pszAddress, PDWORD pdwAddress)
+ {
+ DWORD dwAddress = 0;
+ const char *h = NULL;
+ int cnt;
+
+ for (cnt = 0,h = pszAddress; *h != 0; h++)
+ if (h[0] == '.')
+ cnt++;
+ if (cnt != 3)
+ return FALSE;
+ dwAddress = inet_addr (pszAddress);
+ if (dwAddress == INADDR_NONE)
+ return FALSE;
+ *pdwAddress = dwAddress;
+ return TRUE;
+ }
+
+ __CRT_INLINE struct addrinfo * WINAPI
+ WspiapiNewAddrInfo (int iSocketType,int iProtocol, WORD wPort,DWORD dwAddress)
+ {
+ struct addrinfo *n;
+ struct sockaddr_in *pa;
+
+ if ((n = (struct addrinfo *) WspiapiMalloc (sizeof (struct addrinfo))) == NULL)
+ return NULL;
+ if ((pa = (struct sockaddr_in *) WspiapiMalloc (sizeof(struct sockaddr_in))) == NULL)
+ {
+ WspiapiFree(n);
+ return NULL;
+ }
+ pa->sin_family = AF_INET;
+ pa->sin_port = wPort;
+ pa->sin_addr.s_addr = dwAddress;
+ n->ai_family = PF_INET;
+ n->ai_socktype = iSocketType;
+ n->ai_protocol = iProtocol;
+ n->ai_addrlen = sizeof (struct sockaddr_in);
+ n->ai_addr = (struct sockaddr *) pa;
+ return n;
+ }
+
+ __CRT_INLINE int WINAPI
+ WspiapiLookupNode (const char *pszNodeName, int iSocketType, int iProtocol, WORD wPort,
+ WINBOOL bAI_CANONNAME, struct addrinfo **pptResult)
+ {
+ int err = 0, cntAlias = 0;
+ char name[NI_MAXHOST] = "";
+ char alias[NI_MAXHOST] = "";
+ char *pname = name, *palias = alias, *tmp = NULL;
+
+ strncpy (pname, pszNodeName, NI_MAXHOST - 1);
+ pname[NI_MAXHOST - 1] = 0;
+ for (;;)
+ {
+ err = WspiapiQueryDNS (pszNodeName, iSocketType, iProtocol, wPort, palias, pptResult);
+ if (err)
+ break;
+ if (*pptResult)
+ break;
+ ++cntAlias;
+ if (strlen (palias) == 0 || !strcmp (pname, palias) || cntAlias == 16)
+ {
+ err = EAI_FAIL;
+ break;
+ }
+ WspiapiSwap(pname, palias, tmp);
+ }
+ if (!err && bAI_CANONNAME)
+ {
+ (*pptResult)->ai_canonname = WspiapiStrdup (palias);
+ if (!(*pptResult)->ai_canonname)
+ err = EAI_MEMORY;
+ }
+ return err;
+ }
+
+ __CRT_INLINE int WINAPI
+ WspiapiClone (WORD wPort,struct addrinfo *ptResult)
+ {
+ struct addrinfo *p = NULL;
+ struct addrinfo *n = NULL;
+
+ for (p = ptResult; p != NULL;)
+ {
+ n = WspiapiNewAddrInfo (SOCK_DGRAM, p->ai_protocol, wPort,
+ ((struct sockaddr_in *) p->ai_addr)->sin_addr.s_addr);
+ if (!n)
+ break;
+ n->ai_next = p->ai_next;
+ p->ai_next = n;
+ p = n->ai_next;
+ }
+ if (p != NULL)
+ return EAI_MEMORY;
+ return 0;
+ }
+
+ __CRT_INLINE void WINAPI
+ WspiapiLegacyFreeAddrInfo (struct addrinfo *ptHead)
+ {
+ struct addrinfo *p;
+
+ for (p = ptHead; p != NULL; p = ptHead)
+ {
+ if (p->ai_canonname)
+ WspiapiFree (p->ai_canonname);
+ if (p->ai_addr)
+ WspiapiFree (p->ai_addr);
+ ptHead = p->ai_next;
+ WspiapiFree (p);
+ }
+ }
+#endif /* !__CRT__NO_INLINE */
+
+#ifdef __cplusplus
+}
+#endif
+
+//#include <_mingw_print_pop.h>
+
+#endif
--- wpcap/libpcap/gencode.c.w2k 2012-11-19 16:28:40.579739505 +0100
+++ wpcap/libpcap/gencode.c 2012-11-19 16:28:54.392453743 +0100
@@ -74,6 +74,7 @@
#include "ppp.h"
#include "pcap/sll.h"
#include "arcnet.h"
+#include "sockutils.h"
#ifdef HAVE_NET_PFVAR_H
#include <sys/socket.h>
#include <net/if.h>
--- wpcap/libpcap/sockutils.h.w2k 2011-11-30 22:31:36.148649395 +0100
+++ wpcap/libpcap/sockutils.h 2011-11-30 22:32:21.197411498 +0100
@@ -52,6 +52,7 @@
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
+#include <wspiapi.h>
#else
#include <stdio.h>
#include <string.h> /* for memset() */
@@ -69,7 +70,7 @@
/* MingW headers include this definition, but only for Windows XP and above.
MSDN states that this function is available for most versions on Windows.
*/
-#if ((defined(__MINGW32__)) && (_WIN32_WINNT < 0x0501))
+#if 0 && ((defined(__MINGW32__)) && (_WIN32_WINNT < 0x0501))
int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD,
char*,DWORD,int);
#endif
--- wpcap/PRJ/GNUmakefile.w2k 2011-11-30 22:52:59.541092745 +0100
+++ wpcap/PRJ/GNUmakefile 2011-11-30 22:54:11.127259152 +0100
@@ -62,7 +62,20 @@
../libpcap/sockutils.o \
../libpcap/Win32/Src/gai_strerror.o \
../libpcap/pcap-tc.o \
- ../Win32-Extensions/Win32-Extensions.o
+ ../Win32-Extensions/Win32-Extensions.o \
+ ../libpcap/WspiapiClone.o \
+ ../libpcap/WspiapiFreeAddrInfo.o \
+ ../libpcap/WspiapiGetAddrInfo.o \
+ ../libpcap/WspiapiGetNameInfo.o \
+ ../libpcap/WspiapiLegacyFreeAddrInfo.o \
+ ../libpcap/WspiapiLegacyGetAddrInfo.o \
+ ../libpcap/WspiapiLegacyGetNameInfo.o \
+ ../libpcap/WspiapiLoad.o \
+ ../libpcap/WspiapiLookupNode.o \
+ ../libpcap/WspiapiNewAddrInfo.o \
+ ../libpcap/WspiapiParseV4Address.o \
+ ../libpcap/WspiapiQueryDNS.o \
+ ../libpcap/WspiapiStrdup.o
main: ${OBJS}
@${RM} -rf ../lib/
--- wpcap/libpcap/scanner.l.w2k 2012-11-19 17:41:57.104363371 +0100
+++ wpcap/libpcap/scanner.l 2012-11-19 17:42:17.572458108 +0100
@@ -35,6 +35,7 @@
#include "pcap-int.h"
#include "gencode.h"
+#include "sockutils.h"
#ifdef INET6
#ifdef WIN32
#include <pcap-stdinc.h>
--- wpcap/libpcap/nametoaddr.c.w2k 2012-11-19 17:40:09.210403187 +0100
+++ wpcap/libpcap/nametoaddr.c 2012-11-19 17:40:42.872268409 +0100
@@ -80,6 +80,7 @@
#include "pcap-int.h"
#include "gencode.h"
+#include "sockutils.h"
#include <pcap/namedb.h>
#ifdef HAVE_OS_PROTO_H