www.pudn.com > snmpsample.rar > srwTable.c


 
/* 
 * Note: this file originally auto-generated by mib2c using 
 *        : mib2c.create-dataset.conf,v 5.3 2002/12/05 00:29:45 hardaker Exp $ 
 */ 
 
#include  
#include  
#include  
#include "srwTable.h" 
 
/** Initialize the srwTable table by defining its contents and how it's structured */ 
void 
initialize_table_srwTable(void) 
{ 
    static oid      srwTable_oid[] = { 1, 3, 6, 1, 4, 1, 1159, 1 }; 
    size_t          srwTable_oid_len = OID_LENGTH(srwTable_oid); 
    netsnmp_table_data_set *table_set; 
    netsnmp_table_row *row; 
 
 
 
    /* 创建表结构自身 */ 
    table_set = netsnmp_create_table_data_set("srwTable"); 
 
    /* 
     * comment this out or delete if you don't support creation of new rows  
     */ 
    table_set->allow_creation = 1; /*允许在表中创建新的行*/ 
 
    /*************************************************** 
     * Adding indexes 
     */ 
    DEBUGMSGTL(("initialize_table_srwTable", 
                "adding indexes to table srwTable\n")); 
    netsnmp_table_set_add_indexes(table_set, ASN_INTEGER,       /* index: srwindex */ 
                                  0);/*给表添加索引项*/ 
 
    DEBUGMSGTL(("initialize_table_srwTable", 
                "adding column types to table srwTable\n")); 
    netsnmp_table_set_multi_add_default_row(table_set,/*设置默认表项*/ 
                                            COLUMN_SRWINDEX, ASN_INTEGER, 
                                            1, NULL, 0, COLUMN_SRWNAME, 
                                            ASN_OCTET_STR, 1, NULL, 0, 0); 
 
    /* 
     * registering the table with the master agent  
     */ 
    /* 
     * note: if you don't need a subhandler to deal with any aspects 
     * of the request, change srwTable_handler to "NULL"  
     */ 
    netsnmp_register_table_data_set(netsnmp_create_handler_registration 
                                    ("srwTable", srwTable_handler, 
                                     srwTable_oid, srwTable_oid_len, 
                                     HANDLER_CAN_RWRITE), table_set, NULL); 
     //create the a row for the table, and add the data  
      
      row = netsnmp_create_table_data_row();    /*创建新的行数据*/  
    /* 
     * set the index to the  name "1980"  
     */ 
    netsnmp_table_row_add_index(row, ASN_INTEGER, "1982", /*添加索引*/ 
                                strlen("1982")); 
 
 
    /* 
     * set column 2 to be the WG chair name "Russ Mundy"  
     */ 
    netsnmp_set_row_column(row, 2, ASN_OCTET_STR,  /*设置可读写列数据*/  
                           "Sheng rui", strlen("Sheng rui")); 
    netsnmp_mark_row_column_writable(row, 2, 1);        /* make writable via SETs */ 
 
    /* 
     * set column 3 to be the WG chair name "David Harrington"  
     */ 
    //netsnmp_set_row_column(row, 3, ASN_OCTET_STR, "David Harrington", 
                           //strlen("David Harrington")); 
    //netsnmp_mark_row_column_writable(row, 3, 1);        /* make writable via SETs */ 
 
    /* 
     * add the row to the table  
     */ 
    netsnmp_table_dataset_add_row(table_set, row); 
 
//#ifdef ADD_MORE_DATA 
    /* 
     * add the data, for the second row  
     */ 
    //row = netsnmp_create_table_data_row(); 
    //netsnmp_table_row_add_index(row, ASN_OCTET_STR, "snmpconf", 
                               //strlen("snmpconf")); 
    //netsnmp_set_row_column(row, 2, ASN_OCTET_STR, "David Partain", 
                           //strlen("David Partain")); 
    //netsnmp_mark_row_column_writable(row, 2, 1);        /* make writable */ 
    //netsnmp_set_row_column(row, 3, ASN_OCTET_STR, "Jon Saperia", 
                           //strlen("Jon Saperia")); 
    //netsnmp_mark_row_column_writable(row, 3, 1);        /* make writable */ 
    //netsnmp_table_dataset_add_row(table_set, row); 
//#endif 
 
    /* 
     * Finally, this actually allows the "add_row" token it the 
     * * snmpd.conf file to add rows to this table. 
     * * Example snmpd.conf line: 
     * *   add_row netSnmpIETFWGTable eos "Glenn Waters" "Dale Francisco" 
     */ 
    netsnmp_register_auto_data_table(table_set, NULL); 
 
    DEBUGMSGTL(("example_data_set", "Done initializing.\n")); 
 
 
} 
 
/** Initializes the srwTable module */ 
void 
init_srwTable(void) 
{ 
 
    /* 这里初始化所有计划支持的表 */ 
    initialize_table_srwTable(); 
} 
 
/** handles requests for the srwTable table, if anything else needs to be done */ 
 
int 
srwTable_handler(netsnmp_mib_handler *handler, 
                 netsnmp_handler_registration *reginfo, 
                 netsnmp_agent_request_info *reqinfo, 
                 netsnmp_request_info *requests) 
{ 
    /* 
     * perform anything here that you need to do.  The requests have 
     * already been processed by the master table_dataset handler, but 
     * this gives you chance to act on the request in some other way 
     * if need be.  
     */ 
    return SNMP_ERR_NOERROR; 
}