]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-snmp.c
Get rid of an extra newline.
[tcpdump] / print-snmp.c
index bdc13b04018896564b0b1f1d7ff3467e981852e0..a82cbf9203646bb662de8466660fa207661d6b9a 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.47 2001-03-22 02:06:43 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.52 2002-05-07 18:27:40 fenner Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -675,13 +688,17 @@ asn1_print(struct be *elem)
                        
                        /*
                         * 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)
@@ -849,7 +866,7 @@ static struct smi2be smi2betab[] = {
 };
 
 static void smi_decode_oid(struct be *elem, unsigned int *oid,
-                          unsigned int *oidlen)
+                          unsigned int oidsize, unsigned int *oidlen)
 {
        u_char *p = (u_char *)elem->data.raw;
        u_int32_t asnlen = elem->asnlen;
@@ -862,13 +879,20 @@ static void smi_decode_oid(struct be *elem, unsigned int *oid,
            
                /*
                 * first subitem encodes two items with 1st*OIDMUX+2nd
+                * (see X.690:1997 clause 8.19 for the details)
                 */
                if (first < 0) {
                        first = 0;
-                       oid[(*oidlen)++] = o/OIDMUX;
-                       o %= OIDMUX;
+                       if (*oidlen < oidsize) {
+                           oid[*oidlen] = o / OIDMUX;
+                           if (oid[*oidlen] > 2) oid[*oidlen] = 2;
+                       }
+                       o -= oid[*oidlen] * OIDMUX;
+                       if (*oidlen < oidsize) (*oidlen)++;
+               }
+               if (*oidlen < oidsize) {
+                       oid[(*oidlen)++] = o;
                }
-               oid[(*oidlen)++] = o;
                o = 0;
        }
 }
@@ -965,7 +989,7 @@ static SmiNode *smi_print_variable(struct be *elem)
        SmiNode *smiNode = NULL;
        int i;
 
-       smi_decode_oid(elem, oid, &oidlen);
+       smi_decode_oid(elem, oid, sizeof(oid)/sizeof(unsigned int), &oidlen);
        smiNode = smiGetNodeByOID(oidlen, oid);
        if (! smiNode) {
                asn1_print(elem);
@@ -1032,7 +1056,7 @@ static void smi_print_value(SmiNode *smiNode, u_char pduid, struct be *elem)
        }
 
        if (! smi_check_range(smiType, elem)) {
-           fputs("[wrongLength]", stdout);
+           fputs("[outOfRange]", stdout);
        }
 
        /* resolve bits to named bits */
@@ -1048,7 +1072,9 @@ static void smi_print_value(SmiNode *smiNode, u_char pduid, struct be *elem)
                if (smiType->basetype == SMI_BASETYPE_BITS) {
                        /* print bit labels */
                } else {
-                       smi_decode_oid(elem, oid, &oidlen);
+                       smi_decode_oid(elem, oid,
+                                      sizeof(oid)/sizeof(unsigned int),
+                                      &oidlen);
                        smiNode = smiGetNodeByOID(oidlen, oid);
                        if (smiNode) {
                                if (vflag) {
@@ -1436,7 +1462,7 @@ pdu_print(const u_char *np, u_int length, int version)
        }
 
        if (vflag) {
-               fputs("} ", stdout);
+               fputs(" } ", stdout);
        }
 }