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 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 #include <stdio.h>
30 #include <errno.h>
31 #include <string.h>
32 #include <stdarg.h>
33 #include <sys/types.h>
34 #include "snmp_msg.h"
35 #include "error.h"
36 #include "trace.h"
37
38
39 /***** GLOBAL VARIABLES *****/
40
41 int trace_level = 0;
42 uint32_t trace_flags = 0;
43
44
45 /***** STATIC VARIABLES *****/
46
47 static FILE *trace_stream = stdout;
48
49
50 /******************************************************************/
51
trace(char * format,...)52 void trace(char *format, ...)
53 {
54 va_list ap;
55
56 if(trace_stream == NULL)
57 {
58 return;
59 }
60
61 va_start(ap, format);
62 (void)vfprintf(trace_stream, format, ap);
63 va_end(ap);
64 }
65
66
67 /******************************************************************/
68
trace_set(int level,char * error_label)69 int trace_set(int level, char *error_label)
70 {
71 error_label[0] = '\0';
72
73 if(level < 0 || level > TRACE_LEVEL_MAX)
74 {
75 sprintf(error_label, ERR_MSG_BAD_TRACE_LEVEL,
76 level, TRACE_LEVEL_MAX);
77 return (-1);
78 }
79
80 trace_level = level;
81
82 if(trace_level > 0)
83 trace_flags = trace_flags | TRACE_TRAFFIC;
84 else
85 trace_flags = trace_flags & (~TRACE_TRAFFIC);
86
87 if(trace_level > 2)
88 trace_flags = trace_flags | TRACE_PDU;
89 else
90 trace_flags = trace_flags & (~TRACE_PDU);
91
92 if(trace_level > 3)
93 trace_flags = trace_flags | TRACE_PACKET;
94 else
95 trace_flags = trace_flags & (~TRACE_PACKET);
96
97 return (0);
98 }
99
100
101 /******************************************************************/
102
trace_reset()103 void trace_reset()
104 {
105 (void)trace_set(0, error_label);
106 }
107
108
109 /******************************************************************/
110
trace_increment()111 void trace_increment()
112 {
113 if(trace_level < TRACE_LEVEL_MAX)
114 (void)trace_set(trace_level + 1, error_label);
115
116 }
117
118
119 /******************************************************************/
120
trace_decrement()121 void trace_decrement()
122 {
123 if(trace_level > 0)
124 (void)trace_set(trace_level - 1, error_label);
125 }
126