[AGENT++] Some Questions about SNMP walk

Jochen Katz katz at agentpp.com
Thu Jan 6 14:13:00 CET 2005


Hi,

> My question is , for example,I set the start OID to be
> "1.3.6.1.2.1.4.20.1.1" and version to be "v2" and correct Community
> Name.  Now it outputs all the entries under the OID given above. It
> also gives the value of "1.3.6.1.2.1.4.20.1.2" and so on.

the example snmpWalk always walks to the end of mib (until now... ;-)

> I only just want to output the  "1.3.6.1.2.1.4.20.1.1"
> sub-entries,but not others.

Use patch below to snmpWalk.cpp recompile and call snmpalk with -S option.

Regards,
   Jochen

--- snmpWalk.cpp        28 May 2004 18:47:24 -0000      1.6
+++ snmpWalk.cpp        6 Jan 2005 13:07:42 -0000
@@ -78,6 +78,7 @@
  #ifdef _SNMPv3
            cout << "         -v3 , use SNMPV3\n";
  #endif
+         cout << "         -S , only walk within subtree\n";
           cout << "         -pPort , remote port to use\n";
           cout << "         -CCommunity_name, specify community default 
is 'public' \n";
           cout << "         -rN , retries default is N = 1 retry\n";
@@ -126,6 +127,7 @@
     int timeout=100;                                // default is 1 second
     u_short port=161;                               // default snmp 
port is 161
     OctetStr community("public");                   // community name
+   bool subtree = false;

  #ifdef _SNMPv3
     OctetStr privPassword("");
@@ -169,6 +171,10 @@
         sscanf(ptr, "%hu", &port);
         continue;
       }
+     if ( strstr( argv[x],"-S") != 0) {
+       subtree = true;
+       continue;
+     }

  #ifdef _SNMPv3
       if ( strstr( argv[x],"-v3")!= 0) {
@@ -379,6 +385,15 @@
                return -5;
              }
  #endif
+            Oid tmp;
+            vb.get_oid(tmp);
+            if (subtree && (oid.nCompare(oid.len(), tmp) != 0))
+            {
+                cout << "End of SUBTREE Reached\n";
+                cout << "Total # of Requests = " << requests << "\n";
+                cout << "Total # of Objects  = " << objects  << "\n";
+                return -4;
+            }
                  objects++;
                  // look for var bind exception, applies to v2 only
                  if ( vb.get_syntax() != sNMP_SYNTAX_ENDOFMIBVIEW) {




More information about the AGENTPP mailing list