]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-snmp.c
Clean up whitespaces
[tcpdump] / print-snmp.c
index 7028c0b1e1856dbb719cb75484719637c6bc5c37..87c7e9705e70b1d7f1107c531008d662a0062c94 100644 (file)
@@ -59,7 +59,7 @@
 /* \summary: Simple Network Management Protocol (SNMP) printer */
 
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
 #include "netdissect-stdinc.h"
@@ -76,7 +76,6 @@
 
 #undef OPAQUE  /* defined in <wingdi.h> */
 
-static const char tstr[] = "[|snmp]";
 
 /*
  * Universal ASN.1 types
@@ -198,7 +197,7 @@ static const char *ErrorStatus[] = {
 #define DECODE_ErrorStatus(e) \
        ( e >= 0 && (size_t)e < sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \
                ? ErrorStatus[e] \
-               : (snprintf(errbuf, sizeof(errbuf), "err=%u", e), errbuf))
+               : (nd_snprintf(errbuf, sizeof(errbuf), "err=%u", e), errbuf))
 
 /*
  * generic-trap values in the SNMP Trap-PDU
@@ -216,7 +215,7 @@ static const char *GenericTrap[] = {
 #define DECODE_GenericTrap(t) \
        ( t >= 0 && (size_t)t < sizeof(GenericTrap)/sizeof(GenericTrap[0]) \
                ? GenericTrap[t] \
-               : (snprintf(buf, sizeof(buf), "gt=%d", t), buf))
+               : (nd_snprintf(buf, sizeof(buf), "gt=%d", t), buf))
 
 /*
  * ASN.1 type class table
@@ -421,7 +420,7 @@ asn1_parse(netdissect_options *ndo,
            const u_char *p, u_int len, struct be *elem)
 {
        u_char form, class, id;
-       int i, hdr;
+       u_int i, hdr;
 
        elem->asnlen = 0;
        elem->type = BE_ANY;
@@ -545,7 +544,7 @@ asn1_parse(netdissect_options *ndo,
                                }
                                if (EXTRACT_U_1(p) & ASN_BIT8)  /* negative */
                                        data = -1;
-                               for (i = elem->asnlen; i-- > 0; p++)
+                               for (i = elem->asnlen; i != 0; p++, i--)
                                        data = (data << ASN_SHIFT8) | EXTRACT_U_1(p);
                                elem->data.integer = data;
                                break;
