From 933efcddb5e4e17f3fcfcb963fc2ee7800df6ede Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Fri, 31 May 2002 20:53:39 +0000 Subject: [PATCH] * configure.in: Check return type for getservbyname_r just as for gethostbyname_r. * fake-addrinfo.h (GET_HOST_BY_NAME): Use plain gethostbyname if THREADSAFE_GETHOSTBYNAME is defined, even if _r versions are available. (GET_HOST_BY_ADDR) [GETHOSTBYNAME_R_RETURNS_INT]: Add missing variable declaration. (GET_SERV_BY_NAME, GET_SERV_BY_PORT): New macros, in three flavors, parallel to GET_HOST macros; not used yet. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@14461 dc483132-0cff-0310-8789-dd5450dbe970 --- src/include/ChangeLog | 12 ++++++++ src/include/configure.in | 30 +++++++++++++++++-- src/include/fake-addrinfo.h | 60 +++++++++++++++++++++++++++++++++++-- 3 files changed, 97 insertions(+), 5 deletions(-) diff --git a/src/include/ChangeLog b/src/include/ChangeLog index e64a3fb26..d22528f10 100644 --- a/src/include/ChangeLog +++ b/src/include/ChangeLog @@ -1,3 +1,15 @@ +2002-05-31 Ken Raeburn + + * configure.in: Check return type for getservbyname_r just as for + gethostbyname_r. + * fake-addrinfo.h (GET_HOST_BY_NAME): Use plain gethostbyname if + THREADSAFE_GETHOSTBYNAME is defined, even if _r versions are + available. + (GET_HOST_BY_ADDR) [GETHOSTBYNAME_R_RETURNS_INT]: Add missing + variable declaration. + (GET_SERV_BY_NAME, GET_SERV_BY_PORT): New macros, in three + flavors, parallel to GET_HOST macros; not used yet. + 2002-05-24 Ken Raeburn Reduce build-time per-system dependencies and krb5.h namespace diff --git a/src/include/configure.in b/src/include/configure.in index f18527f5b..a5a548dcb 100644 --- a/src/include/configure.in +++ b/src/include/configure.in @@ -7,9 +7,7 @@ AC_PROG_LEX AC_C_CONST AC_CHECK_FUNCS(strdup labs setvbuf memmove bcopy inet_ntoa inet_aton gethostbyname_r gethostbyaddr_r getservbyname_r getservbyport_r) dnl -dnl Check what the return type for gethostbyname_r is. -dnl I don't think we need this for getservbyname_r at the moment, but -dnl it does have similar issues. +dnl Check what the return types for gethostbyname_r and getservbyname_r are. dnl if test "$ac_cv_func_gethostbyname_r" = yes; then AC_MSG_CHECKING([if gethostbyname_r returns an int]) @@ -37,6 +35,32 @@ if test "$ac_cv_func_gethostbyname_r" = yes; then fi fi dnl +if test "$ac_cv_func_getservbyname_r" = yes; then + AC_MSG_CHECKING([if getservbyname_r returns an int]) + AC_CACHE_VAL(krb5_cv_getservbyname_r_returns_int, + [AC_TRY_COMPILE([#include + extern int getservbyname_r ();], [1;], + krb5_cv_getservbyname_r_returns_int=yes, + krb5_cv_getservbyname_r_returns_int=no)]) + AC_MSG_RESULT($krb5_cv_getservbyname_r_returns_int) + + AC_MSG_CHECKING([if getservbyname_r returns a pointer]) + AC_CACHE_VAL(krb5_cv_getservbyname_r_returns_ptr, + [AC_TRY_COMPILE([#include + extern struct servent *getservbyname_r ();], [1;], + krb5_cv_getservbyname_r_returns_ptr=yes, + krb5_cv_getservbyname_r_returns_ptr=no)]) + AC_MSG_RESULT($krb5_cv_getservbyname_r_returns_ptr) + + if test "$krb5_cv_getservbyname_r_returns_int" = "$krb5_cv_getservbyname_r_returns_ptr"; then + AC_MSG_WARN(cannot determine return type of getservbyname_r -- disabling) + ac_cv_func_getservbyname_r=no + fi + if test "$krb5_cv_getservbyname_r_returns_int" = yes; then + AC_DEFINE(GETSERVBYNAME_R_RETURNS_INT, 1, [Define if getservbyname_r returns int rather than struct servent * ]) + fi +fi +dnl HAVE_YYLINENO CHECK_DIRENT AC_TYPE_UID_T diff --git a/src/include/fake-addrinfo.h b/src/include/fake-addrinfo.h index d555726c8..10c9c3c2a 100644 --- a/src/include/fake-addrinfo.h +++ b/src/include/fake-addrinfo.h @@ -105,7 +105,7 @@ /* Do we actually have *any* systems we care about that don't provide either getaddrinfo or one of these two flavors of gethostbyname_r? */ -#ifndef HAVE_GETHOSTBYNAME_R +#if !defined(HAVE_GETHOSTBYNAME_R) || defined(THREADSAFE_GETHOSTBYNAME) #define GET_HOST_BY_NAME(NAME, HP, ERR) \ { (HP) = gethostbyname (NAME); (ERR) = h_errno; } #define GET_HOST_BY_ADDR(ADDR, ADDRLEN, FAMILY, HP, ERR) \ @@ -126,7 +126,7 @@ } #define GET_HOST_BY_ADDR(ADDR, ADDRLEN, FAMILY, HP, ERR) \ { \ - struct hostent my_h_ent; \ + struct hostent my_h_ent, *my_hp; \ int my_h_err; \ char my_h_buf[8192]; \ (HP) = (gethostbyaddr_r((ADDR), (ADDRLEN), (FAMILY), &my_h_ent, \ @@ -158,6 +158,62 @@ #endif #endif +/* Now do the same for getservby* functions. */ +#ifndef HAVE_GETSERVBYNAME_R +#define GET_SERV_BY_NAME(NAME, PROTO, SP, ERR) \ + ((SP) = getservbyname (NAME, PROTO), (ERR) = (SP) ? 0 : -1) +#define GET_SERV_BY_PORT(PORT, PROTO, SP, ERR) \ + ((SP) = getservbyport (PORT, PROTO), (ERR) = (SP) ? 0 : -1) +#else +#ifdef GETSERVBYNAME_R_RETURNS_INT +#define GET_SERV_BY_NAME(NAME, PROTO, SP, ERR) \ + { \ + struct servent my_s_ent, *my_sp; \ + int my_s_err; \ + char my_s_buf[8192]; \ + (SP) = (getservbyname_r((NAME), (PROTO), &my_s_ent, \ + my_s_buf, sizeof (my_s_buf), &my_sp, \ + &my_s_err) \ + ? 0 \ + : &my_s_ent); \ + (ERR) = my_s_err; \ + } +#define GET_SERV_BY_PORT(PORT, PROTO, SP, ERR) \ + { \ + struct servent my_s_ent, *my_sp; \ + int my_s_err; \ + char my_s_buf[8192]; \ + (SP) = (getservbyport_r((PORT), (PROTO), &my_s_ent, \ + my_s_buf, sizeof (my_s_buf), &my_sp, \ + &my_s_err) \ + ? 0 \ + : &my_s_ent); \ + (ERR) = my_s_err; \ + } +#else +/* returns ptr */ +#define GET_SERV_BY_NAME(NAME, PROTO, SP, ERR) \ + { \ + struct servent my_s_ent; \ + int my_s_err; \ + char my_s_buf[8192]; \ + (SP) = getservbyname_r((NAME), (PROTO), &my_s_ent, \ + my_s_buf, sizeof (my_s_buf), &my_s_err); \ + (ERR) = my_s_err; \ + } + +#define GET_SERV_BY_PORT(PORT, PROTO, SP, ERR) \ + { \ + struct servent my_s_ent; \ + int my_s_err; \ + char my_s_buf[8192]; \ + (SP) = getservbyport_r((PORT), (PROTO), &my_s_ent, \ + my_s_buf, sizeof (my_s_buf), &my_s_err); \ + (ERR) = my_s_err; \ + } +#endif +#endif + #ifdef WRAP_GETADDRINFO static int (*const gaiptr) (const char *, const char *, const struct addrinfo *, -- 2.26.2