Use preprocessor to check for AI_V4MAPPED, AI_ALL and AI_IDN (#13513)

The preprocessor macros defined in some header can be checked, using
Autoconf's AC_COMPILE_IFELSE, or with simpler AC_CHECK_DECL(S), or even
better and simpler directly in the C code.
This commit is contained in:
Peter Kokot 2024-02-26 16:38:00 +01:00 committed by GitHub
parent 718a8b4278
commit 23844538d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 9 additions and 48 deletions

View file

@ -11,45 +11,6 @@ if test "$PHP_SOCKETS" != "no"; then
dnl Check for field ss_family in sockaddr_storage (missing in AIX until 5.3) dnl Check for field ss_family in sockaddr_storage (missing in AIX until 5.3)
AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family],,,[#include <sys/socket.h>]) AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family],,,[#include <sys/socket.h>])
dnl Check for AI_V4MAPPED flag
AC_CACHE_CHECK([if getaddrinfo supports AI_V4MAPPED],[ac_cv_gai_ai_v4mapped],
[
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <netdb.h>
]], [[int flag = AI_V4MAPPED;]])],
[ac_cv_gai_ai_v4mapped=yes], [ac_cv_gai_ai_v4mapped=no])
])
if test "$ac_cv_gai_ai_v4mapped" = yes; then
AC_DEFINE(HAVE_AI_V4MAPPED,1,[Whether you have AI_V4MAPPED])
fi
dnl Check for AI_ALL flag
AC_CACHE_CHECK([if getaddrinfo supports AI_ALL],[ac_cv_gai_ai_all],
[
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <netdb.h>
]], [[int flag = AI_ALL;]])],
[ac_cv_gai_ai_all=yes], [ac_cv_gai_ai_all=no])
])
if test "$ac_cv_gai_ai_all" = yes; then
AC_DEFINE(HAVE_AI_ALL,1,[Whether you have AI_ALL])
fi
dnl Check for AI_IDN flag
AC_CACHE_CHECK([if getaddrinfo supports AI_IDN],[ac_cv_gai_ai_idn],
[
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <netdb.h>
]], [[int flag = AI_IDN;]])],
[ac_cv_gai_ai_idn=yes], [ac_cv_gai_ai_idn=no])
])
if test "$ac_cv_gai_ai_idn" = yes; then
AC_DEFINE(HAVE_AI_IDN,1,[Whether you have AI_IDN])
fi
dnl Check for struct ucred. Checking the header is not enough (DragonFlyBSD). dnl Check for struct ucred. Checking the header is not enough (DragonFlyBSD).
AC_CHECK_TYPES([struct ucred],,, AC_CHECK_TYPES([struct ucred],,,
[#ifndef _GNU_SOURCE [#ifndef _GNU_SOURCE

View file

@ -29,7 +29,7 @@ int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_
memset(&hints, 0, sizeof(struct addrinfo)); memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET6; hints.ai_family = AF_INET6;
#if HAVE_AI_V4MAPPED #ifdef AI_V4MAPPED
hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG; hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG;
#else #else
hints.ai_flags = AI_ADDRCONFIG; hints.ai_flags = AI_ADDRCONFIG;

View file

@ -1591,14 +1591,14 @@ const AI_CANONNAME = UNKNOWN;
* @cvalue AI_NUMERICHOST * @cvalue AI_NUMERICHOST
*/ */
const AI_NUMERICHOST = UNKNOWN; const AI_NUMERICHOST = UNKNOWN;
#if HAVE_AI_V4MAPPED #ifdef AI_V4MAPPED
/** /**
* @var int * @var int
* @cvalue AI_V4MAPPED * @cvalue AI_V4MAPPED
*/ */
const AI_V4MAPPED = UNKNOWN; const AI_V4MAPPED = UNKNOWN;
#endif #endif
#if HAVE_AI_ALL #ifdef AI_ALL
/** /**
* @var int * @var int
* @cvalue AI_ALL * @cvalue AI_ALL
@ -1610,7 +1610,7 @@ const AI_ALL = UNKNOWN;
* @cvalue AI_ADDRCONFIG * @cvalue AI_ADDRCONFIG
*/ */
const AI_ADDRCONFIG = UNKNOWN; const AI_ADDRCONFIG = UNKNOWN;
#if HAVE_AI_IDN #ifdef AI_IDN
/** /**
* @var int * @var int
* @cvalue AI_IDN * @cvalue AI_IDN

View file

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead. /* This is a generated file, edit the .stub.php file instead.
* Stub hash: 5aebcb542405e392cbe7129eac964826f61f7dac */ * Stub hash: ec04de98f14d553e10da9f7f6de7ec281215ef44 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_socket_select, 0, 4, MAY_BE_LONG|MAY_BE_FALSE) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_socket_select, 0, 4, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(1, read, IS_ARRAY, 1) ZEND_ARG_TYPE_INFO(1, read, IS_ARRAY, 1)
@ -935,17 +935,17 @@ static void register_sockets_symbols(int module_number)
REGISTER_LONG_CONSTANT("AI_PASSIVE", AI_PASSIVE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("AI_PASSIVE", AI_PASSIVE, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("AI_CANONNAME", AI_CANONNAME, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("AI_CANONNAME", AI_CANONNAME, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("AI_NUMERICHOST", AI_NUMERICHOST, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("AI_NUMERICHOST", AI_NUMERICHOST, CONST_PERSISTENT);
#if HAVE_AI_V4MAPPED #if defined(AI_V4MAPPED)
REGISTER_LONG_CONSTANT("AI_V4MAPPED", AI_V4MAPPED, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("AI_V4MAPPED", AI_V4MAPPED, CONST_PERSISTENT);
#endif #endif
#if HAVE_AI_ALL #if defined(AI_ALL)
REGISTER_LONG_CONSTANT("AI_ALL", AI_ALL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("AI_ALL", AI_ALL, CONST_PERSISTENT);
#endif #endif
REGISTER_LONG_CONSTANT("AI_ADDRCONFIG", AI_ADDRCONFIG, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("AI_ADDRCONFIG", AI_ADDRCONFIG, CONST_PERSISTENT);
#if HAVE_AI_IDN #if defined(AI_IDN)
REGISTER_LONG_CONSTANT("AI_IDN", AI_IDN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("AI_IDN", AI_IDN, CONST_PERSISTENT);
#endif #endif
#if HAVE_AI_IDN #if defined(AI_IDN)
REGISTER_LONG_CONSTANT("AI_CANONIDN", AI_CANONIDN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("AI_CANONIDN", AI_CANONIDN, CONST_PERSISTENT);
#endif #endif
#if defined(AI_NUMERICSERV) #if defined(AI_NUMERICSERV)