From 0c1ae21c110454413f0a19ef8134e024f4c5c6ef Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 17 Sep 2008 11:31:37 +0000 Subject: improve detection of getservbyport_r() --- ares/m4/cares-functions.m4 | 163 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 162 insertions(+), 1 deletion(-) (limited to 'ares/m4') diff --git a/ares/m4/cares-functions.m4 b/ares/m4/cares-functions.m4 index e1ba24083..0ba032477 100644 --- a/ares/m4/cares-functions.m4 +++ b/ares/m4/cares-functions.m4 @@ -16,7 +16,28 @@ #*************************************************************************** # File version for 'aclocal' use. Keep it a single number. -# serial 1 +# serial 5 + + +dnl CARES_INCLUDES_NETDB +dnl ------------------------------------------------- +dnl Set up variable with list of headers that must be +dnl included when netdb.h is to be included. + +AC_DEFUN([CARES_INCLUDES_NETDB], [ +cares_includes_netdb="\ +/* includes start */ +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_NETDB_H +# include +#endif +/* includes end */" + AC_CHECK_HEADERS( + sys/types.h netdb.h, + [], [], [$cares_includes_netdb]) +]) dnl CARES_INCLUDES_STRING @@ -170,6 +191,146 @@ AC_DEFUN([CARES_CHECK_FUNC_GETHOSTNAME], [ ]) +dnl CARES_CHECK_FUNC_GETSERVBYPORT_R +dnl ------------------------------------------------- +dnl Verify if getservbyport_r is available, prototyped, +dnl and can be compiled. If all of these are true, and +dnl usage has not been previously disallowed with +dnl shell variable cares_disallow_getservbyport_r, then +dnl HAVE_GETSERVBYPORT_R will be defined. + +AC_DEFUN([CARES_CHECK_FUNC_GETSERVBYPORT_R], [ + AC_REQUIRE([CARES_INCLUDES_SYS_UIO])dnl + # + tst_links_getservbyport_r="unknown" + tst_proto_getservbyport_r="unknown" + tst_compi_getservbyport_r="unknown" + tst_allow_getservbyport_r="unknown" + tst_nargs_getservbyport_r="unknown" + # + AC_MSG_CHECKING([if getservbyport_r can be linked]) + AC_LINK_IFELSE([ + AC_LANG_FUNC_LINK_TRY([getservbyport_r]) + ],[ + AC_MSG_RESULT([yes]) + tst_links_getservbyport_r="yes" + ],[ + AC_MSG_RESULT([no]) + tst_links_getservbyport_r="no" + ]) + # + if test "$tst_links_getservbyport_r" = "yes"; then + AC_MSG_CHECKING([if getservbyport_r is prototyped]) + AC_EGREP_CPP([getservbyport_r],[ + $cares_includes_netdb + ],[ + AC_MSG_RESULT([yes]) + tst_proto_getservbyport_r="yes" + ],[ + AC_MSG_RESULT([no]) + tst_proto_getservbyport_r="no" + ]) + fi + # + if test "$tst_proto_getservbyport_r" = "yes"; then + if test "$tst_nargs_getservbyport_r" = "unknown"; then + AC_MSG_CHECKING([if getservbyport_r takes 4 args.]) + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ + $cares_includes_netdb + ]],[[ + if(0 != getservbyport_r(0, 0, 0, 0)) + return 1; + ]]) + ],[ + AC_MSG_RESULT([yes]) + tst_compi_getservbyport_r="yes" + tst_nargs_getservbyport_r="4" + ],[ + AC_MSG_RESULT([no]) + tst_compi_getservbyport_r="no" + ]) + fi + if test "$tst_nargs_getservbyport_r" = "unknown"; then + AC_MSG_CHECKING([if getservbyport_r takes 5 args.]) + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ + $cares_includes_netdb + ]],[[ + if(0 != getservbyport_r(0, 0, 0, 0, 0)) + return 1; + ]]) + ],[ + AC_MSG_RESULT([yes]) + tst_compi_getservbyport_r="yes" + tst_nargs_getservbyport_r="5" + ],[ + AC_MSG_RESULT([no]) + tst_compi_getservbyport_r="no" + ]) + fi + if test "$tst_nargs_getservbyport_r" = "unknown"; then + AC_MSG_CHECKING([if getservbyport_r takes 6 args.]) + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ + $cares_includes_netdb + ]],[[ + if(0 != getservbyport_r(0, 0, 0, 0, 0, 0)) + return 1; + ]]) + ],[ + AC_MSG_RESULT([yes]) + tst_compi_getservbyport_r="yes" + tst_nargs_getservbyport_r="6" + ],[ + AC_MSG_RESULT([no]) + tst_compi_getservbyport_r="no" + ]) + fi + AC_MSG_CHECKING([if getservbyport_r is compilable]) + if test "$tst_compi_getservbyport_r" = "yes"; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + fi + # + if test "$tst_compi_getservbyport_r" = "yes"; then + AC_MSG_CHECKING([if getservbyport_r usage allowed]) + if test "x$cares_disallow_getservbyport_r" != "xyes"; then + AC_MSG_RESULT([yes]) + tst_allow_getservbyport_r="yes" + else + AC_MSG_RESULT([no]) + tst_allow_getservbyport_r="no" + fi + fi + # + AC_MSG_CHECKING([if getservbyport_r might be used]) + if test "$tst_links_getservbyport_r" = "yes" && + test "$tst_proto_getservbyport_r" = "yes" && + test "$tst_compi_getservbyport_r" = "yes" && + test "$tst_allow_getservbyport_r" = "yes"; then + AC_MSG_RESULT([yes]) + AC_DEFINE_UNQUOTED(HAVE_GETSERVBYPORT_R, 1, + [Define to 1 if you have the getservbyport_r function.]) + AC_DEFINE_UNQUOTED(GETSERVBYPORT_R_ARGS, $tst_nargs_getservbyport_r, + [Specifies the number of arguments to getservbyport_r]) + if test "$tst_nargs_getservbyport_r" -eq "4"; then + AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, sizeof(struct servent_data), + [Specifies the size of the buffer to pass to getservbyport_r]) + else + AC_DEFINE(GETSERVBYPORT_R_BUFSIZE, 4096, + [Specifies the size of the buffer to pass to getservbyport_r]) + fi + ac_cv_func_getservbyport_r="yes" + else + AC_MSG_RESULT([no]) + ac_cv_func_getservbyport_r="no" + fi +]) + + dnl CARES_CHECK_FUNC_STRCASECMP dnl ------------------------------------------------- dnl Verify if strcasecmp is available, prototyped, and -- cgit v1.2.3