diff --git a/clients/fax500/rp500.c b/clients/fax500/rp500.c
index 67de48322d2b50da484d870524d894004dff88ab..8f81e70afbbaf901fad454635d4b9b0159f420b5 100644
--- a/clients/fax500/rp500.c
+++ b/clients/fax500/rp500.c
@@ -110,7 +110,7 @@ main( int argc, char **argv )
 		exit( -1 );
 	}
 
-	if ( (ld = ldap_open( ldaphost, LDAP_PORT )) == NULL ) {
+	if ( (ld = ldap_open( ldaphost, 0 )) == NULL ) {
 		perror( "ldap_open" );
 		exit( -1 );
 	}
diff --git a/clients/gopher/go500.c b/clients/gopher/go500.c
index de0059380ab5bdd4d3da3c35e7f4044bbfed8a91..ca582e939bf2ee1a96ad44fdd5f97941db94ee90 100644
--- a/clients/gopher/go500.c
+++ b/clients/gopher/go500.c
@@ -378,7 +378,7 @@ do_queries( int s )
 
 	if ( *query == '~' || *query == '@' ) {
 		ld = NULL;
-	} else if ( (ld = ldap_open( ldaphost, LDAP_PORT )) == NULL ) {
+	} else if ( (ld = ldap_open( ldaphost, 0 )) == NULL ) {
 		fprintf(fp,
 			"0An error occurred (explanation)\t@%d\t%s\t%d\r\n",
 			LDAP_SERVER_DOWN, myhost, myport );
diff --git a/clients/mail500/main.c b/clients/mail500/main.c
index f405bd31bb8b83a1dadc7f8f4017a2050c6d14c5..b147908db6216c922d8374d1e1039c860d6fc57f 100644
--- a/clients/mail500/main.c
+++ b/clients/mail500/main.c
@@ -355,7 +355,7 @@ connect_to_x500( void )
 {
 	int opt;
 
-	if ( (ld = ldap_open( ldaphost, LDAP_PORT )) == NULL ) {
+	if ( (ld = ldap_open( ldaphost, 0 )) == NULL ) {
 		syslog( LOG_ALERT, "ldap_open failed" );
 		return( -1 );
 	}
diff --git a/clients/tools/ldapmodify.c b/clients/tools/ldapmodify.c
index f30815a7063276ba05484ea3a3f4870b811dd9ac..88756ada24f19a1727c24e1577b45bb6f3a073fb 100644
--- a/clients/tools/ldapmodify.c
+++ b/clients/tools/ldapmodify.c
@@ -262,7 +262,7 @@ process_ldif_rec( char *rbuf )
 	    if ( !use_record && strcasecmp( type, T_REPLICA_STR ) == 0 ) {
 		++saw_replica;
 		if (( p = strchr( value, ':' )) == NULL ) {
-		    replicaport = LDAP_PORT;
+		    replicaport = 0;
 		} else {
 		    *p++ = '\0';
 		    replicaport = atoi( p );
diff --git a/clients/ud/main.c b/clients/ud/main.c
index 5a527c2979f1b98bd1c0d4df982f319f305795ec..79fab94ff04f5818d3cdf5f2dbaa02f31e9510f0 100644
--- a/clients/ud/main.c
+++ b/clients/ud/main.c
@@ -59,7 +59,7 @@ char copyright[] =
 static char *server = NULL;
 static char *config_file = UD_CONFIG_FILE;
 static char *filter_file = FILTERFILE;
-static int ldap_port = LDAP_PORT;
+static int ldap_port = 0;
 static int dereference = TRUE;
 
 char *default_bind_object = NULL;
diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c
index 821a29aa7498e1d4626ef8f608b4283d416f9366..f2d290e876286e219eeb7e3bf031cc382bdd21a9 100644
--- a/libraries/libldap/request.c
+++ b/libraries/libldap/request.c
@@ -696,7 +696,7 @@ ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp )
 				*ports++ = '\0';
 				srv->lsrv_port = atoi( ports );
 			} else {
-				srv->lsrv_port = LDAP_PORT;
+				srv->lsrv_port = openldap_ldap_global_options.ldo_defport;
 			}
 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
 		} else {
@@ -879,7 +879,7 @@ dn2servers( LDAP *ld, char *dn )	/* dn can also be a domain.... */
 	srvlist = NULL;
 
 	for ( i = 0; dxs[ i ] != NULL; ++i ) {
-		port = LDAP_PORT;
+		port = openldap_ldap_global_options.ldo_defport;
 		server_dn = NULL;
 		if ( strchr( dxs[ i ], ':' ) == NULL ) {
 			host = dxs[ i ];
diff --git a/libraries/libldap/url.c b/libraries/libldap/url.c
index bc6726164fe63cd7abd28f52b2aecff7ad1c9a18..510d89ac1ac013c85c25fd946bdec95a0c25445d 100644
--- a/libraries/libldap/url.c
+++ b/libraries/libldap/url.c
@@ -272,7 +272,7 @@ ldap_url_search( LDAP *ld, char *url, int attrsonly )
 			err = -1;
 		} else {
 			if ( ludp->lud_port == 0 ) {
-				srv->lsrv_port = LDAP_PORT;
+				srv->lsrv_port = openldap_ldap_global_options.ldo_defport;
 			} else {
 				 srv->lsrv_port = ludp->lud_port;
 			}