1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22/* 23 * Copyright 1996 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26#pragma ident "%Z%%M% %I% %E% SMI" 27 28#include <stdio.h> 29#include <sys/types.h> 30#include <netinet/in.h> 31 32#include "asn1.h" 33#include "error.h" 34#include "pdu.h" 35 36 37#define BUFFER_SZ 10 38 39static u_char static_buffer[] = { 0x41, 0x03, 0xF5, 0x1E, 0x5C }; 40 41static void second_test(long value, u_char asn_type); 42static void third_test(); 43 44 45main() 46{ 47 u_char *p; 48 int len; 49 long integer = 0; 50 u_char type = 0; 51 52 53 /* 1st test */ 54 55 len = sizeof(static_buffer); 56 integer = 0; 57 type = 0; 58 p = asn_parse_int(static_buffer, &len, &type, &integer, sizeof(long), error_label); 59 if(p == NULL) 60 { 61 fprintf(stderr, "asn_parse_int() failed: %s\n", error_label); 62 exit(1); 63 } 64 printf("type: 0x%x\n", type); 65 printf("integer: %ld\n", integer); 66 printf("\n"); 67 68 69 /* 2nd test */ 70 71 second_test(0xFF, COUNTER); 72 second_test(-0xFF, COUNTER); 73 74 second_test(0xFFFF, COUNTER); 75 second_test(-0xFFFF, COUNTER); 76 77 second_test(0xFFFFFF, COUNTER); 78 second_test(-0xFFFFFF, COUNTER); 79 80 second_test(16523569, COUNTER); 81 second_test(-1363058786, COUNTER); 82 83 84 /* 3rd test */ 85 86 third_test(); 87 88 89 exit(0); 90 91} 92 93 94static void second_test(long value, u_char asn_type) 95{ 96 u_char *p; 97 int len; 98 long integer = 0; 99 u_char type = 0; 100 u_char buffer[BUFFER_SZ]; 101 int i; 102 103 104 printf("VALUE: %ld - TYPE: 0x%x\n\n", value, asn_type); 105 106 integer = value; 107 type = asn_type; 108 memset(buffer, 0, sizeof(buffer)); 109 len = BUFFER_SZ; 110 p = asn_build_int(buffer, &len, type, &integer, sizeof(long), error_label); 111 if(p == NULL) 112 { 113 fprintf(stderr, "asn_build_int() failed: %s\n", error_label); 114 exit(1); 115 } 116 printf("len: %d\n", len); 117 printf("buffer: "); 118 for(i = 0; i < BUFFER_SZ; i++) 119 { 120 printf(" %02x", buffer[i]); 121 } 122 printf("\n"); 123 124 integer = 0; 125 type = 0; 126 len = BUFFER_SZ; 127 p = asn_parse_int(buffer, &len, &type, &integer, sizeof(long), error_label); 128 if(p == NULL) 129 { 130 fprintf(stderr, "asn_parse_int() failed: %s\n", error_label); 131 exit(1); 132 } 133 printf("type: 0x%x\n", type); 134 printf("integer: %ld\n", integer); 135 printf("\n"); 136} 137 138 139static void third_test() 140{ 141 SNMP_pdu *pdu; 142 143 pdu = snmp_pdu_new(error_label); 144} 145