+
+ if ( select(ldap_int_tblsize, z, &wfds,
+#ifdef HAVE_WINSOCK
+ &efds,
+#else
+ z,
+#endif
+ opt_tv ? &tv : NULL) == -1)
+ return ( -1 );
+
+#ifdef HAVE_WINSOCK
+ /* This means the connection failed */
+ if (FD_ISSET(s, &efds))
+ {
+ ldap_pvt_set_errno(WSAECONNREFUSED);
+ osip_debug(ld, "ldap_pvt_connect: error on socket %d: "
+ "errno: %d (%s)\n", s, errno, sock_errstr(errno));
+ return -1;
+ }
+#endif
+ if ( FD_ISSET(s, &wfds) ) {
+ if ( ldap_pvt_is_socket_ready(ld, s) == -1 )
+ return ( -1 );
+ if ( ldap_pvt_ndelay_off(ld, s) == -1 )
+ return ( -1 );
+ return ( 0 );
+ }
+ osip_debug(ld, "ldap_connect_timeout: timed out\n",0,0,0);
+ ldap_pvt_set_errno( ETIMEDOUT );
+ return ( -1 );
+}
+
+#ifndef HAVE_INET_ATON
+int
+ldap_pvt_inet_aton( const char *host, struct in_addr *in)
+{
+ unsigned long u = inet_addr( host );
+ if ( u != 0xffffffff || u != (unsigned long) -1 ) {
+ in->s_addr = u;
+ return 1;
+ }
+ return 0;
+}
+#endif
+
+
+int
+ldap_connect_to_host(LDAP *ld, Sockbuf *sb, const char *host,
+ unsigned long address, int port, int async)
+{
+ struct sockaddr_in sin;
+ struct in_addr in;
+ ber_socket_t s = AC_SOCKET_INVALID;
+ int rc, i, use_hp = 0;
+ struct hostent *hp, he_buf;
+ int local_h_errno;
+ char *ha_buf=NULL, *p, *q;
+
+ osip_debug(ld, "ldap_connect_to_host\n",0,0,0);
+
+ if (host != NULL) {
+ if (! inet_aton( host, &in) ) {
+ rc = ldap_pvt_gethostbyname_a(host, &he_buf, &ha_buf,
+ &hp, &local_h_errno);
+
+ if ( rc < 0 )
+ ; /*XXX NO MEMORY? */
+
+ if ( (rc < 0) || (hp == NULL) ) {
+#ifdef HAVE_WINSOCK
+ ldap_pvt_set_errno( WSAGetLastError() );
+#else
+ /* not exactly right, but... */
+ ldap_pvt_set_errno( EHOSTUNREACH );
+#endif
+ if (ha_buf) LDAP_FREE(ha_buf);
+ return -1;