diff --git a/acinclude.m4 b/acinclude.m4 index ac592adad..1418ce739 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -192,6 +192,91 @@ AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [ ]) +dnl CURL_FUNC_GETNAMEINFO_ARGTYPES +dnl ------------------------------------------------- +dnl Check the type to be passed to five of the arguments +dnl of getnameinfo function, and define those types in +dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2, +dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7. +dnl This function is experimental and its results shall +dnl not be trusted while this notice is in place ------ + +AC_DEFUN([CURL_FUNC_GETNAMEINFO_ARGTYPES], [ + AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl + AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl + AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h) + AC_CACHE_CHECK([types of arguments for getnameinfo], + [curl_cv_func_getnameinfo_args], [ + curl_cv_func_getnameinfo_args="unknown" + for gni_arg1 in 'struct sockaddr *' 'void *'; do + for gni_arg2 in 'socklen_t' 'size_t' 'int'; do + for gni_arg46 in 'size_t' 'int' 'socklen_t'; do + for gni_arg7 in 'int' 'unsigned int'; do + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([ +#undef inline +#ifdef HAVE_WINDOWS_H +#define WIN32_LEAN_AND_MEAN +#include +#ifdef HAVE_WINSOCK2_H +#include +#endif +#ifdef HAVE_WS2TCPIP_H +#include +#endif +#else +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_NETDB_H +#include +#endif +#endif + extern int getnameinfo($gni_arg1, $gni_arg2, + char *, $gni_arg46, + char *, $gni_arg46, + $gni_arg7); + ],[ + $gni_arg1 sa=0; + $gni_arg2 salen=0; + char *host=0; + $gni_arg46 hostlen=0; + char *serv=0; + $gni_arg46 servlen=0; + $gni_arg7 flags=0; + getnameinfo(sa, salen, host, hostlen, serv, servlen, flags); + ]) + ],[ + curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7" + break 4 + ]) + done + done + done + done + ]) + if test "$curl_cv_func_getnameinfo_args" = "unknown"; then + AC_MSG_ERROR([Cannot find proper types to use for getnameinfo args]) + else + gni_prev_IFS=$IFS; IFS=',' + set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'` + IFS=$gni_prev_IFS + shift + AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $[1], + [Define to the type of arg 1 for `getnameinfo'.]) + AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2], + [Define to the type of arg 2 for `getnameinfo'.]) + AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3], + [Define to the type of args 4 and 6 for `getnameinfo'.]) + AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4], + [Define to the type of arg 7 for `getnameinfo'.]) + fi +]) + + dnl Check for how to set a socket to non-blocking state. There seems to exist dnl four known different ways, with the one used almost everywhere being POSIX dnl and XPG3, while the other different ways for different systems (old BSD, @@ -343,50 +428,6 @@ AC_DEFUN([TYPE_SOCKADDR_STORAGE], ]) -dnl Check for socklen_t: historically on BSD it is an int, and in -dnl POSIX 1g it is a type of its own, but some platforms use different -dnl types for the argument to getsockopt, getpeername, etc. So we -dnl have to test to find something that will work. -AC_DEFUN([TYPE_SOCKLEN_T], -[ - AC_CHECK_TYPE([socklen_t], ,[ - AC_MSG_CHECKING([for socklen_t equivalent]) - AC_CACHE_VAL([curl_cv_socklen_t_equiv], - [ - # Systems have either "struct sockaddr *" or - # "void *" as the second argument to getpeername - curl_cv_socklen_t_equiv= - for arg2 in "struct sockaddr" void; do - for t in int size_t unsigned long "unsigned long"; do - AC_TRY_COMPILE([ - #ifdef HAVE_SYS_TYPES_H - #include - #endif - #ifdef HAVE_SYS_SOCKET_H - #include - #endif - - int getpeername (int, $arg2 *, $t *); - ],[ - $t len; - getpeername(0,0,&len); - ],[ - curl_cv_socklen_t_equiv="$t" - break - ]) - done - done - - if test "x$curl_cv_socklen_t_equiv" = x; then - AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) - fi - ]) - AC_MSG_RESULT($curl_cv_socklen_t_equiv) - AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv, - [type to use in place of socklen_t if not defined])], - [#include -#include ]) -]) dnl Check for in_addr_t: it is used to receive the return code of inet_addr() dnl and a few other things. @@ -882,83 +923,6 @@ fi ]) -dnl CURL_FUNC_GETNAMEINFO_ARGTYPES -dnl ------------------------------ -dnl This function is experimental and its results shall -dnl not be trusted while this notice is in place ------ - -AC_DEFUN([CURL_FUNC_GETNAMEINFO_ARGTYPES], [ - AC_REQUIRE([TYPE_SOCKLEN_T])dnl - AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h) - AC_CACHE_CHECK([types of arguments for getnameinfo], - [curl_cv_func_getnameinfo_args], [ - for gni_arg2 in 'socklen_t' 'size_t' 'int'; do - for gni_arg46 in 'size_t' 'int' 'socklen_t'; do - for gni_arg7 in 'int' 'unsigned int'; do - AC_COMPILE_IFELSE([ - AC_LANG_PROGRAM([ - -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_SYS_SOCKET_H -#include -#endif -#ifdef HAVE_NETDB_H -#include -#endif - - extern int getnameinfo(const struct sockaddr *, - $gni_arg2, - char *, - $gni_arg46, - char *, - $gni_arg46, - $gni_arg7); - - ],[ - - int res; - struct sockaddr *sa=0; - $gni_arg2 salen=0; - char *host=0; - $gni_arg46 hostlen=0; - char *serv=0; - $gni_arg46 servlen=0; - $gni_arg7 flags=0; - - res = getnameinfo(sa, - salen, - host, - hostlen, - serv, - servlen, - flags); - - ]) - ],[ - curl_cv_func_getnameinfo_args="$gni_arg2,$gni_arg46,$gni_arg7" - break 3 - ]) - done - done - done - # Provide widely used default values. - : ${curl_cv_func_getnameinfo_args='socklen_t,size_t,int'} - ]) - gni_prev_IFS=$IFS; IFS=',' - set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'` - IFS=$gni_prev_IFS - shift - AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[1], - [Define to the type of arg 2 for `getnameinfo'.]) - AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[2], - [Define to the type of args 4 and 6 for `getnameinfo'.]) - AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[3], - [Define to the type of arg 7 for `getnameinfo'.]) -]) - - dnl We create a function for detecting which compiler we use and then set as dnl pendantic compiler options as possible for that particular compiler. The dnl options are only used for debug-builds. diff --git a/ares/acinclude.m4 b/ares/acinclude.m4 index 214c005e7..6d1835ecb 100644 --- a/ares/acinclude.m4 +++ b/ares/acinclude.m4 @@ -1,3 +1,282 @@ + + +dnl CURL_CHECK_HEADER_WINDOWS +dnl ------------------------------------------------- +dnl Check for compilable and valid windows.h header + +AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [ + AC_CACHE_CHECK([for windows.h], [ac_cv_header_windows_h], [ + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([ +#undef inline +#define WIN32_LEAN_AND_MEAN +#include + ],[ + int dummy=2*WINVER; + ]) + ],[ + ac_cv_header_windows_h="yes" + ],[ + ac_cv_header_windows_h="no" + ]) + ]) + if test "x$ac_cv_header_windows_h" = "xyes"; then + AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1, + [Define to 1 if you have the windows.h header file.]) + AC_DEFINE_UNQUOTED(WIN32_LEAN_AND_MEAN, 1, + [Define to avoid automatic inclusion of winsock.h]) + fi +]) + + +dnl CURL_CHECK_HEADER_WINSOCK +dnl ------------------------------------------------- +dnl Check for compilable and valid winsock.h header + +AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [ + AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl + AC_CACHE_CHECK([for winsock.h], [ac_cv_header_winsock_h], [ + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([ +#undef inline +#define WIN32_LEAN_AND_MEAN +#include +#include + ],[ + int dummy=WSACleanup(); + ]) + ],[ + ac_cv_header_winsock_h="yes" + ],[ + ac_cv_header_winsock_h="no" + ]) + ]) + if test "x$ac_cv_header_winsock_h" = "xyes"; then + AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1, + [Define to 1 if you have the winsock.h header file.]) + fi +]) + + +dnl CURL_CHECK_HEADER_WINSOCK2 +dnl ------------------------------------------------- +dnl Check for compilable and valid winsock2.h header + +AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [ + AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl + AC_CACHE_CHECK([for winsock2.h], [ac_cv_header_winsock2_h], [ + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([ +#undef inline +#define WIN32_LEAN_AND_MEAN +#include +#include + ],[ + int dummy=2*IPPROTO_ESP; + ]) + ],[ + ac_cv_header_winsock2_h="yes" + ],[ + ac_cv_header_winsock2_h="no" + ]) + ]) + if test "x$ac_cv_header_winsock2_h" = "xyes"; then + AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1, + [Define to 1 if you have the winsock2.h header file.]) + fi +]) + + +dnl CURL_CHECK_HEADER_WS2TCPIP +dnl ------------------------------------------------- +dnl Check for compilable and valid ws2tcpip.h header + +AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [ + AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl + AC_CACHE_CHECK([for ws2tcpip.h], [ac_cv_header_ws2tcpip_h], [ + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([ +#undef inline +#define WIN32_LEAN_AND_MEAN +#include +#include +#include + ],[ + int dummy=2*IP_PKTINFO; + ]) + ],[ + ac_cv_header_ws2tcpip_h="yes" + ],[ + ac_cv_header_ws2tcpip_h="no" + ]) + ]) + if test "x$ac_cv_header_ws2tcpip_h" = "xyes"; then + AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1, + [Define to 1 if you have the ws2tcpip.h header file.]) + fi +]) + + +dnl CURL_CHECK_TYPE_SOCKLEN_T +dnl ------------------------------------------------- +dnl Check for existing socklen_t type, and provide +dnl an equivalent type if socklen_t not available + +AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [ + AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl + AC_CHECK_TYPE([socklen_t], ,[ + AC_CACHE_CHECK([for socklen_t equivalent], + [curl_cv_socklen_t_equiv], [ + curl_cv_socklen_t_equiv="unknown" + for arg2 in "struct sockaddr" void; do + for t in int size_t unsigned long "unsigned long"; do + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([ +#undef inline +#ifdef HAVE_WINDOWS_H +#define WIN32_LEAN_AND_MEAN +#include +#ifdef HAVE_WINSOCK2_H +#include +#else +#ifdef HAVE_WINSOCK_H +#include +#endif +#endif +#else +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#endif + int getpeername (int, $arg2 *, $t *); + int getsockname (int, $arg2 *, $t *); + int bind (int, $arg2 *, $t); + int accept (int, $arg2 *, $t *); + ],[ + $t len=0; + getpeername(0,0,&len); + getsockname(0,0,&len); + bind(0,0,len); + accept(0,0,&len); + ]) + ],[ + curl_cv_socklen_t_equiv="$t" + break 2 + ]) + done + done + ]) + if test "$curl_cv_socklen_t_equiv" = "unknown"; then + AC_MSG_ERROR([Cannot find a type to use in place of socklen_t]) + else + AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv, + [type to use in place of socklen_t if not defined]) + fi + ],[ +#ifdef HAVE_WINDOWS_H +#ifdef HAVE_WS2TCPIP_H +#include +#endif +#else +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#endif + ]) +]) + + +dnl CURL_FUNC_GETNAMEINFO_ARGTYPES +dnl ------------------------------------------------- +dnl Check the type to be passed to five of the arguments +dnl of getnameinfo function, and define those types in +dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2, +dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7. +dnl This function is experimental and its results shall +dnl not be trusted while this notice is in place ------ + +AC_DEFUN([CURL_FUNC_GETNAMEINFO_ARGTYPES], [ + AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl + AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl + AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h) + AC_CACHE_CHECK([types of arguments for getnameinfo], + [curl_cv_func_getnameinfo_args], [ + curl_cv_func_getnameinfo_args="unknown" + for gni_arg1 in 'struct sockaddr *' 'void *'; do + for gni_arg2 in 'socklen_t' 'size_t' 'int'; do + for gni_arg46 in 'size_t' 'int' 'socklen_t'; do + for gni_arg7 in 'int' 'unsigned int'; do + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([ +#undef inline +#ifdef HAVE_WINDOWS_H +#define WIN32_LEAN_AND_MEAN +#include +#ifdef HAVE_WINSOCK2_H +#include +#endif +#ifdef HAVE_WS2TCPIP_H +#include +#endif +#else +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_NETDB_H +#include +#endif +#endif + extern int getnameinfo($gni_arg1, $gni_arg2, + char *, $gni_arg46, + char *, $gni_arg46, + $gni_arg7); + ],[ + $gni_arg1 sa=0; + $gni_arg2 salen=0; + char *host=0; + $gni_arg46 hostlen=0; + char *serv=0; + $gni_arg46 servlen=0; + $gni_arg7 flags=0; + getnameinfo(sa, salen, host, hostlen, serv, servlen, flags); + ]) + ],[ + curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7" + break 4 + ]) + done + done + done + done + ]) + if test "$curl_cv_func_getnameinfo_args" = "unknown"; then + AC_MSG_ERROR([Cannot find proper types to use for getnameinfo args]) + else + gni_prev_IFS=$IFS; IFS=',' + set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'` + IFS=$gni_prev_IFS + shift + AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $[1], + [Define to the type of arg 1 for `getnameinfo'.]) + AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2], + [Define to the type of arg 2 for `getnameinfo'.]) + AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3], + [Define to the type of args 4 and 6 for `getnameinfo'.]) + AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4], + [Define to the type of arg 7 for `getnameinfo'.]) + fi +]) + + dnl Check for how to set a socket to non-blocking state. There seems to exist dnl four known different ways, with the one used almost everywhere being POSIX dnl and XPG3, while the other different ways for different systems (old BSD, diff --git a/ares/configure.ac b/ares/configure.ac index 60436fb0a..5b3431a05 100644 --- a/ares/configure.ac +++ b/ares/configure.ac @@ -59,6 +59,18 @@ AC_HELP_STRING([--disable-debug],[Disable debug options]), AC_PROG_LIBTOOL +dnl ********************************************************************** +dnl Make sure that our checks for headers windows.h winsock.h winsock2.h +dnl and ws2tcpip.h take precedence over any other further checks which +dnl could be done later using AC_CHECK_HEADER or AC_CHECK_HEADERS for +dnl this specific header files. +dnl ********************************************************************** + +CURL_CHECK_HEADER_WINDOWS +CURL_CHECK_HEADER_WINSOCK +CURL_CHECK_HEADER_WINSOCK2 +CURL_CHECK_HEADER_WS2TCPIP + dnl check for a few basic system headers we need AC_CHECK_HEADERS( sys/types.h \ @@ -67,8 +79,6 @@ AC_CHECK_HEADERS( sys/socket.h \ sys/ioctl.h \ netdb.h \ - winsock2.h \ - ws2tcpip.h \ netinet/in.h \ net/if.h \ arpa/nameser.h \ @@ -95,19 +105,8 @@ dnl *Sigh* these are needed in order for net/if.h to get properly detected. ] ) -AC_CHECK_TYPE(socklen_t, , - AC_DEFINE(socklen_t, int, [the length of a socket address]), - [ -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_SYS_SOCKET_H -#include -#endif -#ifdef HAVE_WINSOCK2_H -#include -#endif - ]) +# Check for socklen_t or equivalent +CURL_CHECK_TYPE_SOCKLEN_T dnl check for AF_INET6 CARES_CHECK_CONSTANT( @@ -228,6 +227,26 @@ AC_CHECK_MEMBER(struct addrinfo.ai_flags, ] ) + +AC_CHECK_FUNCS( getnameinfo \ + bitncmp \ + if_indextoname, +dnl if found +[], +dnl if not found, $ac_func is the name we check for +func="$ac_func" +AC_MSG_CHECKING([deeper for $func]) +AC_TRY_LINK( [], + [ $func ();], + AC_MSG_RESULT(yes!) + eval "ac_cv_func_$func=yes" + def=`echo "HAVE_$func" | tr 'a-z' 'A-Z'` + AC_DEFINE_UNQUOTED($def, 1, [If you have $func]), + AC_MSG_RESULT(but still no) + ) +) + + dnl check for inet_pton AC_CHECK_FUNCS(inet_pton) dnl Some systems have it, but not IPv6 @@ -362,7 +381,13 @@ AC_CHECK_SIZEOF(struct in_addr, , ] ) -AC_CHECK_FUNCS([bitncmp if_indextoname]) +if test "x$ac_cv_func_getnameinfo" = "x"; then + AC_MSG_ERROR([Checking availability of function getnameinfo must be done previously]) +else + if test "x$ac_cv_func_getnameinfo" = "xyes"; then + CURL_FUNC_GETNAMEINFO_ARGTYPES + fi +fi dnl God bless non-standardized functions! We need to see which getservbyport_r variant is available CARES_CHECK_GETSERVBYPORT_R diff --git a/configure.ac b/configure.ac index 4ab6503b1..03675a90e 100644 --- a/configure.ac +++ b/configure.ac @@ -1396,8 +1396,9 @@ AC_HEADER_STDC dnl ********************************************************************** dnl Make sure that our checks for headers windows.h winsock.h winsock2.h -dnl and ws2tcpip.h take precedence over any other further check which -dnl could be done later using AC_CHECK_HEADER or AC_CHECK_HEADERS. +dnl and ws2tcpip.h take precedence over any other further checks which +dnl could be done later using AC_CHECK_HEADER or AC_CHECK_HEADERS for +dnl this specific header files. dnl ********************************************************************** CURL_CHECK_HEADER_WINDOWS @@ -1432,8 +1433,6 @@ AC_CHECK_HEADERS( fcntl.h \ dlfcn.h \ alloca.h \ - winsock.h \ - winsock2.h \ time.h \ io.h \ pwd.h \ @@ -1503,11 +1502,9 @@ fi AC_CHECK_TYPE(ssize_t, , AC_DEFINE(ssize_t, int, [the signed version of size_t])) -# Experimental check +# Check for socklen_t or equivalent CURL_CHECK_TYPE_SOCKLEN_T -# TYPE_SOCKLEN_T - TYPE_IN_ADDR_T TYPE_SOCKADDR_STORAGE @@ -1628,19 +1625,12 @@ AC_CHECK_DECL(inet_pton, , ] ) -if test "$ac_cv_func_getnameinfo" = "yes"; then - AC_CHECK_DECL(getnameinfo, , - AC_DEFINE(HAVE_NO_GETNAMEINFO_PROTO, 1, - [Defined if no getnameinfo() prototype available]), - [ -#ifdef HAVE_SYS_SOCKET_H -#include -#endif -#ifdef HAVE_NETDB_H -#include -#endif - ]) - CURL_FUNC_GETNAMEINFO_ARGTYPES +if test "x$ac_cv_func_getnameinfo" = "x"; then + AC_MSG_ERROR([Checking availability of function getnameinfo must be done previously]) +else + if test "x$ac_cv_func_getnameinfo" = "xyes"; then + CURL_FUNC_GETNAMEINFO_ARGTYPES + fi fi AC_MSG_CHECKING([if we are Mac OS X (to disable poll)])