新手求助:NET-SNMP中表变量的实现问题
本帖最后由 asite123 于 2010-08-10 12:00:17 编辑
在实现表对象的过程中,转换后的C代码如下:
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "ExampleTable.h"
struct ExampleTable_entry {
long UserIndex;
char UserStatus[30];
u_long CheckTime;
long MonSet;
long Old_MonSet;
int valid;
struct ExampleTable_entry *next;
};
struct ExampleTable_entry *ExampleTable_head;
struct ExampleTable_entry * ExampleTable_createEntry(long UserIndex,char* UserStatus,u_long CheckTime,long MonSet)
{
struct ExampleTable_entry *entry;
entry = SNMP_MALLOC_TYPEDEF(struct ExampleTable_entry);
if (!entry)
return NULL;
entry->UserIndex = UserIndex;
strcpy(entry->UserStatus,UserStatus);
entry->CheckTime=CheckTime;
entry->MonSet=MonSet;
entry->next = ExampleTable_head;
ExampleTable_head = entry;
return entry;
}
void init_ExampleTable(void)
{
/* here we initialize all the tables we're planning on supporting */
initialize_table_ExampleTable();
}
// # Determine the first/last column names
void initialize_table_ExampleTable(void)
{
static oid ExampleTable_oid[] = {1,3,6,1,4,1,310,3};
size_t ExampleTable_oid_len = OID_LENGTH(ExampleTable_oid);
netsnmp_handler_registration *reg;
netsnmp_iterator_info *iinfo;
netsnmp_table_registration_info *table_info;
reg = netsnmp_create_handler_registration(
"ExampleTable", ExampleTable_handler,
ExampleTable_oid, ExampleTable_oid_len,
HANDLER_CAN_RWRITE
);
table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: UserIndex */ 0);
table_info->min_column = 2;
table_info->max_column = 10;
iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info );
iinfo->get_first_data_point = ExampleTable_get_first_data_point;
iin