hints.ai_socktype = socktype;
snprintf(serv, sizeof serv, "%d", port );
- if ( ( err = getaddrinfo(host, serv, &hints, &res) ) ) {
+
+#ifdef LDAP_R_COMPILE
+ /* most getaddrinfo(3) use non-threadsafe resolver libraries */
+ ldap_pvt_thread_mutex_lock(&ldap_int_resolv_mutex);
+#endif
+
+ err = getaddrinfo( host, serv, &hints, &res );
+
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock(&ldap_int_resolv_mutex);
+#endif
+
+ if ( err != 0 ) {
osip_debug(ld, "ldap_connect_to_host: getaddrinfo failed: %s\n",
AC_GAI_STRERROR(err), 0, 0);
return -1;
# ifndef USE_CTIME_R
static ldap_pvt_thread_mutex_t ldap_int_ctime_mutex;
# endif
-# if !defined( HAVE_GETHOSTBYNAME_R ) || !defined( HAVE_GETHOSTBYADDR_R )
- static ldap_pvt_thread_mutex_t ldap_int_gethostby_mutex;
-# endif
# ifdef HAVE_RES_QUERY
ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
# endif
int retval;
*buf = NULL;
- ldap_pvt_thread_mutex_lock( &ldap_int_gethostby_mutex );
+ ldap_pvt_thread_mutex_lock( &ldap_int_resolv_mutex );
he = gethostbyname( name );
retval = 0;
}
- ldap_pvt_thread_mutex_unlock( &ldap_int_gethostby_mutex );
+ ldap_pvt_thread_mutex_unlock( &ldap_int_resolv_mutex );
return retval;
#else
int retval;
*buf = NULL;
- ldap_pvt_thread_mutex_lock( &ldap_int_gethostby_mutex );
+ ldap_pvt_thread_mutex_lock( &ldap_int_resolv_mutex );
he = gethostbyaddr( addr, len, type );
retval = 0;
}
- ldap_pvt_thread_mutex_unlock( &ldap_int_gethostby_mutex );
+ ldap_pvt_thread_mutex_unlock( &ldap_int_resolv_mutex );
return retval;
#else /* gethostbyaddr() */
ldap_pvt_thread_mutex_init( &ldap_int_ctime_mutex );
#endif
-#if !defined( HAVE_GETHOSTBYNAME_R ) || !defined( HAVE_GETHOSTBYADDR_R )
- ldap_pvt_thread_mutex_init( &ldap_int_gethostby_mutex );
-#endif
-
#ifdef HAVE_RES_QUERY
ldap_pvt_thread_mutex_init( &ldap_int_resolv_mutex );
#endif