]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/os-ip.c
Commit preliminary fix for ldap.conf base usage.
[openldap] / libraries / libldap / os-ip.c
index 9c16fa921570db122ebdb29cc8ae883d683c4b44..1b22917a46e95c5f996beb6a58801bbf0b4a3dc2 100644 (file)
@@ -26,8 +26,6 @@
 #include <sys/ioctl.h>
 #endif
 
-#include "lber.h"
-#include "ldap.h"
 #include "ldap-int.h"
 
 int
@@ -37,7 +35,7 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
  * if host == NULL, connect using address
  * "address" and "port" must be in network byte order
  * zero is returned upon success, -1 if fatal error, -2 EINPROGRESS
- * async is only used ifdef LDAP_REFERRALS (non-0 means don't wait for connect)
+ * async is only used ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS (non-0 means don't wait for connect)
  * XXX async is not used yet!
  */
 {
@@ -46,9 +44,9 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
        struct sockaddr_in      sin;
        struct hostent          *hp = NULL;
 #ifdef notyet
-#ifdef LDAP_REFERRALS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
        int                     status; /* for ioctl call */
-#endif /* LDAP_REFERRALS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
 #endif /* notyet */
 
        Debug( LDAP_DEBUG_TRACE, "ldap_connect_to_host: %s:%d\n",
@@ -56,12 +54,21 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
 
        connected = use_hp = 0;
 
-       if ( host != NULL && ( address = inet_addr( host )) == -1 ) {
+       if ( host != NULL ) {
+           address = inet_addr( host );
+           /* This was just a test for -1 until OSF1 let inet_addr return
+              unsigned int, which is narrower than 'unsigned long address' */
+           if ( address == 0xffffffff || address == (unsigned long) -1 ) {
                if ( (hp = gethostbyname( host )) == NULL ) {
+#ifdef HAVE_WINSOCK
+                       errno = WSAGetLastError();
+#else
                        errno = EHOSTUNREACH;   /* not exactly right, but... */
+#endif
                        return( -1 );
                }
                use_hp = 1;
+           }
        }
 
        rc = -1;
@@ -70,13 +77,13 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
                        return( -1 );
                }
 #ifdef notyet
-#ifdef LDAP_REFERRALS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
                status = 1;
                if ( async && ioctl( s, FIONBIO, (caddr_t)&status ) == -1 ) {
                        Debug( LDAP_DEBUG_ANY, "FIONBIO ioctl failed on %d\n",
                            s, 0, 0 );
                }
-#endif /* LDAP_REFERRALS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
 #endif /* notyet */
                (void)memset( (char *)&sin, 0, sizeof( struct sockaddr_in ));
                sin.sin_family = AF_INET;
@@ -91,8 +98,11 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
                        rc = 0;
                        break;
                } else {
+#ifdef HAVE_WINSOCK
+                       errno = WSAGetLastError();
+#endif
 #ifdef notyet
-#ifdef LDAP_REFERRALS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
 #ifdef EAGAIN
                        if ( errno == EINPROGRESS || errno == EAGAIN ) {
 #else /* EAGAIN */
@@ -103,7 +113,7 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
                                rc = -2;
                                break;
                        }
-#endif /* LDAP_REFERRALS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
 #endif /* notyet */
 
 #ifdef LDAP_DEBUG              
@@ -111,7 +121,7 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
                                perror( (char *)inet_ntoa( sin.sin_addr ));
                        }
 #endif
-                       close( s );
+                       tcp_close( s );
                        if ( !use_hp ) {
                                break;
                        }
@@ -122,17 +132,17 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
 
        if ( connected ) {
 #ifdef notyet
-#ifdef LDAP_REFERRALS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
                status = 0;
                if ( !async && ioctl( s, FIONBIO, (caddr_t)&on ) == -1 ) {
                        Debug( LDAP_DEBUG_ANY, "FIONBIO ioctl failed on %d\n",
                            s, 0, 0 );
                }
-#endif /* LDAP_REFERRALS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
 #endif /* notyet */
 
                Debug( LDAP_DEBUG_TRACE, "sd %d connected to: %s\n",
-                   s, inet_ntoa( sin.sin_addr ), 0 );
+                   s, (char *) inet_ntoa( sin.sin_addr ), 0 );
        }
 
        return( rc );
@@ -146,7 +156,7 @@ ldap_close_connection( Sockbuf *sb )
 }
 
 
-#ifdef KERBEROS
+#ifdef HAVE_KERBEROS
 char *
 ldap_host_connected_to( Sockbuf *sb )
 {
@@ -169,16 +179,16 @@ ldap_host_connected_to( Sockbuf *sb )
        if (( hp = gethostbyaddr( (char *) &sin.sin_addr,
            sizeof( sin.sin_addr ), AF_INET )) != NULL ) {
                if ( hp->h_name != NULL ) {
-                       return( strdup( hp->h_name ));
+                       return( ldap_strdup( hp->h_name ));
                }
        }
 
        return( NULL );
 }
-#endif /* KERBEROS */
+#endif /* HAVE_KERBEROS */
 
 
-#ifdef LDAP_REFERRALS
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS
 /* for UNIX */
 struct selectinfo {
        fd_set  si_readfds;
@@ -249,7 +259,7 @@ ldap_is_read_ready( LDAP *ld, Sockbuf *sb )
 
 
 void *
-ldap_new_select_info()
+ldap_new_select_info( void )
 {
        struct selectinfo       *sip;
 
@@ -283,6 +293,8 @@ do_ldap_select( LDAP *ld, struct timeval *timeout )
                tblsize = sysconf( _SC_OPEN_MAX );
 #elif defined( HAVE_GETDTABLESIZE )
                tblsize = getdtablesize();
+#else
+               tblsize = FD_SETSIZE;
 #endif /* !USE_SYSCONF */
 
 #ifdef FD_SETSIZE
@@ -299,4 +311,4 @@ do_ldap_select( LDAP *ld, struct timeval *timeout )
        return( select( tblsize, &sip->si_use_readfds, &sip->si_use_writefds,
            NULL, timeout ));
 }
-#endif /* LDAP_REFERRALS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */