LDAP structure that represents the context of the connection to that server.
#include <ldap.h>
LDAP * ldap_init( const char *defhost, int defport );
defhost | |
defport |
ldap_init() function initializes a session with an LDAP server. ldap_init() allocates an LDAP structure containing information about the session, including the host name and port of the LDAP server, preferences for the session (such as the maximum number of entries to return in a search), and the error code of the last LDAP operation performed.
You can specify a list of LDAP servers that you want to attempt to connect to. Your client will attempt to connect to the first LDAP server in the list. If the attempt fails, your client will attempt to connect to the next LDAP server in the list.
You can specify the list of LDAP servers by passing a space-delimited list of the host names as the host argument. For example:
...
LDAP *ld
...
ld = ldap_init( "ld1.netscape.com ld2.netscape.com ld3.netscape.com",
LDAP_PORT );In the example above, the LDAP client will attempt to connect to the LDAP server on ld1.netscape.com, port 389. If that server does not respond, the client will attempt to connect to the LDAP server on ld2.netscape.com, port 389. If that server does not respond, the client will use the server on ld3.netscape.com, port 389. If any of the servers do not use the default port specified by the
defport argument, use the host:port format to specify the server name. For example:
...
LDAP *ld
...
ld = ldap_init( "ld1.netscape.com ld2.netscape.com:38900", LDAP_PORT );In the example above, the LDAP client will attempt to connect to the LDAP server on ld1.netscape.com, port 389. If that server does not respond, the client will attempt to connect to the LDAP server on ld2.netscape.com, port 38900. Once you initialize a session, you need to call the
ldap_simple_bind() or ldap_simple_bind_s() function to connect and authenticate to the LDAP server.
For more information, see "Initializing an LDAP Session" on page 51.
(Note that if you are connecting to a secure LDAP server over SSL, you should be calling the ldapssl_init() function instead. For details, see Chapter 12, "Connecting Over SSL".)
#include <ldap.h>
...
LDAP *ld;
/* Specify the host name of the LDAP server. */
char *ldap_host = "ldap.netscape.com";
/* Because the LDAP server is running on the standard LDAP port (port 389), you can use LDAP_PORT to identify the port number. */
int ldap_port = LDAP_PORT;
...
/* Initialize the session with ldap.netscape.com:389 */
if ( ( ld = ldap_init( ldap_host, ldap_port ) ) == NULL ) { perror( "ldap_init" );
return( 1 );
}
...
/* Subsequent calls that authenticate to the LDAP server. */
...
ldap_unbind(), ldap_unbind_s().
Last Updated: 10/01/98 17:06:23