if ((ld = ldap_init(ldap_host, LDAP_PORT)) == NULL ) {
perror( "ldap_init failed" );
exit( EXIT_FAILURE );
}
/* set the LDAP version to be 3 */
if (ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &desired_version) != LDAP_OPT_SUCCESS)
{
ldap_perror(ld, "ldap_set_option");
exit(EXIT_FAILURE);
}
if(ldap_start_tls_s(ld,NULL,NULL)!=LDAP_SUCCESS)
{
ldap_perror(ld, "ldap_start_tls");
exit(EXIT_FAILURE);
}