]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-snmp.c
Add SunATM support, based on code from Yen Yen Lim at North Dakota State
[tcpdump] / print-snmp.c
index 76578ee83774c11e930ea8fe3c62dc653eadfea8..c7a5edf1af6830bf531a72d61f69c51b4a8bb98e 100644 (file)
@@ -1,16 +1,29 @@
 /*
  * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
- *     The Regents of the University of California.  All rights reserved.
+ *     John Robert LoVerso. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by John Robert LoVerso.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * This implementation has been influenced by the CMU SNMP release,
  * by Steve Waldbusser.  However, this shares no code with that system.
@@ -45,7 +58,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.49 2001-06-15 21:06:59 fenner Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.53 2002-06-11 17:08:56 itojun Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -546,7 +559,7 @@ asn1_parse(register const u_char *p, u_int len, struct be *elem)
                                elem->type = BE_UNS64;
                                high = 0, low = 0;
                                for (i = elem->asnlen; i-- > 0; p++) {
-                                       high = (high << 8) | 
+                                       high = (high << 8) |
                                            ((low & 0xFF000000) >> 24);
                                        low = (low << 8) | *p;
                                }
@@ -672,16 +685,20 @@ asn1_print(struct be *elem)
                        o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8);
                        if (*p & ASN_LONGLEN)
                                continue;
-                       
+
                        /*
                         * first subitem encodes two items with 1st*OIDMUX+2nd
+                        * (see X.690:1997 clause 8.19 for the details)
                         */
                        if (first < 0) {
+                               int s;
                                if (!nflag)
                                        objp = mibroot;
                                first = 0;
-                               OBJ_PRINT(o/OIDMUX, first);
-                               o %= OIDMUX;
+                               s = o / OIDMUX;
+                               if (s > 2) s = 2;
+                               OBJ_PRINT(s, first);
+                               o -= s * OIDMUX;
                        }
                        OBJ_PRINT(o, first);
                        if (--first < 0)
@@ -708,7 +725,7 @@ asn1_print(struct be *elem)
                        break;
                }
                d = elem->data.uns64.high * 4294967296.0;       /* 2^32 */
-               if (elem->data.uns64.high <= 0x1fffff) { 
+               if (elem->data.uns64.high <= 0x1fffff) {
                        d += elem->data.uns64.low;
 #if 0 /*is looks illegal, but what is the intention?*/
                        printf("%.f", d);
@@ -859,19 +876,22 @@ static void smi_decode_oid(struct be *elem, unsigned int *oid,
                o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8);
                if (*p & ASN_LONGLEN)
                    continue;
-           
+
                /*
                 * first subitem encodes two items with 1st*OIDMUX+2nd
+                * (see X.690:1997 clause 8.19 for the details)
                 */
                if (first < 0) {
                        first = 0;
                        if (*oidlen < oidsize) {
-                           oid[(*oidlen)++] = o/OIDMUX;
+                           oid[*oidlen] = o / OIDMUX;
+                           if (oid[*oidlen] > 2) oid[*oidlen] = 2;
                        }
-                       o %= OIDMUX;
+                       o -= oid[*oidlen] * OIDMUX;
+                       if (*oidlen < oidsize) (*oidlen)++;
                }
                if (*oidlen < oidsize) {
-                   oid[(*oidlen)++] = o;
+                       oid[(*oidlen)++] = o;
                }
                o = 0;
        }
@@ -894,7 +914,7 @@ static int smi_check_a_range(SmiType *smiType, SmiRange *smiRange,
                             struct be *elem)
 {
     int ok = 1;
-    
+
     switch (smiType->basetype) {
     case SMI_BASETYPE_OBJECTIDENTIFIER:
     case SMI_BASETYPE_OCTETSTRING:
@@ -911,12 +931,12 @@ static int smi_check_a_range(SmiType *smiType, SmiRange *smiRange,
        ok = (elem->data.integer >= smiRange->minValue.value.integer32
              && elem->data.integer <= smiRange->maxValue.value.integer32);
        break;
-           
+
     case SMI_BASETYPE_UNSIGNED32:
        ok = (elem->data.uns >= smiRange->minValue.value.unsigned32
              && elem->data.uns <= smiRange->maxValue.value.unsigned32);
        break;
-       
+
     case SMI_BASETYPE_UNSIGNED64:
        /* XXX */
        break;
@@ -1046,7 +1066,7 @@ static void smi_print_value(SmiNode *smiNode, u_char pduid, struct be *elem)
        /* apply display hints (integer, octetstring) */
 
        /* convert instance identifier to index type values */
-       
+
        switch (elem->type) {
        case BE_OID:
                if (smiType->basetype == SMI_BASETYPE_BITS) {
@@ -1063,7 +1083,7 @@ static void smi_print_value(SmiNode *smiNode, u_char pduid, struct be *elem)
                                }
                                fputs(smiNode->name, stdout);
                                if (smiNode->oidlen < oidlen) {
-                                       for (i = smiNode->oidlen; 
+                                       for (i = smiNode->oidlen;
                                             i < oidlen; i++) {
                                                printf(".%u", oid[i]);
                                        }
@@ -1414,7 +1434,7 @@ pdu_print(const u_char *np, u_int length, int version)
        np = (u_char *)pdu.data.raw;
 
        if (version == SNMP_VERSION_1 &&
-           (pdu.id == GETBULKREQ || pdu.id == INFORMREQ || 
+           (pdu.id == GETBULKREQ || pdu.id == INFORMREQ ||
             pdu.id == V2TRAP || pdu.id == REPORT)) {
                printf("[v2 PDU in v1 message]");
                return;
@@ -1442,7 +1462,7 @@ pdu_print(const u_char *np, u_int length, int version)
        }
 
        if (vflag) {
-               fputs("} ", stdout);
+               fputs(" } ", stdout);
        }
 }
 
@@ -1566,7 +1586,7 @@ usm_print(const u_char *np, u_int length)
                asn1_print(&elem);
                return;
        }
-       if (vflag) 
+       if (vflag)
                printf("B=%d ", elem.data.integer);
        length -= count;
        np += count;
@@ -1579,7 +1599,7 @@ usm_print(const u_char *np, u_int length)
                asn1_print(&elem);
                return;
        }
-       if (vflag) 
+       if (vflag)
                printf("T=%d ", elem.data.integer);
        length -= count;
        np += count;
@@ -1686,7 +1706,7 @@ v3msg_print(const u_char *np, u_int length)
                return;
        }
        flags = elem.data.str[0];
-       if (flags != 0x00 && flags != 0x01 && flags != 0x03 
+       if (flags != 0x00 && flags != 0x01 && flags != 0x03
            && flags != 0x04 && flags != 0x05 && flags != 0x07) {
                printf("[msgFlags=0x%02X]", flags);
                return;