1 /* dtest.c - lber decoding test program */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
8 * Copyright (c) 1990 Regents of the University of Michigan.
11 * Redistribution and use in source and binary forms are permitted
12 * provided that this notice is preserved and that due credit is given
13 * to the University of Michigan at Ann Arbor. The name of the University
14 * may not be used to endorse or promote products derived from this
15 * software without specific prior written permission. This software
16 * is provided ``as is'' without express or implied warranty.
23 #include <ac/stdlib.h>
24 #include <ac/string.h>
25 #include <ac/socket.h>
26 #include <ac/unistd.h>
34 static void usage( char *name )
36 fprintf( stderr, "usage: %s fmt\n", name );
40 main( int argc, char **argv )
51 /* enable debugging */
53 ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ival );
57 return( EXIT_FAILURE );
65 sb = ber_sockbuf_alloc_fd( fileno(stdin) );
67 if( (ber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
68 perror( "ber_alloc_t" );
69 return( EXIT_FAILURE );
72 if(( tag = ber_get_next( sb, &len, ber) ) == LBER_ERROR ) {
73 perror( "ber_get_next" );
74 return( EXIT_FAILURE );
77 printf("decode: message tag 0x%lx and length %ld\n",
78 (unsigned long) tag, (long) len );
80 for( s = argv[1]; *s; s++ ) {
86 printf("decode: format %s\n", fmt );
88 rc = ber_scanf( ber, fmt, &buf[0], &len );
90 if( rc == LBER_ERROR ) {
91 perror( "ber_scanf" );
92 return( EXIT_FAILURE );
96 ber_sockbuf_free( sb );
97 return( EXIT_SUCCESS );