1 /* dtest.c - lber decoding test program */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
17 * All rights reserved.
19 * Redistribution and use in source and binary forms are permitted
20 * provided that this notice is preserved and that due credit is given
21 * to the University of Michigan at Ann Arbor. The name of the University
22 * may not be used to endorse or promote products derived from this
23 * software without specific prior written permission. This software
24 * is provided ``as is'' without express or implied warranty.
27 * This work was originally developed by the University of Michigan
28 * (as part of U-MICH LDAP).
35 #include <ac/stdlib.h>
36 #include <ac/string.h>
37 #include <ac/socket.h>
38 #include <ac/unistd.h>
47 static void usage( const char *name )
49 fprintf( stderr, "usage: %s fmt\n", name );
53 main( int argc, char **argv )
64 /* enable debugging */
66 ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ival );
70 return( EXIT_FAILURE );
78 sb = ber_sockbuf_alloc();
80 ber_sockbuf_add_io( sb, &ber_sockbuf_io_fd, LBER_SBIOD_LEVEL_PROVIDER,
83 ber = ber_alloc_t(LBER_USE_DER);
85 perror( "ber_alloc_t" );
86 return( EXIT_FAILURE );
90 tag = ber_get_next( sb, &len, ber);
91 if( tag != LBER_ERROR ) break;
93 if( errno == EWOULDBLOCK ) continue;
94 if( errno == EAGAIN ) continue;
96 perror( "ber_get_next" );
97 return( EXIT_FAILURE );
100 printf("decode: message tag 0x%lx and length %ld\n",
101 (unsigned long) tag, (long) len );
103 for( s = argv[1]; *s; s++ ) {
109 printf("decode: format %s\n", fmt );
111 tag = ber_scanf( ber, fmt, &buf[0], &len );
113 if( tag == LBER_ERROR ) {
114 perror( "ber_scanf" );
115 return( EXIT_FAILURE );
119 ber_sockbuf_free( sb );
120 return( EXIT_SUCCESS );