openldap/libraries/liblber/dtest.c

74 lines
1.6 KiB
C
Raw Normal View History

1998-08-09 08:43:13 +08:00
/* dtest.c - lber decoding test program */
1998-12-29 04:38:04 +08:00
/*
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/* Portions
1998-08-09 08:43:13 +08:00
* Copyright (c) 1990 Regents of the University of Michigan.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of Michigan at Ann Arbor. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
*/
1998-10-25 09:41:42 +08:00
#include "portable.h"
1998-08-09 08:43:13 +08:00
#include <stdio.h>
#include <stdlib.h>
1998-10-25 09:41:42 +08:00
#include <ac/string.h>
#include <ac/socket.h>
#include <ac/unistd.h>
1998-10-25 09:41:42 +08:00
#ifdef HAVE_CONSOLE_H
1998-08-09 08:43:13 +08:00
#include <console.h>
#endif /* MACOS */
1998-10-25 09:41:42 +08:00
#include <lber.h>
1998-08-09 08:43:13 +08:00
1998-10-25 09:41:42 +08:00
static void usage( char *name )
1998-08-09 08:43:13 +08:00
{
fprintf( stderr, "usage: %s fmt\n", name );
}
int
1998-08-09 08:43:13 +08:00
main( int argc, char **argv )
{
1998-10-25 09:41:42 +08:00
long i;
1998-08-09 08:43:13 +08:00
unsigned long len;
int tag;
BerElement *ber;
Sockbuf *sb;
1998-08-09 08:43:13 +08:00
1998-10-25 09:41:42 +08:00
#ifdef HAVE_CONSOLE_H
1998-08-09 08:43:13 +08:00
ccommand( &argv );
cshow( stdout );
#endif /* MACOS */
sb = lber_pvt_sb_alloc_fd( fileno(stdin) );
1998-10-25 09:41:42 +08:00
if( (ber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
perror( "ber_alloc_t" );
exit( 1 );
}
if ( (tag = ber_get_next( sb, &len, ber )) == -1 ) {
1998-08-09 08:43:13 +08:00
perror( "ber_get_next" );
exit( 1 );
}
printf( "message has tag 0x%x and length %ld\n", tag, len );
if ( ber_scanf( ber, "i", &i ) == -1 ) {
1998-08-09 08:43:13 +08:00
fprintf( stderr, "ber_scanf returns -1\n" );
exit( 1 );
}
1998-11-23 09:46:32 +08:00
printf( "got int %ld\n", i );
1998-08-09 08:43:13 +08:00
lber_pvt_sb_free( sb );
1998-08-09 08:43:13 +08:00
return( 0 );
}