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
|
|
|
|
*/
|
1998-12-29 04:46:13 +08:00
|
|
|
/* 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>
|
1998-11-16 13:07:27 +08:00
|
|
|
#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
|
|
|
|
1998-12-22 09:34:01 +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 );
|
|
|
|
}
|
|
|
|
|
1998-11-08 10:31:31 +08:00
|
|
|
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;
|
1998-12-22 09:34:01 +08:00
|
|
|
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 */
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
sb = lber_sockbuf_alloc_fd( fileno(stdin) );
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-12-22 09:34:01 +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 );
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
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
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
lber_sockbuf_free( sb );
|
1998-08-09 08:43:13 +08:00
|
|
|
return( 0 );
|
|
|
|
}
|