=?windows-1256?Q?RE:_Help_o?= =?windows-1256?Q?n_Index_ou?= =?windows-1256?Q?t_of_range?= =?windows-1256?Q?_error_=FE?=
X Z <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
Sorry that I used "copy & paste" and some part got omitted by the copy board. Here are the original c & h files. ThanksXuan > Date: Wed, 7 Apr 2010 09:15:56 +0100 > Subject: Re: Help on Index out of range error أ¾ > From: [email protected] > To: [email protected] > CC: [email protected] > > 2010/4/6 X Z <[email protected]>: > > Attached please find the code I used. It's from mib2c.iterator -S 1 option. > > This code cannot possibly work. > It registers a routine 'myTable_handler' to process requests, > but there is no such routine in the file. > > (You've also omitted to include the header file 'myTable.h') > > We cannot help you if you keep providing incomplete information! > > Dave _________________________________________________________________ Hotmail is redefining busy with tools for the New Busy. Get more from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2 ------------------------------------------------------------------------------ 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 [email protected] Please see the following page to unsubscribe or change other options: https://lists.sourceforge.net/lists/listinfo/net-snmp-users
myTable.c
(application/octet-stream, 6.6 KB)
#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[] =
{1,3,6,1,4,1,8072,2,2,3};
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 = 2;
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;
}
}
int myTable_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
netsnmp_request_info *request;
netsnmp_table_request_info *table_info;
struct myTable_entry *table_entry;
switch (reqinfo->mode) {
/*
* SNMP GET support (also covers GetNext requests)
*/
case MODE_GET:
for (request = requests; request; request = request->next) {
table_entry = (struct myTable_entry *)
netsnmp_extract_iterator_context(request);
table_info = netsnmp_extract_table_info(request);
switch (table_info->colnum) {
case COLUMN_STATUS:
if (!table_entry) {
netsnmp_set_request_error(reqinfo,
request,
SNMP_NOSUCHINSTANCE);
continue;
}
snmp_set_var_typed_integer(request->requestvb,
ASN_INTEGER,
table_entry->status);
break;
default:
netsnmp_set_request_error(reqinfo,
request,
SNMP_NOSUCHOBJECT);
break;
}
}
break;
/* no support for SNMP SET */
}
return SNMP_ERR_NOERROR;
}
myTable.h
(application/octet-stream, 454 B)
#include <net-snmp/net-snmp-config-i386.h> #include <net-snmp/net-snmp-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h> /* * function declarations */ void init_myTable(void); Netsnmp_Node_Handler myTable_handler; Netsnmp_First_Data_Point myTable_get_first_data_point; Netsnmp_Next_Data_Point myTable_get_next_data_point; NetsnmpCacheLoad myTable_load; NetsnmpCacheFree myTable_free; #define COLUMN_MYINDEX 1 #define COLUMN_STATUS 2