]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-snmp.c
NDOize OpenFlow, IEEE slow and telnet decoders
[tcpdump] / print-snmp.c
index bab18da75c7c7b95dc4d9d5d97681c6b536a6f1b..6f57c2f1e05ef2e807a7d9e0bc6c51e63c03aca2 100644 (file)
  #     @(#)snmp.awk.x  1.1 (LANL) 1/15/90
  */
 
-#ifndef lint
-static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.61 2004-12-27 22:14:12 guy Exp $ (LBL)";
-#endif
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -75,15 +70,16 @@ static const char rcsid[] _U_ =
 #endif
 
 #include "interface.h"
-#include "addrtoname.h"
 
 #undef OPAQUE  /* defined in <wingdi.h> */
 
+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 +102,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 +121,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 +151,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 +164,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 +200,7 @@ const char *ErrorStatus[] = {
 /*
  * generic-trap values in the SNMP Trap-PDU
  */
-const char *GenericTrap[] = {
+static const char *GenericTrap[] = {
        "coldStart",
        "warmStart",
        "linkDown",
@@ -225,7 +221,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 +241,7 @@ struct {
 /*
  * defined forms for ASN.1 types
  */
-const char *Form[] = {
+static const char *Form[] = {
        "Primitive",
 #define PRIMITIVE      0
        "Constructed",
@@ -278,7 +274,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 +356,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 +649,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 +680,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);
@@ -782,11 +778,14 @@ asn1_print(struct be *elem)
                const u_char *p = elem->data.str;
                TCHECK2(*p, asnlen);
                for (i = asnlen; printable && i-- > 0; p++)
-                       printable = isprint(*p) || isspace(*p);
+                       printable = ND_ISPRINT(*p);
                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 +830,7 @@ asn1_print(struct be *elem)
        return 0;
 
 trunc:
-       fputs("[|snmp]", stdout);
+       printf("%s", tstr);
        return -1;
 }
 
@@ -876,7 +875,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 +926,7 @@ smi_decode_oid(struct be *elem, unsigned int *oid,
        return 0;
 
 trunc:
-       fputs("[|snmp]", stdout);
+       printf("%s", tstr);
        return -1;
 }
 
@@ -1025,7 +1024,7 @@ static SmiNode *smi_print_variable(struct be *elem, int *status)
 {
        unsigned int oid[128], oidlen;
        SmiNode *smiNode = NULL;
-       int i;
+       unsigned int i;
 
        *status = smi_decode_oid(elem, oid, sizeof(oid)/sizeof(unsigned int),
            &oidlen);
@@ -1053,10 +1052,10 @@ static SmiNode *smi_print_variable(struct be *elem, int *status)
 static int
 smi_print_value(SmiNode *smiNode, u_char pduid, struct be *elem)
 {
-       unsigned int oid[128], oidlen;
+       unsigned int i, oid[128], oidlen;
        SmiType *smiType;
        SmiNamedNumber *nn;
-       int i, done = 0;
+       int done = 0;
 
        if (! smiNode || ! (smiNode->nodekind
                            & (SMI_NODEKIND_SCALAR | SMI_NODEKIND_COLUMN))) {
@@ -1290,7 +1289,7 @@ varbind_print(u_char pduid, const u_char *np, u_int length)
  * GetBulk, Inform, V2Trap, and Report
  */
 static void
-snmppdu_print(u_char pduid, const u_char *np, u_int length)
+snmppdu_print(u_short pduid, const u_char *np, u_int length)
 {
        struct be elem;
        int count = 0, error;
@@ -1320,13 +1319,13 @@ snmppdu_print(u_char 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 +1414,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;