Table of Contents | Previous | Next | Index

Netscape Directory SDK 3.0 for C Programmer’s Guide
     Chapter 18 Functions

ldap_get_dn()

The ldap_get_dn() routine returns the distinguished name (DN) for an entry in a chain of search results. You can get an entry from a chain of search results by calling the ldap_first_entry() and ldap_next_entry() functions. For more information, see "Getting Distinguished Names for Each Entry" on page 127.

Syntax

#include <ldap.h>
char * ldap_get_dn( LDAP *ld, LDAPMessage *entry );

Parameters

This function has the following parameters:

ld

Connection handle, which is a pointer to an LDAP structure containing information about the connection to the LDAP server.

entry

Pointer to an entry in a chain of search results, as returned by the ldap_first_entry() and ldap_next_entry() functions.

Returns

One of the following values:

Example

The following section of code prints the distinguished name for each entry found in a search.

#include <stdio.h>
#include <ldap.h>
...
LDAP *ld;
LDAPMessage *result, *e;
char *dn;
char *my_searchbase = "o=Airius.com";
char *my_filter = "(sn=Jensen)";
...
/* Search the directory */
if ( ldap_search_s( ld, my_searchbase, LDAP_SCOPE_SUBTREE, my_filter, 
   NULL, 0, &result ) != LDAP_SUCCESS ) {
   ldap_perror( ld, "ldap_search_s" );
   return( 1 );
}
/* For each matching entry found, print out the name of the entry.*/
for ( e = ldap_first_entry( ld, result ); e != NULL; 
   e = ldap_next_entry( ld, e ) ) {
   if ( ( dn = ldap_get_dn( ld, e ) ) != NULL ) {
      printf( "dn: %s\n", dn );
      /* Free the memory used for the DN when done */
      ldap_memfree( dn );
   }
}
/* Free the result from memory when done. */
ldap_msgfree( result );
...

See Also

ldap_first_entry(), ldap_next_entry().


Table of Contents | Previous | Next | Index

Last Updated: 10/01/98 17:06:23