Initializes an LDAP session associated with an LDAP server and returns a pointer to a session handle.
#include <ldap.h> LDAP *ldap_init ( const char *host, int port);
(IN) Contains the names of the available hosts, each separated by a space, or a list of IP addresses (in dot format) of the hosts, each separated by a space. If a port number is included with the name or the address, it is separated from them with a colon (:).
(IN) Contains the TCP port number to connect to. If a port number is included with the host parameter, this parameter is ignored.
If you connect to an LDAP v2 server, you must call an LDAP bind operation before performing any operations. If you connect to an LDAP v3 server, some operations can be performed before calling a bind operation.
The ldap_init function does not actually communicate with the LDAP server. Communication begins when the application binds or does some other operation.
The LDAP libraries first contact the first server listed in the host parameter. If they are unable to communicate with that server, they try the next server and then the next.
The session handle returned contains opaque data identifying the session. To get or set handle information, use ldap_set_option and ldap_get_option. For a list of the handle options, see Section 6.10, Session Preference Options.
IMPORTANT:The ldap_init function allocates memory for the LDAP structure. This memory must be freed by calling ldap_unbind or ldap_unbind_s even when an LDAP bind function is not called or the LDAP bind function fails.