]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/cldap.c
Remove LDAP_PORT dependencies so that ldap.conf defaults take over.
[openldap] / libraries / libldap / cldap.c
index 5ce38dee7d7a88656ed3ed0ad0f7670947a90a1a..5ae4c6a66350a2fe51235658ccf385b0dd543485 100644 (file)
@@ -20,6 +20,7 @@ static char copyright[] = "@(#) Copyright (c) 1990, 1994 Regents of the Universi
 #include <ac/socket.h>
 #include <ac/string.h>
 #include <ac/time.h>
+#include <ac/unistd.h>
 
 #include "ldap-int.h"
 
@@ -65,10 +66,6 @@ cldap_open( char *host, int port )
 
     Debug( LDAP_DEBUG_TRACE, "ldap_open\n", 0, 0, 0 );
 
-    if ( port == 0 ) {
-           port = LDAP_PORT;
-    }
-
     if ( (s = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 ) {
        return( NULL );
     }
@@ -87,8 +84,8 @@ cldap_open( char *host, int port )
     }
     if ( (ld->ld_sb.sb_fromaddr = (void *) calloc( 1,
            sizeof( struct sockaddr ))) == NULL ) {
-       free( ld );
-       close( s );
+
+       ldap_ld_free(ld, 1);
        return( NULL );
     }  
     ld->ld_sb.sb_sd = s;
@@ -109,7 +106,10 @@ cldap_open( char *host, int port )
                }
            }
 
-           if ( (address = inet_addr( host )) == (unsigned long) -1L ) {
+           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 ) {
                    errno = EHOSTUNREACH;
                    continue;
@@ -120,8 +120,7 @@ cldap_open( char *host, int port )
                            (char *)hp->h_addr_list[ i ],
                            sizeof(sock.sin_addr.s_addr));
                    if ( add_addr( ld, (struct sockaddr *)&sock ) < 0 ) {
-                       close( s );
-                       free( ld );
+                       ldap_ld_free( ld, 1 );
                        return( NULL );
                    }
                }
@@ -129,14 +128,13 @@ cldap_open( char *host, int port )
            } else {
                sock.sin_addr.s_addr = address;
                if ( add_addr( ld, (struct sockaddr *)&sock ) < 0 ) {
-                   close( s );
-                   free( ld );
+                   ldap_ld_free( ld, 1 );
                    return( NULL );
                }
            }
 
            if ( ld->ld_host == NULL ) {
-                   ld->ld_host = strdup( host );
+                   ld->ld_host = ldap_strdup( host );
            }
        }
 
@@ -144,8 +142,7 @@ cldap_open( char *host, int port )
        address = INADDR_LOOPBACK;
        sock.sin_addr.s_addr = htonl( address );
        if ( add_addr( ld, (struct sockaddr *)&sock ) < 0 ) {
-           close( s );
-           free( ld );
+           ldap_ld_free( ld, 1 );
            return( NULL );
        }
     }
@@ -155,7 +152,7 @@ cldap_open( char *host, int port )
            || ( ld->ld_defconn = ldap_new_connection( ld, NULL, 1,0,0 )) == NULL
 #endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_REFERRALS */
            ) {
-       free( ld );
+       ldap_ld_free( ld, 0 );
        return( NULL );
     }
 
@@ -295,8 +292,8 @@ cldap_result( LDAP *ld, int msgid, LDAPMessage **res,
     tv.tv_usec = 0;
 
     Debug( LDAP_DEBUG_TRACE,
-           "cldap_result waiting up to %d seconds for a response\n",
-           tv.tv_sec, 0, 0 );
+           "cldap_result waiting up to %ld seconds for a response\n",
+           (long) tv.tv_sec, 0, 0 );
     ber_init_w_nullc( &ber, 0 );
     ldap_set_ber_options( ld, &ber );
 
@@ -468,7 +465,7 @@ cldap_parsemsg( LDAP *ld, int msgid, BerElement *ber,
            bv = NULL;
                
        } else {
-           Debug( LDAP_DEBUG_TRACE, "cldap_parsemsg got unknown tag %d\n",
+           Debug( LDAP_DEBUG_TRACE, "cldap_parsemsg got unknown tag %lu\n",
                    tag, 0, 0 );
            rc = LDAP_PROTOCOL_ERROR;
            break;      /* return w/error */