Attached please find the code I used. It's from mib2c.iterator -S 1 option.
ThanksXuan
> Date: Tue, 6 Apr 2010 12:31:46 +0100
> Subject: Re: Help on Index out of range error
> From: d.t.shi...@liverpool.ac.uk
> To: b...@live.com
> CC: net-snmp-users@lists.sourceforge.net
>
> 2010/4/5 X Z <b...@live.com>:
> > Sorry for the typo. I modified the MIB text so that the index and table name
> > are easy to read, but I forgot to change this Index name, it should be
> > MyIndex.
>
> No - it should be "myIndex".
> MIB object names must start with a lower-case letter.
>
>
>
> > I got rid of the index out of range error by defining index to be a smaller
> > range. It seems 4294967295 is too big for unsigned32.
>
> Hmmm...
> That should be OK.
>
> I can certainly query entries in the DisMan Event-MIB mteObjectsTable,
> which has an index of syntax "Unsigned32 (1..4294967295)"
>
>
>
> >
> > But now I got a
> > different error saying that "no such instance currently exists at this oid".
>
> Note that this is an error from the agent-side,
> The range error will be coming from the "snmpget" tool,
> which probably never even sent a request to the agent.
> (You can check this by adding the '-d' flag, to display a
> raw dump of the request and response packets).
>
>
> > I can do snmpwalk on the same table. So I wonder if it's related
> > to the iterator MIB table implementation?
>
> Please post the full text of your MIB module code (as an attachment),
> so we can investigate properly.
>
>
> Dave
_________________________________________________________________
The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail.
http://www.windowslive.com/campaign/thenewbusy?tile=multiaccount&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4
I used mib2c.iterate.conf -S cache=1 option to generate the code:
#include "myTable.h"
struct myTable_entry {
u_long myIndex;
long status;
/*
* linked list
*/
struct myTable_entry *next;
};
struct myTable_entry *myTable_head;
void init_myTable(void)
{
static oid myTable_oid[] =
{x,x,x,x,x,x,x,x,x};
size_t myTable_oid_len =
OID_LENGTH(myTable_oid);
netsnmp_handler_registration *reg;
netsnmp_iterator_info *iinfo;
netsnmp_table_registration_info *table_info;
reg = netsnmp_create_handler_registration("mylTable",
myTable_handler,
myTable_oid,
myTable_oid_len,
HANDLER_CAN_RONLY);
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
if (table_info == NULL) {
return;
}
netsnmp_table_helper_add_indexes(table_info, ASN_UNSIGNED, 1);
table_info->min_column = 2;
table_info->max_column =3;
iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
if (iinfo == NULL) {
SNMP_FREE(table_info);
return;
}
iinfo->get_first_data_point = myTable_get_first_data_point;
iinfo->get_next_data_point = myTable_get_next_data_point;
iinfo->table_reginfo = table_info;
netsnmp_register_table_iterator(reg, iinfo);
netsnmp_inject_handler_before(reg,
netsnmp_get_cache_handler
(60,
myTable_load,
myTable_free,
myTable_oid,
myTable_oid_len),
TABLE_ITERATOR_NAME);
}
struct myTable_entry *myTable_createEntry(u_long myIndex)
{
struct myTable_entry *entry;
entry = SNMP_MALLOC_TYPEDEF(struct myTable_entry);
if (entry == NULL) {
return NULL;
}
entry->myIndex = myIndex;
entry->next = myTable_head;
myTable_head = entry;
return entry;
}
void myTable_removeEntry(struct myTable_entry *entry)
{
struct myTable_entry *ptr, *prev;
if (entry == NULL) {
return;
}
for (ptr = myTable_head, prev = NULL;
ptr != NULL;
prev = ptr, ptr = ptr->next) {
if (ptr == entry)
break;
}
if (ptr == NULL)
return;
if (prev == NULL)
myTable_head = ptr->next;
else
prev->next = ptr->next;
SNMP_FREE(entry);
}
int myTable_load(netsnmp_cache * cache, void *vmagic)
{
struct myTable_entry *this;
u_long i;
int state = 1;
for (i = 0; i < 10; i++) {
this = SNMP_MALLOC_TYPEDEF(struct myTable_entry);
if (this == NULL) {
return SNMP_ERR_GENERR;
}
/* MIB index should start from 1 */
this->myIndex = i+1;
this->status = state;
this->next = myTable_head;
myTable_head = this;
}
return SNMP_ERR_NOERROR;
}
void myTable_free(netsnmp_cache * cache, void *vmagic)
{
struct myTable_entry *this, *that;
for (this = myTable_head; this; this = that) {
that = this->next;
SNMP_FREE(this);
}
myTable_head = NULL;
}
netsnmp_variable_list
*myTable_get_first_data_point(void **my_loop_context,
void **my_data_context,
netsnmp_variable_list *
put_index_data,
netsnmp_iterator_info *mydata)
{
*my_loop_context = myTable_head;
*my_data_context = myTable_head;
snmp_set_var_typed_value(put_index_data, ASN_UNSIGNED ,
(u_char *)&(myTable_head->myIndex),
sizeof(myTable_head->myIndex));
return myTable_get_next_data_point(my_loop_context,
my_data_context,
put_index_data,
mydata);
}
netsnmp_variable_list *
myTable_get_next_data_point(void **my_loop_context,
void **my_data_context,
netsnmp_variable_list * put_index_data,
netsnmp_iterator_info *mydata)
{
struct myTable_entry *entry =
(struct myTable_entry *) *my_loop_context;
netsnmp_variable_list *idx = put_index_data;
if (entry) {
snmp_set_var_typed_value(idx, ASN_UNSIGNED , (u_char
*)&(entry->myIndex), sizeof(entry->myIndex));
idx = idx->next_variable;
*my_data_context = (void *) entry;
*my_loop_context = (void *) entry->next;
return put_index_data;
} else {
return NULL;
}
}
------------------------------------------------------------------------------
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-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users