if ( ludp->lud_port == 0 ) { if (( ludp->lud_options & LDAP_URL_OPT_SECURE ) == 0 ) { srv->lsrv_port = LDAP_PORT; } else { srv->lsrv_port = LDAPS_PORT; }
if ( ludp->lud_port != 0 ) {  srv->lsrv_port = ludp->lud_port; } else if ( ludp->lud_host == NULL ) {  srv->lsrv_port = ld->ld_defport; } else if (( ludp->lud_options & LDAP_URL_OPT_SECURE ) == 0 ) {  srv->lsrv_port = LDAP_PORT;
ldap_url_search( LDAP *ld, const char *url, int attrsonly ){	int		err, msgid;	LDAPURLDesc	*ludp;	BerElement	*ber;	LDAPServer	*srv;	char		*host;	if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {		return( -1 );		/* punt */	}	if ( ldap_url_parse( url, &ludp ) != 0 ) {		LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );		return( -1 );	}	LDAP_MUTEX_LOCK( ld, LDAP_MSGID_LOCK );	msgid = ++ld->ld_msgid;	LDAP_MUTEX_UNLOCK( ld, LDAP_MSGID_LOCK );	if ( nsldapi_build_search_req( ld, ludp->lud_dn, ludp->lud_scope,	    ludp->lud_filter, ludp->lud_attrs, attrsonly, NULL, NULL,	    -1, -1, msgid, &ber ) != LDAP_SUCCESS ) {		return( -1 );	}	err = 0;	if ( ludp->lud_host == NULL ) {		host = ld->ld_defhost;	} else {		host = ludp->lud_host;	}	if (( srv = (LDAPServer *)NSLDAPI_CALLOC( 1, sizeof( LDAPServer )))	    == NULL || ( host != NULL &&	    ( srv->lsrv_host = nsldapi_strdup( host )) == NULL )) {		if ( srv != NULL ) {			NSLDAPI_FREE( srv );		}		LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY, NULL, NULL );		err = -1;	} else {		if ( ludp->lud_port == 0 ) {			if (( ludp->lud_options & LDAP_URL_OPT_SECURE ) == 0 ) {				srv->lsrv_port = LDAP_PORT;			} else {				srv->lsrv_port = LDAPS_PORT;			}		} else {			 srv->lsrv_port = ludp->lud_port;		}	}	if (( ludp->lud_options & LDAP_URL_OPT_SECURE ) != 0 ) {		srv->lsrv_options |= LDAP_SRV_OPT_SECURE;	}	if ( err != 0 ) {		ber_free( ber, 1 );	} else {		err = nsldapi_send_server_request( ld, ber, msgid, NULL, srv,		    NULL, NULL, 1 );	}	ldap_free_urldesc( ludp );	return( err );}