On 13 March 2010 11:45, Magnus Fromreide <ma...@lysator.liu.se> wrote:
>> >> a) start at .1
>> >> pros: will show all available objects
>> >> cons: will show all available objects
>>
>> MF> I think I prefer a slight variation on this one if it is chosen:
>>
>> MF> start at . as opposed to .1.
>>
>> I'm not sure you can do that. I'd actually have to go look through the
>> SNMP and BER docs to figure out whether a zero-length OID is legal in
>> both of them.
>
> Given that BER encodes the first two digits in one octet I suspect you
> can't do .1 either.
I think there's a danger of getting sidetracked here.
The question is not whether you can represent the root of the tree as
a valid OID.
Rather it's a matter of deciding where the default snmpwalk should
start and stop.
Remember that GETNEXT knows nothing (and cares less) about the heirarchical
nature of the MIB tree. It works with a simple linear ordering of the OIDs.
And the "snmpwalk" code actually uses separate start/end OIDs anyway.
So all that's necessary is to set these appropriately.
I'm attaching a simple patch that walks from .0 until the end of the MIB tree
if given an explicit starting point of '.' or no starting point at all.
Comments?
Dave
Index: apps/snmpwalk.c
===================================================================
--- apps/snmpwalk.c (revision 18256)
+++ apps/snmpwalk.c (working copy)
@@ -180,6 +180,7 @@
int status;
int check;
int exitval = 0;
+ int everything = 0;
struct timeval tv1, tv2;
netsnmp_ds_register_config(ASN_BOOLEAN, "snmpwalk", "includeRequested",
@@ -222,23 +223,33 @@
/*
* specified on the command line
*/
+ if ( argv[arg][0] == '.' && argv[arg][1] == '\0' ) {
+ /* Walk the whole tree */
+ memset(root, 0, sizeof(root));
+ root[0] = 0;
+ rootlen = 1;
+ everything = 1;
+ } else {
rootlen = MAX_OID_LEN;
if (snmp_parse_oid(argv[arg], root, &rootlen) == NULL) {
snmp_perror(argv[arg]);
exit(1);
}
+ }
} else {
/*
- * use default value
+ * Start at the very beginning.
+ * A very good place to start.
*/
- memmove(root, objid_mib, sizeof(objid_mib));
- rootlen = sizeof(objid_mib) / sizeof(oid);
+ memset(root, 0, sizeof(root));
+ root[0] = 0;
+ rootlen = 1;
+ everything = 1;
}
/*
* If we've been given an explicit end point,
- * then convert this to an OID, otherwise
- * move to the next sibling of the start.
+ * then convert this to an OID...
*/
if ( end_name ) {
end_len = MAX_OID_LEN;
@@ -246,7 +257,18 @@
snmp_perror(end_name);
exit(1);
}
+ } else if (everything) {
+ /*
+ * ... if we're walking the whole tree,
+ * don't stop till we've had enough...
+ */
+ memset(end_oid, 0, sizeof(end_oid));
+ end_oid[0] = 3;
+ end_len = 1;
} else {
+ /*
+ * ... otherwise step at the next sibling following the start point
+ */
memmove(end_oid, root, rootlen*sizeof(oid));
end_len = rootlen;
end_oid[end_len-1]++;
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders