]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-snmp.c
Fix a bunch of de-constifications.
[tcpdump] / print-snmp.c
index 3b14f9ec27a62eee0b12f93c377e05f1dab75b3f..b9372644a99f394754c101aad9081eefc5a9b65f 100644 (file)
@@ -56,7 +56,6 @@
  #     @(#)snmp.awk.x  1.1 (LANL) 1/15/90
  */
 
-#define NETDISSECT_REWORKED
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -66,7 +65,7 @@
 #include <stdio.h>
 #include <string.h>
 
-#ifdef HAVE_SMI_H
+#ifdef USE_LIBSMI
 #include <smi.h>
 #endif
 
@@ -323,15 +322,15 @@ static const struct obj_abrev {
  * temporary internal representation while decoding an ASN.1 data stream.
  */
 struct be {
-       u_int32_t asnlen;
+       uint32_t asnlen;
        union {
-               caddr_t raw;
+               const uint8_t *raw;
                int32_t integer;
-               u_int32_t uns;
+               uint32_t uns;
                const u_char *str;
                struct {
-                       u_int32_t high;
-                       u_int32_t low;
+                       uint32_t high;
+                       uint32_t low;
                } uns64;
        } data;
        u_short id;
@@ -472,7 +471,7 @@ asn1_parse(netdissect_options *ndo,
        elem->asnlen = *p;
        p++; len--; hdr++;
        if (elem->asnlen & ASN_BIT8) {
-               u_int32_t noct = elem->asnlen % ASN_BIT8;
+               uint32_t noct = elem->asnlen % ASN_BIT8;
                elem->asnlen = 0;
                if (len < noct) {
                        ND_PRINT((ndo, "[asnlen? %d<%d]", len, noct));
@@ -525,7 +524,7 @@ asn1_parse(netdissect_options *ndo,
 
                        case OBJECTID:
                                elem->type = BE_OID;
-                               elem->data.raw = (caddr_t)p;
+                               elem->data.raw = (const uint8_t *)p;
                                break;
 
                        case ASN_NULL:
@@ -535,7 +534,7 @@ asn1_parse(netdissect_options *ndo,
 
                        default:
                                elem->type = BE_OCTET;
-                               elem->data.raw = (caddr_t)p;
+                               elem->data.raw = (const uint8_t *)p;
                                ND_PRINT((ndo, "[P/U/%s]", Class[class].Id[id]));
                                break;
                        }
@@ -545,13 +544,13 @@ asn1_parse(netdissect_options *ndo,
                        switch (id) {
                        case IPADDR:
                                elem->type = BE_INETADDR;
-                               elem->data.raw = (caddr_t)p;
+                               elem->data.raw = (const uint8_t *)p;
                                break;
 
                        case COUNTER:
                        case GAUGE:
                        case TIMETICKS: {
-                               register u_int32_t data;
+                               register uint32_t data;
                                ND_TCHECK2(*p, elem->asnlen);
                                elem->type = BE_UNS;
                                data = 0;
@@ -562,7 +561,7 @@ asn1_parse(netdissect_options *ndo,
                        }
 
                        case COUNTER64: {
-                               register u_int32_t high, low;
+                               register uint32_t high, low;
                                ND_TCHECK2(*p, elem->asnlen);
                                elem->type = BE_UNS64;
                                high = 0, low = 0;
@@ -578,7 +577,7 @@ asn1_parse(netdissect_options *ndo,
 
                        default:
                                elem->type = BE_OCTET;
-                               elem->data.raw = (caddr_t)p;
+                               elem->data.raw = (const uint8_t *)p;
                                ND_PRINT((ndo, "[P/A/%s]",
                                        Class[class].Id[id]));
                                break;
@@ -608,7 +607,7 @@ asn1_parse(netdissect_options *ndo,
                        ND_PRINT((ndo, "[P/%s/%s]", Class[class].name, Class[class].Id[id]));
                        ND_TCHECK2(*p, elem->asnlen);
                        elem->type = BE_OCTET;
-                       elem->data.raw = (caddr_t)p;
+                       elem->data.raw = (const uint8_t *)p;
                        break;
                }
                break;
@@ -619,12 +618,12 @@ asn1_parse(netdissect_options *ndo,
                        switch (id) {
                        case SEQUENCE:
                                elem->type = BE_SEQ;
-                               elem->data.raw = (caddr_t)p;
+                               elem->data.raw = (const uint8_t *)p;
                                break;
 
                        default:
                                elem->type = BE_OCTET;
-                               elem->data.raw = (caddr_t)p;
+                               elem->data.raw = (const uint8_t *)p;
                                ND_PRINT((ndo, "C/U/%s", Class[class].Id[id]));
                                break;
                        }
@@ -632,12 +631,12 @@ asn1_parse(netdissect_options *ndo,
 
                case CONTEXT:
                        elem->type = BE_PDU;
-                       elem->data.raw = (caddr_t)p;
+                       elem->data.raw = (const uint8_t *)p;
                        break;
 
                default:
                        elem->type = BE_OCTET;
-                       elem->data.raw = (caddr_t)p;
+                       elem->data.raw = (const uint8_t *)p;
                        ND_PRINT((ndo, "C/%s/%s", Class[class].name, Class[class].Id[id]));
                        break;
                }
@@ -661,9 +660,9 @@ static int
 asn1_print(netdissect_options *ndo,
            struct be *elem)
 {
-       u_char *p = (u_char *)elem->data.raw;
-       u_int32_t asnlen = elem->asnlen;
-       u_int32_t i;
+       const u_char *p = (const u_char *)elem->data.raw;
+       uint32_t asnlen = elem->asnlen;
+       uint32_t i;
 
        switch (elem->type) {
 
@@ -684,7 +683,7 @@ asn1_print(netdissect_options *ndo,
                        size_t a_len = strlen(a->oid);
                        for (; a->node; a++) {
                                ND_TCHECK2(*p, a_len);
-                               if (memcmp(a->oid, (char *)p, a_len) == 0) {
+                               if (memcmp(a->oid, p, a_len) == 0) {
                                        objp = a->node->child;
                                        i -= strlen(a->oid);
                                        p += strlen(a->oid);
@@ -782,7 +781,7 @@ asn1_print(netdissect_options *ndo,
                p = elem->data.str;
                if (printable) {
                        ND_PRINT((ndo, "\""));
-                       if (fn_printn(p, asnlen, ndo->ndo_snapend)) {
+                       if (fn_printn(ndo, p, asnlen, ndo->ndo_snapend)) {
                                ND_PRINT((ndo, "\""));
                                goto trunc;
                        }
@@ -867,7 +866,7 @@ asn1_decode(u_char *p, u_int length)
 }
 #endif
 
-#ifdef LIBSMI
+#ifdef USE_LIBSMI
 
 struct smi2be {
     SmiBasetype basetype;
@@ -895,9 +894,10 @@ smi_decode_oid(netdissect_options *ndo,
                struct be *elem, unsigned int *oid,
                unsigned int oidsize, unsigned int *oidlen)
 {
-       u_char *p = (u_char *)elem->data.raw;
-       u_int32_t asnlen = elem->asnlen;
+       const u_char *p = (const u_char *)elem->data.raw;
+       uint32_t asnlen = elem->asnlen;
        int o = 0, first = -1, i = asnlen;
+       unsigned int firstval;
 
        for (*oidlen = 0; ndo->ndo_sflag && i-- > 0; p++) {
                ND_TCHECK(*p);
@@ -911,12 +911,12 @@ smi_decode_oid(netdissect_options *ndo,
                 */
                if (first < 0) {
                        first = 0;
+                       firstval = o / OIDMUX;
+                       if (firstval > 2) firstval = 2;
+                       o -= firstval * OIDMUX;
                        if (*oidlen < oidsize) {
-                           oid[*oidlen] = o / OIDMUX;
-                           if (oid[*oidlen] > 2) oid[*oidlen] = 2;
+                           oid[(*oidlen)++] = firstval;
                        }
-                       o -= oid[*oidlen] * OIDMUX;
-                       if (*oidlen < oidsize) (*oidlen)++;
                }
                if (*oidlen < oidsize) {
                        oid[(*oidlen)++] = o;
@@ -1199,7 +1199,7 @@ varbind_print(netdissect_options *ndo,
 {
        struct be elem;
        int count = 0, ind;
-#ifdef LIBSMI
+#ifdef USE_LIBSMI
        SmiNode *smiNode = NULL;
 #endif
        int status;
@@ -1216,7 +1216,7 @@ varbind_print(netdissect_options *ndo,
                ND_PRINT((ndo, "[%d extra after SEQ of varbind]", length - count));
        /* descend */
        length = elem.asnlen;
-       np = (u_char *)elem.data.raw;
+       np = (const u_char *)elem.data.raw;
 
        for (ind = 1; length > 0; ind++) {
                const u_char *vbend;
@@ -1236,7 +1236,7 @@ varbind_print(netdissect_options *ndo,
                vblength = length - count;
                /* descend */
                length = elem.asnlen;
-               np = (u_char *)elem.data.raw;
+               np = (const u_char *)elem.data.raw;
 
                /* objName (OID) */
                if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
@@ -1246,7 +1246,7 @@ varbind_print(netdissect_options *ndo,
                        asn1_print(ndo, &elem);
                        return;
                }
-#ifdef LIBSMI
+#ifdef USE_LIBSMI
                smiNode = smi_print_variable(ndo, &elem, &status);
 #else
                status = asn1_print(ndo, &elem);
@@ -1272,7 +1272,7 @@ varbind_print(netdissect_options *ndo,
                        }
                } else {
                        if (elem.type != BE_NULL) {
-#ifdef LIBSMI
+#ifdef USE_LIBSMI
                                status = smi_print_value(ndo, smiNode, pduid, &elem);
 #else
                                status = asn1_print(ndo, &elem);
@@ -1485,7 +1485,7 @@ pdu_print(netdissect_options *ndo,
        ND_PRINT((ndo, " "));
        /* descend into PDU */
        length = pdu.asnlen;
-       np = (u_char *)pdu.data.raw;
+       np = (const u_char *)pdu.data.raw;
 
        if (version == SNMP_VERSION_1 &&
            (pdu.id == GETBULKREQ || pdu.id == INFORMREQ ||
@@ -1539,7 +1539,7 @@ scopedpdu_print(netdissect_options *ndo,
                return;
        }
        length = elem.asnlen;
-       np = (u_char *)elem.data.raw;
+       np = (const u_char *)elem.data.raw;
 
        /* contextEngineID (OCTET STRING) */
        if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
@@ -1594,7 +1594,7 @@ community_print(netdissect_options *ndo,
        }
        /* default community */
        if (!(elem.asnlen == sizeof(DEF_COMMUNITY) - 1 &&
-           strncmp((char *)elem.data.str, DEF_COMMUNITY,
+           strncmp((const char *)elem.data.str, DEF_COMMUNITY,
                    sizeof(DEF_COMMUNITY) - 1) == 0))
                /* ! "public" */
                ND_PRINT((ndo, "C=%.*s ", (int)elem.asnlen, elem.data.str));
@@ -1623,7 +1623,7 @@ usm_print(netdissect_options *ndo,
                return;
        }
        length = elem.asnlen;
-       np = (u_char *)elem.data.raw;
+       np = (const u_char *)elem.data.raw;
 
        /* msgAuthoritativeEngineID (OCTET STRING) */
        if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
@@ -1724,7 +1724,7 @@ v3msg_print(netdissect_options *ndo,
                return;
        }
        length = elem.asnlen;
-       np = (u_char *)elem.data.raw;
+       np = (const u_char *)elem.data.raw;
 
        if (ndo->ndo_vflag) {
                ND_PRINT((ndo, "{ "));
@@ -1863,7 +1863,7 @@ snmp_print(netdissect_options *ndo,
                ND_PRINT((ndo, "[%d extra after iSEQ]", length - count));
        /* descend */
        length = elem.asnlen;
-       np = (u_char *)elem.data.raw;
+       np = (const u_char *)elem.data.raw;
 
        /* Version (INTEGER) */
        if ((count = asn1_parse(ndo, np, length, &elem)) < 0)