LDAP_OPT_ERROR_NUMBER
Use the LDAP_OPT_ERROR_NUMBER setting to return an error code that is associated with the most recent LDAP error.
This setting is a read-only option. It returns the error code that is associated with the most recent LDAP error that occurred for the specified LDAP connection. For example:
int error;
ldap_get_option( ld, LDAP_OPT_ERROR_NUMBER, &error);