1dnl @synopsis AX_FUNC_WHICH_GETHOSTBYNAME_R 2dnl 3dnl Determines which historical variant of the gethostbyname_r() call 4dnl (taking three, five, or six arguments) is available on the system 5dnl and defines one of the following macros accordingly: 6dnl 7dnl HAVE_FUNC_GETHOSTBYNAME_R_6 8dnl HAVE_FUNC_GETHOSTBYNAME_R_5 9dnl HAVE_FUNC_GETHOSTBYNAME_R_3 10dnl 11dnl If used in conjunction with gethostname.c, the API demonstrated in 12dnl test.c can be used regardless of which gethostbyname_r() is 13dnl available. These example files can be found at 14dnl http://www.csn.ul.ie/~caolan/publink/gethostbyname_r 15dnl 16dnl based on David Arnold's autoconf suggestion in the threads faq 17dnl 18dnl Originally named "AC_caolan_FUNC_WHICH_GETHOSTBYNAME_R". Rewritten 19dnl for Autoconf 2.5x by Daniel Richard G. 20dnl 21dnl @category InstalledPackages 22dnl @author Caolan McNamara <caolan@skynet.ie> 23dnl @author Daniel Richard G. <skunk@iskunk.org> 24dnl @version 2005-01-21 25dnl @license GPLWithACException 26 27AC_DEFUN([AX_FUNC_WHICH_GETHOSTBYNAME_R], [ 28 29 AC_LANG_PUSH(C) 30 AC_MSG_CHECKING([how many arguments gethostbyname_r() takes]) 31 32 AC_CACHE_VAL(ac_cv_func_which_gethostbyname_r, [ 33 34################################################################ 35 36ac_cv_func_which_gethostbyname_r=unknown 37 38# 39# ONE ARGUMENT (sanity check) 40# 41 42# This should fail, as there is no variant of gethostbyname_r() that takes 43# a single argument. If it actually compiles, then we can assume that 44# netdb.h is not declaring the function, and the compiler is thereby 45# assuming an implicit prototype. In which case, we're out of luck. 46# 47AC_COMPILE_IFELSE( 48 [AC_LANG_PROGRAM( 49 [[#include <netdb.h>]], 50 [[ 51 char *name = "www.gnu.org"; 52 (void)gethostbyname_r(name) /* ; */ 53 ]] 54 )], 55 ac_cv_func_which_gethostbyname_r=no 56 ) 57 58# 59# SIX ARGUMENTS 60# (e.g. Linux) 61# 62 63if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then 64 65AC_COMPILE_IFELSE( 66 [AC_LANG_PROGRAM( 67 [[#include <netdb.h>]], 68 [[ 69 char *name = "www.gnu.org"; 70 struct hostent ret, *retp; 71 char buf@<:@1024@:>@; 72 int buflen = 1024; 73 int my_h_errno; 74 (void)gethostbyname_r(name, &ret, buf, buflen, &retp, &my_h_errno) /* ; */ 75 ]] 76 )], 77 ac_cv_func_which_gethostbyname_r=six 78 ) 79 80fi 81 82# 83# FIVE ARGUMENTS 84# (e.g. Solaris) 85# 86 87if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then 88 89AC_COMPILE_IFELSE( 90 [AC_LANG_PROGRAM( 91 [[#include <netdb.h>]], 92 [[ 93 char *name = "www.gnu.org"; 94 struct hostent ret; 95 char buf@<:@1024@:>@; 96 int buflen = 1024; 97 int my_h_errno; 98 (void)gethostbyname_r(name, &ret, buf, buflen, &my_h_errno) /* ; */ 99 ]] 100 )], 101 ac_cv_func_which_gethostbyname_r=five 102 ) 103 104fi 105 106# 107# THREE ARGUMENTS 108# (e.g. AIX, HP-UX, Tru64) 109# 110 111if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then 112 113AC_COMPILE_IFELSE( 114 [AC_LANG_PROGRAM( 115 [[#include <netdb.h>]], 116 [[ 117 char *name = "www.gnu.org"; 118 struct hostent ret; 119 struct hostent_data data; 120 (void)gethostbyname_r(name, &ret, &data) /* ; */ 121 ]] 122 )], 123 ac_cv_func_which_gethostbyname_r=three 124 ) 125 126fi 127 128################################################################ 129 130]) dnl end AC_CACHE_VAL 131 132case "$ac_cv_func_which_gethostbyname_r" in 133 three) 134 AC_MSG_RESULT([three]) 135 AC_DEFINE(HAVE_FUNC_GETHOSTBYNAME_R_3) 136 ;; 137 138 five) 139 AC_MSG_RESULT([five]) 140 AC_DEFINE(HAVE_FUNC_GETHOSTBYNAME_R_5) 141 ;; 142 143 six) 144 AC_MSG_RESULT([six]) 145 AC_DEFINE(HAVE_FUNC_GETHOSTBYNAME_R_6) 146 ;; 147 148 no) 149 AC_MSG_RESULT([cannot find function declaration in netdb.h]) 150 ;; 151 152 unknown) 153 AC_MSG_RESULT([can't tell]) 154 ;; 155 156 *) 157 AC_MSG_ERROR([internal error]) 158 ;; 159esac 160 161AC_LANG_POP(C) 162 163]) dnl end AC_DEFUN 164