@@ -582,7 +581,7 @@ asn1_parse(netdissect_options *ndo,
                                uint32_t data;
                                elem->type = BE_UNS;
                                data = 0;
-                               for (i = elem->asnlen; i-- > 0; p++)
+                               for (i = elem->asnlen; i != 0; p++, i--)
                                        data = (data << 8) + EXTRACT_U_1(p);
                                elem->data.uns = data;
                                break;
@@ -592,7 +591,7 @@ asn1_parse(netdissect_options *ndo,
                                uint64_t data64;
                                elem->type = BE_UNS64;
                                data64 = 0;
-                               for (i = elem->asnlen; i-- > 0; p++)
+                               for (i = elem->asnlen; i != 0; p++, i--)
                                        data64 = (data64 << 8) + EXTRACT_U_1(p);
                                elem->data.uns64 = data64;
                                break;
@@ -669,7 +668,7 @@ asn1_parse(netdissect_options *ndo,
        return elem->asnlen + hdr;
 
 trunc:
-       ND_PRINT("%s", tstr);
+       nd_print_trunc(ndo);
        return -1;
 }
 
@@ -681,12 +680,12 @@ asn1_print_octets(netdissect_options *ndo, struct be *elem)
        uint32_t i;
 
        ND_TCHECK_LEN(p, asnlen);
-       for (i = asnlen; i-- > 0; p++)
+       for (i = asnlen; i != 0; p++, i--)
                ND_PRINT("_%.2x", EXTRACT_U_1(p));
        return 0;
 
 trunc:
-       ND_PRINT("%s", tstr);
+       nd_print_trunc(ndo);
        return -1;
 }
 
@@ -700,18 +699,18 @@ asn1_print_string(netdissect_options *ndo, struct be *elem)
 
        p = elem->data.str;
        ND_TCHECK_LEN(p, asnlen);
-       for (i = asnlen; printable && i-- > 0; p++)
+       for (i = asnlen; printable && i != 0; p++, i--)
                printable = ND_ISPRINT(EXTRACT_U_1(p));
        p = elem->data.str;
        if (printable) {
                ND_PRINT("\"");
-               if (fn_printn(ndo, p, asnlen, ndo->ndo_snapend)) {
+               if (nd_printn(ndo, p, asnlen, ndo->ndo_snapend)) {
                        ND_PRINT("\"");
                        goto trunc;
                }
                ND_PRINT("\"");
        } else {
-               for (i = asnlen; i-- > 0; p++) {
+               for (i = asnlen; i != 0; p++, i--) {
                        ND_PRINT(first ? "%.2x" : "_%.2x", EXTRACT_U_1(p));
                        first = 0;
                }
@@ -719,7 +718,7 @@ asn1_print_string(netdissect_options *ndo, struct be *elem)
        return 0;
 
 trunc:
-       ND_PRINT("%s", tstr);
+       nd_print_trunc(ndo);
        return -1;
 }
 
@@ -769,7 +768,7 @@ asn1_print(netdissect_options *ndo,
                        }
                }
 
-               for (; i-- > 0; p++) {
+               for (; i != 0; p++, i--) {
                        ND_TCHECK_1(p);
                        o = (o << ASN_SHIFT7) + (EXTRACT_U_1(p) & ~ASN_BIT8);
                        if (EXTRACT_U_1(p) & ASN_LONGLEN)
@@ -824,8 +823,8 @@ asn1_print(netdissect_options *ndo,
                        ND_PRINT("[inetaddr len!=%d]", ASNLEN_INETADDR);
                p = (const u_char *)elem->data.raw;
                ND_TCHECK_LEN(p, asnlen);
-               for (i = asnlen; i-- != 0; p++) {
-                       ND_PRINT((i == asnlen-1) ? "%u" : ".%u", EXTRACT_U_1(p));
+               for (i = asnlen; i != 0; p++, i--) {
+                       ND_PRINT((i == asnlen) ? "%u" : ".%u", EXTRACT_U_1(p));
                }
                break;
 
@@ -850,7 +849,7 @@ asn1_print(netdissect_options *ndo,
        return 0;
 
 trunc:
-       ND_PRINT("%s", tstr);
+       nd_print_trunc(ndo);
        return -1;
 }
 
@@ -918,10 +917,11 @@ smi_decode_oid(netdissect_options *ndo,
 {
        const u_char *p = (const u_char *)elem->data.raw;
        uint32_t asnlen = elem->asnlen;
-       int o = 0, first = -1, i = asnlen;
+       uint32_t i = asnlen;
+       int o = 0, first = -1;
        unsigned int firstval;
 
-       for (*oidlen = 0; i-- > 0; p++) {
+       for (*oidlen = 0; i != 0; p++, i--) {
                ND_TCHECK_1(p);
                o = (o << ASN_SHIFT7) + (EXTRACT_U_1(p) & ~ASN_BIT8);
                if (EXTRACT_U_1(p) & ASN_LONGLEN)
@@ -932,7 +932,7 @@ smi_decode_oid(netdissect_options *ndo,
                 * (see X.690:1997 clause 8.19 for the details)
                 */
                if (first < 0) {
-                       first = 0;
+                       first = 0;
                        firstval = o / OIDMUX;
                        if (firstval > 2) firstval = 2;
                        o -= firstval * OIDMUX;
@@ -948,7 +948,7 @@ smi_decode_oid(netdissect_options *ndo,
        return 0;
 
 trunc:
-       ND_PRINT("%s", tstr);
+       nd_print_trunc(ndo);
        return -1;
 }
 
@@ -1883,6 +1883,7 @@ snmp_print(netdissect_options *ndo,
        int count = 0;
        int version = 0;
 
+       ndo->ndo_protocol = "snmp";
        ND_PRINT(" ");
 
        /* initial Sequence */