}
 
 void tool_perror(
+       char *func,
        int err,
        char *extra,
        char *matched,
        char *info,
        char **refs )
 {
-       fprintf( stderr, "ldap_bind: %s%s\n",
-               ldap_err2string( err ), extra ? extra : "" );
+       fprintf( stderr, "%s: %s (%d)%s\n",
+               func, ldap_err2string( err ), err, extra ? extra : "" );
 
        if ( matched && *matched ) {
                fprintf( stderr, _("\tmatched DN: %s\n"), matched );
                        || ( info && info[ 0 ] )
                        || refs )
                {
-                       tool_perror( err, msgbuf, matched, info, refs );
+                       tool_perror( "ldap_bind", err, msgbuf, matched, info, refs );
 
                        if( matched ) ber_memfree( matched );
                        if( info ) ber_memfree( info );
 
 void tool_server_controls LDAP_P(( LDAP *, LDAPControl *, int ));
 int tool_check_abandon LDAP_P(( LDAP *ld, int msgid ));
 void tool_perror LDAP_P((
+       char *func,
        int err,
        char *extra,
        char *matched,