Locating default LDAP servers

You can search for default LDAP servers with the LDAP APIs.

When the ldap_init(), ldap_open(), or ldap_ssl_init() APIs are called with an LDAP URL of the following forms, the ldap_server_locate() function is used to obtain a set of one or more default LDAP servers:
ld=ldap_init ("ldap://", ldap_port);          /* locate servers with 
        non-secure ports */
ld=ldap_ssl_init ("ldaps://", ldap_port);     /* locate servers with 
        secure SSL ports */
The ldap_server_locate() API provides several options for searching for default LDAP servers. An application by using ldap_server_locate() in an explicit fashion can control these options. When ldap_server_locate() is used implicitly, as described here, the following options are used:
Security
If the non-secure LDAP URL is specified such as ldap://, servers with a non-secure security type are used as candidate servers only. If the secure LDAP URL is specified such as ldaps://, servers with a secure security type are used as candidate servers only.
Source for Server Information
The ldap_server_locate() API can be used to find default LDAP server information in either a local configuration file, or published in the Domain Name System (DNS). In this case, the default behavior is used. The ldap_server_locate() API looks for a local configuration file first, and attempts to find one or more LDAP servers that meet the search criteria (security and suffix filter). If nothing is found, it then searches DNS. For more information about using a local configuration file, see ldap_server_conf_save().
DNS Domain Name
When you search the local configuration and DNS, the ldap_server_locate() API assumes that your default LDAP servers are published in your locally configured TCP or DNS. For example, ibm.comĀ®.
Service Name and Protocol
A complete search is run by using ldap for the service name and tcp for the protocol. If no servers are located, the search is rerun by using _ldap and _tcp.
Note: If the default behavior as described here is not appropriate for your application, consider by using the ldap_server_locate() API explicitly before you call the ldap_init() or ldap_ssl_init() API.