]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - lhnet.c
[04:31:11] <@LordHavoc> div0: 9179 (if (msecdelta <= 0) return;) wrecked connect...
[xonotic/darkplaces.git] / lhnet.c
diff --git a/lhnet.c b/lhnet.c
index 9026aca22d1af0799dcc86da5b48aa87f630ac44..1e90318fe603a53bc8b1aa0eb0abc03df2a73eae 100644 (file)
--- a/lhnet.c
+++ b/lhnet.c
@@ -1,6 +1,14 @@
 
 // Written by Forest Hale 2003-06-15 and placed into public domain.
 
+#ifdef WIN32
+// Windows XP or higher is required for getaddrinfo, but the inclusion of wspiapi provides fallbacks for older versions
+#define _WIN32_WINNT 0x0501
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <wspiapi.h>
+#endif
+
 #ifndef STANDALONETEST
 #include "quakedef.h"
 #endif
@@ -9,10 +17,7 @@
 #include <stdio.h>
 #include <time.h>
 #include <string.h>
-#ifdef WIN32
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#else
+#ifndef WIN32
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -146,7 +151,10 @@ int LHNETADDRESS_Resolve(lhnetaddressnative_t *address, const char *name, int po
        if (err != 0 || addrinf == NULL)
                return 0;
        if (addrinf->ai_addr->sa_family != AF_INET6 && addrinf->ai_addr->sa_family != AF_INET)
+       {
+               freeaddrinfo (addrinf);
                return 0;
+       }
 
        // great it worked
        if (addrinf->ai_addr->sa_family == AF_INET6)
@@ -867,7 +875,7 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength,
        }
        else if (lhnetsocket->address.addresstype == LHNETADDRESSTYPE_INET4)
        {
-               unsigned int inetaddresslength;
+               SOCKLEN_T inetaddresslength;
                address->addresstype = LHNETADDRESSTYPE_NONE;
                inetaddresslength = sizeof(address->addr.in);
                value = recvfrom(lhnetsocket->inetsocket, content, maxcontentlength, 0, &address->addr.sock, &inetaddresslength);
@@ -893,7 +901,7 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength,
        }
        else if (lhnetsocket->address.addresstype == LHNETADDRESSTYPE_INET6)
        {
-               unsigned int inetaddresslength;
+               SOCKLEN_T inetaddresslength;
                address->addresstype = LHNETADDRESSTYPE_NONE;
                inetaddresslength = sizeof(address->addr.in6);
                value = recvfrom(lhnetsocket->inetsocket, content, maxcontentlength, 0, &address->addr.sock, &inetaddresslength);