From 73d014c04807b8d8d0bde8a8535ea4e81f339510 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 12 Nov 2016 20:58:16 +0000 Subject: [PATCH] Tighten getaddrinfo test To recognize getaddrinfo as supported, require that the AI_* flags passed to it be usable: - AI_NUMERICSERV must be defined as a number or be undefined - If ipv6=1, then AI_V4MAPPED and AI_ALL must be defined as numbers When getaddrinfo is used, raise _WIN32_WINNT from 0x501 to 0x600. Otherwise, lower it to 0x500. --- SConstruct | 19 +++++++++++++++---- common/main/multi.h | 15 +++++++++++++-- similar/main/net_udp.cpp | 7 ++++++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/SConstruct b/SConstruct index 911e654ab..41d1d9f08 100644 --- a/SConstruct +++ b/SConstruct @@ -917,7 +917,7 @@ int main(int argc,char**argv){(void)argc;(void)argv; Result('%s: building with %s' % (self.msgprefix, s)) def _result_check_user_setting(self,context,condition,CPPDEFINES,label,int=int,str=str): if isinstance(CPPDEFINES, str): - context.sconf.Define(CPPDEFINES, int(condition)) + self._define_macro(context, CPPDEFINES, int(condition)) elif condition: self.successful_flags['CPPDEFINES'].extend(CPPDEFINES) context.Result('%s: checking whether to enable %s...%s' % (self.msgprefix, label, 'yes' if condition else 'no')) @@ -2064,8 +2064,12 @@ where the cast is useless. def check_getaddrinfo_present(self,context,_successflags={'CPPDEFINES' : ['DXX_HAVE_GETADDRINFO']}): self.Compile(context, text=''' #ifdef WIN32 +#define DXX_WIN32_MINIMUM_WIN32_WINNT 0x0600 +#if defined(_WIN32_WINNT) && (_WIN32_WINNT < DXX_WIN32_MINIMUM_WIN32_WINNT) +#undef _WIN32_WINNT +#endif #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0501 +#define _WIN32_WINNT DXX_WIN32_MINIMUM_WIN32_WINNT #endif #include #include @@ -2076,8 +2080,15 @@ where the cast is useless. #endif ''', main=''' addrinfo *res = nullptr; - const addrinfo *hints = nullptr; - int i = getaddrinfo("", "", hints, &res); + addrinfo hints{}; +#ifdef AI_NUMERICSERV + /* Test that it is defined to a term that can be used with bit-or */ + hints.ai_flags |= AI_NUMERICSERV; +#endif +#if DXX_USE_IPv6 + hints.ai_flags |= AI_V4MAPPED | AI_ALL; +#endif + int i = getaddrinfo("", "", &hints, &res); (void)i; freeaddrinfo(res); return 0; diff --git a/common/main/multi.h b/common/main/multi.h index 023ab219a..31265b315 100644 --- a/common/main/multi.h +++ b/common/main/multi.h @@ -25,6 +25,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #pragma once +#include "dxxsconf.h" #include "fwd-player.h" #include "player-callsign.h" #include "player-flags.h" @@ -37,10 +38,20 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "game.h" #ifdef _WIN32 -#ifdef _WIN32_WINNT +/* Require _WIN32_WINNT >= 0x0501 to enable getaddrinfo + * Require _WIN32_WINNT >= 0x0600 to enable some useful AI_* flags + */ +#ifdef DXX_HAVE_GETADDRINFO +#define DXX_WIN32_MINIMUM_WIN32_WINNT 0x0600 +#else +#define DXX_WIN32_MINIMUM_WIN32_WINNT 0x0500 +#endif +#if defined(_WIN32_WINNT) && (_WIN32_WINNT < DXX_WIN32_MINIMUM_WIN32_WINNT) #undef _WIN32_WINNT #endif -#define _WIN32_WINNT 0x0501 // for get/freeaddrinfo() +#ifndef _WIN32_WINNT +#define _WIN32_WINNT DXX_WIN32_MINIMUM_WIN32_WINNT +#endif #include #include #include diff --git a/similar/main/net_udp.cpp b/similar/main/net_udp.cpp index ed105dcf5..db9e643ba 100644 --- a/similar/main/net_udp.cpp +++ b/similar/main/net_udp.cpp @@ -563,7 +563,12 @@ int udp_dns_filladdr_t::apply(sockaddr &addr, socklen_t addrlen, int ai_family, hints.ai_family = ai_family; // We are always UDP hints.ai_socktype = SOCK_DGRAM; - hints.ai_flags = AI_V4MAPPED | AI_ALL | AI_NUMERICSERV; +#ifdef AI_NUMERICSERV + hints.ai_flags |= AI_NUMERICSERV; +#endif +#if DXX_USE_IPv6 + hints.ai_flags |= AI_V4MAPPED | AI_ALL; +#endif // Numeric address only? if (numeric_only) hints.ai_flags |= AI_NUMERICHOST;