From: Roger Meier Date: Tue, 8 Apr 2014 21:52:01 +0000 (+0200) Subject: THRIFT-2454: c_glib: There is no gethostbyname_r() in some OS X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=bea3144a456a635c7a2e84c92277c5ad27f892d6;p=common%2Fthrift.git THRIFT-2454: c_glib: There is no gethostbyname_r() in some OS Patch: Jin-wook Jeong --- diff --git a/configure.ac b/configure.ac index 483c2839..f4d1869b 100755 --- a/configure.ac +++ b/configure.ac @@ -530,6 +530,7 @@ AC_CHECK_FUNCS([strtoul]) AC_CHECK_FUNCS([bzero]) AC_CHECK_FUNCS([ftruncate]) AC_CHECK_FUNCS([gethostbyname]) +AC_CHECK_FUNCS([gethostbyname_r]) AC_CHECK_FUNCS([gettimeofday]) AC_CHECK_FUNCS([memmove]) AC_CHECK_FUNCS([memset]) diff --git a/lib/c_glib/src/thrift/c_glib/transport/thrift_socket.c b/lib/c_glib/src/thrift/c_glib/transport/thrift_socket.c index a371ace1..68eb21c7 100644 --- a/lib/c_glib/src/thrift/c_glib/transport/thrift_socket.c +++ b/lib/c_glib/src/thrift/c_glib/transport/thrift_socket.c @@ -54,16 +54,24 @@ thrift_socket_is_open (ThriftTransport *transport) gboolean thrift_socket_open (ThriftTransport *transport, GError **error) { - struct hostent he, *hp = NULL; + struct hostent *hp = NULL; struct sockaddr_in pin; int err; +#if defined(HAVE_GETHOSTBYNAME_R) + struct hostent he; char buf[1024]; +#endif ThriftSocket *tsocket = THRIFT_SOCKET (transport); g_return_val_if_fail (tsocket->sd == 0, FALSE); /* lookup the destination host */ - if (gethostbyname_r(tsocket->hostname, &he, buf, 1024, &hp, &err) != 0 || hp == NULL) { +#if defined(HAVE_GETHOSTBYNAME_R) + if (gethostbyname_r (tsocket->hostname, &he, buf, 1024, &hp, &err) != 0 || hp == NULL) +#else + if ((hp = gethostbyname (tsocket->hostname)) == NULL && (err = h_errno)) +#endif + { /* host lookup failed, bail out with an error */ g_set_error (error, THRIFT_TRANSPORT_ERROR, THRIFT_TRANSPORT_ERROR_HOST, "host lookup failed for %s:%d - %s",