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])
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
/* 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 *,