X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=lhnet.c;h=6b049d2890b8cd79fc3df1acf0383af0cf31e060;hb=9995e243c1af378170518a1308f24dc66094f1e1;hp=fd668b7ee6d83ac59c55bdb8d4f3e1838dd5de60;hpb=5f91d03c4bf070b4daf087c0b147c0dbf1e05c84;p=xonotic%2Fdarkplaces.git diff --git a/lhnet.c b/lhnet.c index fd668b7e..6b049d28 100644 --- a/lhnet.c +++ b/lhnet.c @@ -1,6 +1,16 @@ // 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 +# include +# ifdef USE_WSPIAPI_H +# include +# endif +#endif + #ifndef STANDALONETEST #include "quakedef.h" #endif @@ -9,12 +19,7 @@ #include #include #include -#ifdef WIN32 -#define _WIN32_WINNT 0x0501 - // Windows XP or higher is required for getaddrinfo -#include -#include -#else +#ifndef WIN32 #include #include #include @@ -148,7 +153,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) @@ -722,7 +730,7 @@ lhnetsocket_t *LHNET_OpenSocket_Connectionless(lhnetaddress_t *address) int ipv6_only = 1; if (address->addresstype != LHNETADDRESSTYPE_INET6 || setsockopt (lhnetsocket->inetsocket, IPPROTO_IPV6, IPV6_V6ONLY, - (const void *)&ipv6_only, sizeof(ipv6_only)) == 0 + (const char *)&ipv6_only, sizeof(ipv6_only)) == 0 #ifdef WIN32 // The Win32 API only supports IPV6_V6ONLY since Windows Vista, but fortunately // the default value is what we want on Win32 anyway (IPV6_V6ONLY = true) @@ -869,10 +877,10 @@ 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); + value = recvfrom(lhnetsocket->inetsocket, (char *)content, maxcontentlength, 0, &address->addr.sock, &inetaddresslength); if (value > 0) { address->addresstype = LHNETADDRESSTYPE_INET4; @@ -895,10 +903,10 @@ 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); + value = recvfrom(lhnetsocket->inetsocket, (char *)content, maxcontentlength, 0, &address->addr.sock, &inetaddresslength); if (value > 0) { address->addresstype = LHNETADDRESSTYPE_INET6; @@ -951,7 +959,7 @@ int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentleng } else if (lhnetsocket->address.addresstype == LHNETADDRESSTYPE_INET4) { - value = sendto(lhnetsocket->inetsocket, content, contentlength, 0, (struct sockaddr *)&address->addr.in, sizeof(struct sockaddr_in)); + value = sendto(lhnetsocket->inetsocket, (char *)content, contentlength, 0, (struct sockaddr *)&address->addr.in, sizeof(struct sockaddr_in)); if (value == -1) { if (SOCKETERRNO == EWOULDBLOCK) @@ -961,7 +969,7 @@ int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentleng } else if (lhnetsocket->address.addresstype == LHNETADDRESSTYPE_INET6) { - value = sendto(lhnetsocket->inetsocket, content, contentlength, 0, (struct sockaddr *)&address->addr.in6, sizeof(struct sockaddr_in6)); + value = sendto(lhnetsocket->inetsocket, (char *)content, contentlength, 0, (struct sockaddr *)&address->addr.in6, sizeof(struct sockaddr_in6)); if (value == -1) { if (SOCKETERRNO == EWOULDBLOCK)