* configure.in: Check return type for getservbyname_r just as for
authorKen Raeburn <raeburn@mit.edu>
Fri, 31 May 2002 20:53:39 +0000 (20:53 +0000)
committerKen Raeburn <raeburn@mit.edu>
Fri, 31 May 2002 20:53:39 +0000 (20:53 +0000)
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
src/include/configure.in
src/include/fake-addrinfo.h

index e64a3fb26e9fad01589084f2bb863a559504c35f..d22528f10bd4843c9dfad2115feb11a0dc90dc84 100644 (file)
@@ -1,3 +1,15 @@
+2002-05-31  Ken Raeburn  <raeburn@mit.edu>
+
+       * 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  <raeburn@mit.edu>
 
        Reduce build-time per-system dependencies and krb5.h namespace
index f18527f5b194f12c7a715f0bef7f76243a72012a..a5a548dcbe3faa7a11f7959cd6f439949fb65023 100644 (file)
@@ -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 <netdb.h>
+  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 <netdb.h>
+  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
index d555726c828c526608db956697b82c3a948d71c7..10c9c3c2a924c478530bb0c7ba89cd263e7eba25 100644 (file)
 /* 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) \
     }
 #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, \
 #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 *,