]>
The Tcpdump Group git mirrors - tcpdump/blob - print-snmp.c
2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by John Robert LoVerso.
11 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
12 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
13 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 * This implementation has been influenced by the CMU SNMP release,
16 * by Steve Waldbusser. However, this shares no code with that system.
17 * Additional ASN.1 insight gained from Marshall T. Rose's _The_Open_Book_.
18 * Earlier forms of this implementation were derived and/or inspired by an
19 * awk script originally written by C. Philip Wood of LANL (but later
20 * heavily modified by John Robert LoVerso). The copyright notice for
21 * that work is preserved below, even though it may not rightly apply
24 * This started out as a very simple program, but the incremental decoding
25 * (into the BE structure) complicated things.
27 # Los Alamos National Laboratory
29 # Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
30 # This software was produced under a U.S. Government contract
31 # (W-7405-ENG-36) by Los Alamos National Laboratory, which is
32 # operated by the University of California for the U.S. Department
33 # of Energy. The U.S. Government is licensed to use, reproduce,
34 # and distribute this software. Permission is granted to the
35 # public to copy and use this software without charge, provided
36 # that this Notice and any statement of authorship are reproduced
37 # on all copies. Neither the Government nor the University makes
38 # any warranty, express or implied, or assumes any liability or
39 # responsibility for the use of this software.
40 # @(#)snmp.awk.x 1.1 (LANL) 1/15/90
44 static const char rcsid
[] =
45 "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.34 1999-10-17 21:12:42 mcr Exp $ (LBL)";
48 #include <sys/param.h>
58 #include "interface.h"
59 #include "addrtoname.h"
62 * Universal ASN.1 types
63 * (we only care about the tag values for those allowed in the Internet SMI)
78 "U-8","U-9","U-10","U-11", /* 8-11 */
79 "U-12","U-13","U-14","U-15", /* 12-15 */
86 * Application-wide ASN.1 types from the Internet SMI and their tags
88 char *Application
[] = {
105 * Context-specific ASN.1 types for the SNMP PDUs and their tags
129 * Context-specific ASN.1 types for the SNMP Exceptions and their tags
131 char *Exceptions
[] = {
133 #define NOSUCHOBJECT 0
135 #define NOSUCHINSTANCE 1
137 #define ENDOFMIBVIEW 2
141 * Private ASN.1 types
142 * The Internet SMI does not specify any
149 * error-status values for any SNMP PDU
151 char *ErrorStatus
[] = {
165 "resourceUnavailable",
168 "authorizationError",
172 #define DECODE_ErrorStatus(e) \
173 ( e >= 0 && e < sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \
174 ? ErrorStatus[e] : (sprintf(errbuf, "err=%u", e), errbuf))
177 * generic-trap values in the SNMP Trap-PDU
179 char *GenericTrap
[] = {
184 "authenticationFailure",
187 #define GT_ENTERPRISE 7
189 #define DECODE_GenericTrap(t) \
190 ( t >= 0 && t < sizeof(GenericTrap)/sizeof(GenericTrap[0]) \
191 ? GenericTrap[t] : (sprintf(buf, "gt=%d", t), buf))
194 * ASN.1 type class table
195 * Ties together the preceding Universal, Application, Context, and Private
198 #define defineCLASS(x) { "x", x, sizeof(x)/sizeof(x[0]) } /* not ANSI-C */
204 defineCLASS(Universal
),
206 defineCLASS(Application
),
207 #define APPLICATION 1
208 defineCLASS(Context
),
210 defineCLASS(Private
),
212 defineCLASS(Exceptions
),
217 * defined forms for ASN.1 types
223 #define CONSTRUCTED 1
227 * A structure for the OID tree for the compiled-in MIB.
228 * This is stored as a general-order tree.
231 char *desc
; /* name of object */
232 u_char oid
; /* sub-id following parent */
233 u_char type
; /* object type (unused) */
234 struct obj
*child
, *next
; /* child and next sibling pointers */
238 * Include the compiled in SNMP MIB. "mib.h" is produced by feeding
239 * RFC-1156 format files into "makemib". "mib.h" MUST define at least
240 * a value for `mibroot'.
242 * In particular, this is gross, as this is including initialized structures,
243 * and by right shouldn't be an "include" file.
248 * This defines a list of OIDs which will be abbreviated on output.
249 * Currently, this includes the prefixes for the Internet MIB, the
250 * private enterprises tree, and the experimental tree.
253 char *prefix
; /* prefix for this abrev */
254 struct obj
*node
; /* pointer into object table */
255 char *oid
; /* ASN.1 encoded OID */
256 } obj_abrev_list
[] = {
258 /* .iso.org.dod.internet.mgmt.mib */
259 { "", &_mib_obj
, "\53\6\1\2\1" },
261 #ifndef NO_ABREV_ENTER
262 /* .iso.org.dod.internet.private.enterprises */
263 { "E:", &_enterprises_obj
, "\53\6\1\4\1" },
265 #ifndef NO_ABREV_EXPERI
266 /* .iso.org.dod.internet.experimental */
267 { "X:", &_experimental_obj
, "\53\6\1\3" },
273 * This is used in the OID print routine to walk down the object tree
274 * rooted at `mibroot'.
276 #define OBJ_PRINT(o, suppressdot) \
280 if ((o) == objp->oid) \
282 } while ((objp = objp->next) != NULL); \
285 printf(suppressdot?"%s":".%s", objp->desc); \
286 objp = objp->child; \
288 printf(suppressdot?"%u":".%u", (o)); \
292 * This is the definition for the Any-Data-Type storage used purely for
293 * temporary internal representation while decoding an ASN.1 data stream.
308 u_char form
, class; /* tag info */
319 #define BE_INETADDR 8
322 #define BE_NOSUCHOBJECT 128
323 #define BE_NOSUCHINST 129
324 #define BE_ENDOFMIBVIEW 130
328 * SNMP versions recognized by this module
330 char *SnmpVersion
[] = {
332 #define SNMP_VERSION_1 0
334 #define SNMP_VERSION_2 1
336 #define DECODE_SnmpVersion(v) \
337 ( v >= 0 && v < sizeof(SnmpVersion)/sizeof(SnmpVersion[0]) \
338 ? SnmpVersion[v] : (sprintf(versionbuf, "version=%u", v), versionbuf))
341 * Defaults for SNMP PDU components
343 #define DEF_COMMUNITY "public"
346 * constants for ASN.1 decoding
349 #define ASNLEN_INETADDR 4
352 #define ASN_BIT8 0x80
353 #define ASN_LONGLEN 0x80
355 #define ASN_ID_BITS 0x1f
356 #define ASN_FORM_BITS 0x20
357 #define ASN_FORM_SHIFT 5
358 #define ASN_CLASS_BITS 0xc0
359 #define ASN_CLASS_SHIFT 6
361 #define ASN_ID_EXT 0x1f /* extension ID in tag field */
364 * truncated==1 means the packet was complete, but we don't have all of
367 static int truncated
;
368 #define ifNotTruncated if (truncated) fputs("[|snmp]", stdout); else
371 * This decodes the next ASN.1 object in the stream pointed to by "p"
372 * (and of real-length "len") and stores the intermediate data in the
373 * provided BE object.
375 * This returns -l if it fails (i.e., the ASN.1 stream is not valid).
376 * O/w, this returns the number of bytes parsed from "p".
379 asn1_parse(register const u_char
*p
, u_int len
, struct be
*elem
)
381 u_char form
, class, id
;
387 ifNotTruncated
puts("[nothing to parse], stdout");
392 * it would be nice to use a bit field, but you can't depend on them.
393 * +---+---+---+---+---+---+---+---+
395 * +---+---+---+---+---+---+---+---+
398 id
= *p
& ASN_ID_BITS
; /* lower 5 bits, range 00-1f */
400 form
= (*p
& 0xe0) >> 5; /* move upper 3 bits to lower 3 */
401 class = form
>> 1; /* bits 7&6 -> bits 1&0, range 0-3 */
402 form
&= 0x1; /* bit 5 -> bit 0, range 0-1 */
404 form
= (u_char
)(*p
& ASN_FORM_BITS
) >> ASN_FORM_SHIFT
;
405 class = (u_char
)(*p
& ASN_CLASS_BITS
) >> ASN_CLASS_SHIFT
;
413 /* extended tag field */
414 if (id
== ASN_ID_EXT
) {
415 for (id
= 0; *p
& ASN_BIT8
&& len
> 0; len
--, hdr
++, p
++) {
418 id
= (id
<< 7) | (*p
& ~ASN_BIT8
);
420 if (len
== 0 && *p
& ASN_BIT8
) {
421 ifNotTruncated
fputs("[Xtagfield?]", stdout
);
424 elem
->id
= id
= (id
<< 7) | *p
;
430 ifNotTruncated
fputs("[no asnlen]", stdout
);
437 if (elem
->asnlen
& ASN_BIT8
) {
438 int noct
= elem
->asnlen
% ASN_BIT8
;
441 ifNotTruncated
printf("[asnlen? %d<%d]", len
, noct
);
444 for (; noct
-- > 0; len
--, hdr
++) {
447 elem
->asnlen
= (elem
->asnlen
<< ASN_SHIFT8
) | *p
++;
450 if (len
< elem
->asnlen
) {
452 printf("[len%d<asnlen%u]", len
, elem
->asnlen
);
455 /* maybe should check at least 4? */
458 if (form
>= sizeof(Form
)/sizeof(Form
[0])) {
459 ifNotTruncated
printf("[form?%d]", form
);
462 if (class >= sizeof(Class
)/sizeof(Class
[0])) {
463 ifNotTruncated
printf("[class?%c/%d]", *Form
[form
], class);
466 if ((int)id
>= Class
[class].numIDs
) {
467 ifNotTruncated
printf("[id?%c/%s/%d]", *Form
[form
],
468 Class
[class].name
, id
);
483 register int32_t data
;
487 if (*p
& ASN_BIT8
) /* negative */
489 for (i
= elem
->asnlen
; i
-- > 0; p
++)
490 data
= (data
<< ASN_SHIFT8
) | *p
;
491 elem
->data
.integer
= data
;
497 elem
->data
.raw
= (caddr_t
)p
;
501 elem
->type
= BE_NULL
;
502 elem
->data
.raw
= NULL
;
506 elem
->type
= BE_OCTET
;
507 elem
->data
.raw
= (caddr_t
)p
;
509 Class
[class].Id
[id
]);
517 elem
->type
= BE_INETADDR
;
518 elem
->data
.raw
= (caddr_t
)p
;
524 register u_int32_t data
;
527 for (i
= elem
->asnlen
; i
-- > 0; p
++)
528 data
= (data
<< 8) + *p
;
529 elem
->data
.uns
= data
;
534 register u_int32_t high
, low
;
535 elem
->type
= BE_UNS64
;
537 for (i
= elem
->asnlen
; i
-- > 0; p
++) {
539 ((low
& 0xFF000000) >> 24);
540 low
= (low
<< 8) | *p
;
542 elem
->data
.uns64
.high
= high
;
543 elem
->data
.uns64
.low
= low
;
548 elem
->type
= BE_OCTET
;
549 elem
->data
.raw
= (caddr_t
)p
;
551 Class
[class].Id
[id
]);
559 elem
->type
= BE_NOSUCHOBJECT
;
560 elem
->data
.raw
= NULL
;
564 elem
->type
= BE_NOSUCHINST
;
565 elem
->data
.raw
= NULL
;
569 elem
->type
= BE_ENDOFMIBVIEW
;
570 elem
->data
.raw
= NULL
;
576 elem
->type
= BE_OCTET
;
577 elem
->data
.raw
= (caddr_t
)p
;
579 Class
[class].name
, Class
[class].Id
[id
]);
590 elem
->data
.raw
= (caddr_t
)p
;
594 elem
->type
= BE_OCTET
;
595 elem
->data
.raw
= (caddr_t
)p
;
596 printf("C/U/%s", Class
[class].Id
[id
]);
603 elem
->data
.raw
= (caddr_t
)p
;
607 elem
->type
= BE_OCTET
;
608 elem
->data
.raw
= (caddr_t
)p
;
610 Class
[class].name
, Class
[class].Id
[id
]);
617 return elem
->asnlen
+ hdr
;
621 * Display the ASN.1 object represented by the BE object.
622 * This used to be an integral part of asn1_parse() before the intermediate
626 asn1_print(struct be
*elem
)
628 u_char
*p
= (u_char
*)elem
->data
.raw
;
629 u_int32_t asnlen
= elem
->asnlen
;
632 switch (elem
->type
) {
635 for (i
= asnlen
; i
-- > 0; p
++);
643 int o
= 0, first
= -1, i
= asnlen
;
645 if (!nflag
&& asnlen
> 2) {
646 struct obj_abrev
*a
= &obj_abrev_list
[0];
647 for (; a
->node
; a
++) {
648 if (!memcmp(a
->oid
, (char *)p
,
650 objp
= a
->node
->child
;
653 fputs(a
->prefix
, stdout
);
659 for (; i
-- > 0; p
++) {
660 o
= (o
<< ASN_SHIFT7
) + (*p
& ~ASN_BIT8
);
661 if (*p
& ASN_LONGLEN
)
665 * first subitem encodes two items with 1st*OIDMUX+2nd
671 OBJ_PRINT(o
/OIDMUX
, first
);
683 printf("%d", elem
->data
.integer
);
687 printf("%d", elem
->data
.uns
);
690 case BE_UNS64
: { /* idea borrowed from by Marshall Rose */
693 char *cpf
, *cpl
, last
[6], first
[30];
694 if (elem
->data
.uns64
.high
== 0) {
695 printf("%u", elem
->data
.uns64
.low
);
698 d
= elem
->data
.uns64
.high
* 4294967296.0; /* 2^32 */
699 if (elem
->data
.uns64
.high
<= 0x1fffff) {
700 d
+= elem
->data
.uns64
.low
;
704 d
+= (elem
->data
.uns64
.low
& 0xfffff000);
705 sprintf(first
, "%.f", d
);
706 sprintf(last
, "%5.5d", elem
->data
.uns64
.low
& 0xfff);
707 for (carry
= 0, cpf
= first
+strlen(first
)-1, cpl
= last
+4;
710 j
= carry
+ (*cpf
- '0') + (*cpl
- '0');
719 fputs(first
, stdout
);
724 register int printable
= 1, first
= 1;
725 const u_char
*p
= elem
->data
.str
;
726 for (i
= asnlen
; printable
&& i
-- > 0; p
++)
727 printable
= isprint(*p
) || isspace(*p
);
731 (void)fn_print(p
, p
+ asnlen
);
734 for (i
= asnlen
; i
-- > 0; p
++) {
735 printf(first
? "%.2x" : "_%.2x", *p
);
742 printf("Seq(%u)", elem
->asnlen
);
747 if (asnlen
!= ASNLEN_INETADDR
)
748 printf("[inetaddr len!=%d]", ASNLEN_INETADDR
);
750 for (i
= asnlen
; i
-- > 0; p
++) {
751 printf("%c%u", sep
, *p
);
758 case BE_NOSUCHOBJECT
:
760 case BE_ENDOFMIBVIEW
:
761 printf("[%s]", Class
[EXCEPTIONS
].Id
[elem
->id
]);
766 Class
[CONTEXT
].Id
[elem
->id
], elem
->asnlen
);
770 fputs("[BE_ANY!?]", stdout
);
774 fputs("[be!?]", stdout
);
781 * This is a brute force ASN.1 printer: recurses to dump an entire structure.
782 * This will work for any ASN.1 stream, not just an SNMP PDU.
784 * By adding newlines and spaces at the correct places, this would print in
787 * This is not currently used.
790 asn1_decode(u_char
*p
, u_int length
)
795 while (i
>= 0 && length
> 0) {
796 i
= asn1_parse(p
, length
, &elem
);
800 if (elem
.type
== BE_SEQ
|| elem
.type
== BE_PDU
) {
802 asn1_decode(elem
.data
.raw
, elem
.asnlen
);
813 * General SNMP header
815 * version INTEGER {version-1(0)},
816 * community OCTET STRING,
819 * PDUs for all but Trap: (see rfc1157 from page 15 on)
821 * request-id INTEGER,
822 * error-status INTEGER,
823 * error-index INTEGER,
824 * varbindlist SEQUENCE OF
832 * enterprise OBJECT IDENTIFIER,
833 * agent-addr NetworkAddress,
834 * generic-trap INTEGER,
835 * specific-trap INTEGER,
836 * time-stamp TimeTicks,
837 * varbindlist SEQUENCE OF
846 * Decode SNMP varBind
849 varbind_print(u_char pduid
, const u_char
*np
, u_int length
, int error
)
854 /* Sequence of varBind */
855 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
857 if (elem
.type
!= BE_SEQ
) {
858 fputs("[!SEQ of varbind]", stdout
);
863 printf("[%d extra after SEQ of varbind]", length
- count
);
865 length
= elem
.asnlen
;
866 np
= (u_char
*)elem
.data
.raw
;
868 for (ind
= 1; length
> 0; ind
++) {
872 if (!error
|| ind
== error
)
876 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
878 if (elem
.type
!= BE_SEQ
) {
879 fputs("[!varbind]", stdout
);
884 vblength
= length
- count
;
886 length
= elem
.asnlen
;
887 np
= (u_char
*)elem
.data
.raw
;
890 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
892 if (elem
.type
!= BE_OID
) {
893 fputs("[objName!=OID]", stdout
);
897 if (!error
|| ind
== error
)
902 if (pduid
!= GETREQ
&& pduid
!= GETNEXTREQ
903 && pduid
!= GETBULKREQ
&& !error
)
907 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
909 if (pduid
== GETREQ
|| pduid
== GETNEXTREQ
910 || pduid
== GETBULKREQ
) {
911 if (elem
.type
!= BE_NULL
) {
912 fputs("[objVal!=NULL]", stdout
);
916 if (error
&& ind
== error
&& elem
.type
!= BE_NULL
)
917 fputs("[err objVal!=NULL]", stdout
);
918 if (!error
|| ind
== error
)
927 * Decode SNMP PDUs: GetRequest, GetNextRequest, GetResponse, SetRequest,
928 * GetBulk, Inform, V2Trap, and Report
931 snmppdu_print(u_char pduid
, const u_char
*np
, u_int length
)
934 int count
= 0, error
;
936 /* reqId (Integer) */
937 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
939 if (elem
.type
!= BE_INT
) {
940 fputs("[reqId!=INT]", stdout
);
944 /* ignore the reqId */
948 /* errorStatus (Integer) */
949 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
951 if (elem
.type
!= BE_INT
) {
952 fputs("[errorStatus!=INT]", stdout
);
957 if ((pduid
== GETREQ
|| pduid
== GETNEXTREQ
|| pduid
== SETREQ
958 || pduid
== INFORMREQ
|| pduid
== V2TRAP
|| pduid
== REPORT
)
959 && elem
.data
.integer
!= 0) {
961 printf("[errorStatus(%s)!=0]",
962 DECODE_ErrorStatus(elem
.data
.integer
));
963 } else if (pduid
== GETBULKREQ
) {
964 printf(" N=%d", elem
.data
.integer
);
965 } else if (elem
.data
.integer
!= 0) {
967 printf(" %s", DECODE_ErrorStatus(elem
.data
.integer
));
968 error
= elem
.data
.integer
;
973 /* errorIndex (Integer) */
974 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
976 if (elem
.type
!= BE_INT
) {
977 fputs("[errorIndex!=INT]", stdout
);
981 if ((pduid
== GETREQ
|| pduid
== GETNEXTREQ
|| pduid
== SETREQ
982 || pduid
== INFORMREQ
|| pduid
== V2TRAP
|| pduid
== REPORT
)
983 && elem
.data
.integer
!= 0)
984 printf("[errorIndex(%d)!=0]", elem
.data
.integer
);
985 else if (pduid
== GETBULKREQ
)
986 printf(" M=%d", elem
.data
.integer
);
987 else if (elem
.data
.integer
!= 0) {
989 printf("[errorIndex(%d) w/o errorStatus]",
992 printf("@%d", elem
.data
.integer
);
993 error
= elem
.data
.integer
;
996 fputs("[errorIndex==0]", stdout
);
1002 varbind_print(pduid
, np
, length
, error
);
1007 * Decode SNMP Trap PDU
1010 trap_print(const u_char
*np
, u_int length
)
1013 int count
= 0, generic
;
1017 /* enterprise (oid) */
1018 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
1020 if (elem
.type
!= BE_OID
) {
1021 fputs("[enterprise!=OID]", stdout
);
1031 /* agent-addr (inetaddr) */
1032 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
1034 if (elem
.type
!= BE_INETADDR
) {
1035 fputs("[agent-addr!=INETADDR]", stdout
);
1043 /* generic-trap (Integer) */
1044 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
1046 if (elem
.type
!= BE_INT
) {
1047 fputs("[generic-trap!=INT]", stdout
);
1051 generic
= elem
.data
.integer
;
1054 printf(" %s", DECODE_GenericTrap(generic
));
1059 /* specific-trap (Integer) */
1060 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
1062 if (elem
.type
!= BE_INT
) {
1063 fputs("[specific-trap!=INT]", stdout
);
1067 if (generic
!= GT_ENTERPRISE
) {
1068 if (elem
.data
.integer
!= 0)
1069 printf("[specific-trap(%d)!=0]", elem
.data
.integer
);
1071 printf(" s=%d", elem
.data
.integer
);
1077 /* time-stamp (TimeTicks) */
1078 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
1080 if (elem
.type
!= BE_UNS
) { /* XXX */
1081 fputs("[time-stamp!=TIMETICKS]", stdout
);
1089 varbind_print (TRAP
, np
, length
, 0);
1094 * Decode SNMP header and pass on to PDU printing routines
1097 snmp_print(const u_char
*np
, u_int length
)
1099 struct be elem
, pdu
;
1105 /* truncated packet? */
1106 if (np
+ length
> snapend
) {
1108 length
= snapend
- np
;
1113 /* initial Sequence */
1114 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
1116 if (elem
.type
!= BE_SEQ
) {
1117 fputs("[!init SEQ]", stdout
);
1122 printf("[%d extra after iSEQ]", length
- count
);
1124 length
= elem
.asnlen
;
1125 np
= (u_char
*)elem
.data
.raw
;
1126 /* Version (Integer) */
1127 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
1129 if (elem
.type
!= BE_INT
) {
1130 fputs("[version!=INT]", stdout
);
1134 /* only handle version==0 || version==1 */
1135 switch (elem
.data
.integer
) {
1136 case SNMP_VERSION_1
:
1137 case SNMP_VERSION_2
: {
1138 char versionbuf
[10];
1140 printf("%s ", DECODE_SnmpVersion(elem
.data
.integer
));
1144 char versionbuf
[10];
1145 printf("[%s]", DECODE_SnmpVersion(elem
.data
.integer
));
1149 version
= elem
.data
.integer
;
1153 /* Community (String) */
1154 if ((count
= asn1_parse(np
, length
, &elem
)) < 0)
1156 if (elem
.type
!= BE_STR
) {
1157 fputs("[comm!=STR]", stdout
);
1161 /* default community */
1162 if (strncmp((char *)elem
.data
.str
, DEF_COMMUNITY
,
1163 sizeof(DEF_COMMUNITY
) - 1))
1165 printf("C=%.*s ", (int)elem
.asnlen
, elem
.data
.str
);
1170 if ((count
= asn1_parse(np
, length
, &pdu
)) < 0)
1172 if (pdu
.type
!= BE_PDU
) {
1173 fputs("[no PDU]", stdout
);
1177 printf("[%d extra after PDU]", length
- count
);
1179 /* descend into PDU */
1180 length
= pdu
.asnlen
;
1181 np
= (u_char
*)pdu
.data
.raw
;
1183 if (version
== SNMP_VERSION_1
&&
1184 (pdu
.id
== GETBULKREQ
|| pdu
.id
== INFORMREQ
||
1185 pdu
.id
== V2TRAP
|| pdu
.id
== REPORT
)) {
1186 printf("[v2 PDU in v1 message]");
1190 if (version
== SNMP_VERSION_2
&& pdu
.id
== TRAP
) {
1191 printf("[v1 PDU in v2 message]");
1197 trap_print(np
, length
);
1207 snmppdu_print(pdu
.id
, np
, length
);