X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/3b42d632cfa32d0fc6923eb8d782e25317992dce..ad7a38341c19e71e3595c17368ac18f08b71482d:/print-snmp.c diff --git a/print-snmp.c b/print-snmp.c index f88c5799..1fd34eab 100644 --- a/print-snmp.c +++ b/print-snmp.c @@ -58,7 +58,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.62 2005-01-05 04:05:04 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.64 2005-05-06 07:56:53 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -79,11 +79,13 @@ static const char rcsid[] _U_ = #undef OPAQUE /* defined in */ +static const char tstr[] = "[|snmp]"; + /* * Universal ASN.1 types * (we only care about the tag values for those allowed in the Internet SMI) */ -const char *Universal[] = { +static const char *Universal[] = { "U-0", "Boolean", "Integer", @@ -106,7 +108,7 @@ const char *Universal[] = { /* * Application-wide ASN.1 types from the Internet SMI and their tags */ -const char *Application[] = { +static const char *Application[] = { "IpAddress", #define IPADDR 0 "Counter", @@ -125,7 +127,7 @@ const char *Application[] = { /* * Context-specific ASN.1 types for the SNMP PDUs and their tags */ -const char *Context[] = { +static const char *Context[] = { "GetRequest", #define GETREQ 0 "GetNextRequest", @@ -155,7 +157,7 @@ const char *Context[] = { /* * Context-specific ASN.1 types for the SNMP Exceptions and their tags */ -const char *Exceptions[] = { +static const char *Exceptions[] = { "noSuchObject", #define NOSUCHOBJECT 0 "noSuchInstance", @@ -168,14 +170,14 @@ const char *Exceptions[] = { * Private ASN.1 types * The Internet SMI does not specify any */ -const char *Private[] = { +static const char *Private[] = { "P-0" }; /* * error-status values for any SNMP PDU */ -const char *ErrorStatus[] = { +static const char *ErrorStatus[] = { "noError", "tooBig", "noSuchName", @@ -204,7 +206,7 @@ const char *ErrorStatus[] = { /* * generic-trap values in the SNMP Trap-PDU */ -const char *GenericTrap[] = { +static const char *GenericTrap[] = { "coldStart", "warmStart", "linkDown", @@ -225,7 +227,7 @@ const char *GenericTrap[] = { * type definitions. */ #define defineCLASS(x) { "x", x, sizeof(x)/sizeof(x[0]) } /* not ANSI-C */ -struct { +static const struct { const char *name; const char **Id; int numIDs; @@ -245,7 +247,7 @@ struct { /* * defined forms for ASN.1 types */ -const char *Form[] = { +static const char *Form[] = { "Primitive", #define PRIMITIVE 0 "Constructed", @@ -278,7 +280,7 @@ struct obj { * Currently, this includes the prefixes for the Internet MIB, the * private enterprises tree, and the experimental tree. */ -struct obj_abrev { +static const struct obj_abrev { const char *prefix; /* prefix for this abrev */ struct obj *node; /* pointer into object table */ const char *oid; /* ASN.1 encoded OID */ @@ -360,7 +362,7 @@ struct be { /* * SNMP versions recognized by this module */ -const char *SnmpVersion[] = { +static const char *SnmpVersion[] = { "SNMPv1", #define SNMP_VERSION_1 0 "SNMPv2c", @@ -653,7 +655,7 @@ asn1_parse(register const u_char *p, u_int len, struct be *elem) return elem->asnlen + hdr; trunc: - fputs("[|snmp]", stdout); + printf("%s", tstr); return -1; } @@ -684,7 +686,7 @@ asn1_print(struct be *elem) int o = 0, first = -1, i = asnlen; if (!sflag && !nflag && asnlen > 2) { - struct obj_abrev *a = &obj_abrev_list[0]; + const struct obj_abrev *a = &obj_abrev_list[0]; size_t a_len = strlen(a->oid); for (; a->node; a++) { TCHECK2(*p, a_len); @@ -786,7 +788,10 @@ asn1_print(struct be *elem) p = elem->data.str; if (printable) { putchar('"'); - (void)fn_print(p, p + asnlen); + if (fn_printn(p, asnlen, snapend)) { + putchar('"'); + goto trunc; + } putchar('"'); } else for (i = asnlen; i-- > 0; p++) { @@ -831,7 +836,7 @@ asn1_print(struct be *elem) return 0; trunc: - fputs("[|snmp]", stdout); + printf("%s", tstr); return -1; } @@ -876,7 +881,7 @@ struct smi2be { int be; }; -static struct smi2be smi2betab[] = { +static const struct smi2be smi2betab[] = { { SMI_BASETYPE_INTEGER32, BE_INT }, { SMI_BASETYPE_OCTETSTRING, BE_STR }, { SMI_BASETYPE_OCTETSTRING, BE_INETADDR }, @@ -927,7 +932,7 @@ smi_decode_oid(struct be *elem, unsigned int *oid, return 0; trunc: - fputs("[|snmp]", stdout); + printf("%s", tstr); return -1; } @@ -1320,13 +1325,13 @@ snmppdu_print(u_short pduid, const u_char *np, u_int length) if ((pduid == GETREQ || pduid == GETNEXTREQ || pduid == SETREQ || pduid == INFORMREQ || pduid == V2TRAP || pduid == REPORT) && elem.data.integer != 0) { - char errbuf[10]; + char errbuf[20]; printf("[errorStatus(%s)!=0]", DECODE_ErrorStatus(elem.data.integer)); } else if (pduid == GETBULKREQ) { printf(" N=%d", elem.data.integer); } else if (elem.data.integer != 0) { - char errbuf[10]; + char errbuf[20]; printf(" %s", DECODE_ErrorStatus(elem.data.integer)); error = elem.data.integer; } @@ -1415,7 +1420,7 @@ trappdu_print(const u_char *np, u_int length) } generic = elem.data.integer; { - char buf[10]; + char buf[20]; printf(" %s", DECODE_GenericTrap(generic)); } length -= count;