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.
This commit is contained in:
Kp 2016-11-12 20:58:16 +00:00
parent fd39a752dd
commit 73d014c048
3 changed files with 34 additions and 7 deletions

View file

@ -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 <winsock2.h>
#include <ws2tcpip.h>
@ -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;

View file

@ -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 <winsock2.h>
#include <ws2tcpip.h>
#include <io.h>

View file

@ -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;