⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iftable.c

📁 开发snmp的开发包有两个开放的SNMP开发库
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * Note: this file originally auto-generated by mib2c using *       version : 1.48 $ of : mfd-top.m2c,v $  * * $Id: ifTable.c 15461 2006-10-19 20:38:00Z hardaker $ *//** \page MFD helper for ifTable * * \section intro Introduction * Introductory text. * *//* * standard Net-SNMP includes  */#include <net-snmp/net-snmp-config.h>#include <net-snmp/net-snmp-includes.h>#include <net-snmp/agent/net-snmp-agent-includes.h>/* * include our parent header  */#include "ifTable.h"#include "ifTable_defs.h"#include <net-snmp/agent/mib_modules.h>#include "ifTable_interface.h"#ifdef USING_IP_MIB_IPV4INTERFACETABLE_IPV4INTERFACETABLE_MODULE#   include "ip-mib/ipv4InterfaceTable/ipv4InterfaceTable.h"#endif#ifdef USING_IP_MIB_IPV6INTERFACETABLE_IPV6INTERFACETABLE_MODULE#   include "ip-mib/ipv4InterfaceTable/ipv4InterfaceTable.h"#endif#ifdef USING_IF_MIB_IFXTABLE_IFXTABLE_MODULE#   include "if-mib/ifXTable/ifXTable.h"#endifoid             ifTable_oid[] = { IFTABLE_OID };int             ifTable_oid_size = OID_LENGTH(ifTable_oid);ifTable_registration ifTable_user_context;void            initialize_table_ifTable(void);void            shutdown_table_ifTable(void);static int_if_number_handler(netsnmp_mib_handler *handler,                   netsnmp_handler_registration *reginfo,                   netsnmp_agent_request_info *reqinfo,                   netsnmp_request_info *requests);/** * Initializes the ifTable module */voidinit_ifTable(void){    static int      ifTable_did_init = 0;    DEBUGMSGTL(("verbose:ifTable:init_ifTable", "called\n"));    /*     * TODO:300:o: Perform ifTable one-time module initialization.     */    if (++ifTable_did_init != 1) {        DEBUGMSGTL(("ifTable:init_ifTable", "ignoring duplicate call\n"));        return;    }    /*     * here we initialize all the tables we're planning on supporting     */    if (should_init("ifTable")) {#ifdef USING_IP_MIB_IPV4INTERFACETABLE_IPV4INTERFACETABLE_MODULE        if (should_init("ipv4InterfaceTable"))            initialize_table_ipv4InterfaceTable();#endif#ifdef USING_IP_MIB_IPV6INTERFACETABLE_IPV6INTERFACETABLE_MODULE        if (should_init("ipv6InterfaceTable"))            initialize_table_ipv6InterfaceTable();#endif        initialize_table_ifTable();#ifdef USING_IF_MIB_IFXTABLE_IFXTABLE_MODULE        if (should_init("ifXTable"))            initialize_table_ifXTable();#endif    }}                               /* init_ifTable *//** * Shut-down the ifTable module (agent is exiting) */voidshutdown_ifTable(void){    if (should_init("ifTable"))        shutdown_table_ifTable();}/** * Initialize the table ifTable  *    (Define its contents and how it's structured) */voidinitialize_table_ifTable(void){    ifTable_registration *user_context;    u_long          flags;    DEBUGMSGTL(("verbose:ifTable:initialize_table_ifTable", "called\n"));    /*     * TODO:301:o: Perform ifTable one-time table initialization.     */    /*     * TODO:302:o: |->Initialize ifTable user context     * if you'd like to pass in a pointer to some data for this     * table, allocate or set it up here.     */    /*     * a netsnmp_data_list is a simple way to store void pointers. A simple     * string token is used to add, find or remove pointers.     */    user_context = netsnmp_create_data_list("ifTable", NULL, NULL);    /*     * No support for any flags yet, but in the future you would     * set any flags here.     */    flags = 0;    /*     * call interface initialization code     */    _ifTable_initialize_interface(user_context, flags);    /*     * register scalar for ifNumber     */    {        oid             reg_oid[] =            { IFTABLE_NUMBER };        netsnmp_handler_registration *myreg;        myreg =            netsnmp_create_handler_registration("if number",                                                _if_number_handler,                                                reg_oid,                                                OID_LENGTH(reg_oid),                                                HANDLER_CAN_RONLY);        netsnmp_register_scalar(myreg);    }}                               /* initialize_table_ifTable *//** * Shutdown the table ifTable */voidshutdown_table_ifTable(void){    /*     * call interface shutdown code     */    _ifTable_shutdown_interface(&ifTable_user_context);}/** * extra context initialization (eg default values) * * @param rowreq_ctx    : row request context * @param user_init_ctx : void pointer for user (parameter to rowreq_ctx_allocate) * * @retval MFD_SUCCESS  : no errors * @retval MFD_ERROR    : error (context allocate will fail) */intifTable_rowreq_ctx_init(ifTable_rowreq_ctx * rowreq_ctx,                        void *user_init_ctx){    DEBUGMSGTL(("verbose:ifTable:ifTable_rowreq_ctx_init", "called\n"));    netsnmp_assert(NULL != rowreq_ctx);    /*     * TODO:210:o: |-> Perform extra ifTable rowreq initialization. (eg DEFVALS)     */    if (NULL == user_init_ctx)        rowreq_ctx->data.ifentry =            netsnmp_access_interface_entry_create(NULL, 0);    else        rowreq_ctx->data.ifentry =            (netsnmp_interface_entry *) user_init_ctx;    return MFD_SUCCESS;}                               /* ifTable_rowreq_ctx_init *//** * extra context cleanup * @param rowreq_ctx */voidifTable_rowreq_ctx_cleanup(ifTable_rowreq_ctx * rowreq_ctx){    DEBUGMSGTL(("verbose:ifTable:ifTable_rowreq_ctx_cleanup", "called\n"));    netsnmp_assert(NULL != rowreq_ctx);    /*     * TODO:211:o: |-> Perform extra ifTable rowreq cleanup.     */    if (NULL != rowreq_ctx->data.ifentry) {        netsnmp_access_interface_entry_free(rowreq_ctx->data.ifentry);        rowreq_ctx->data.ifentry = NULL;    }}                               /* ifTable_rowreq_ctx_cleanup *//** * pre-request callback * @param  user_context * * * @retval MFD_SUCCESS              : success. * @retval MFD_ERROR                : other error */intifTable_pre_request(ifTable_registration * user_context){    DEBUGMSGTL(("verbose:ifTable:ifTable_pre_request", "called\n"));    /*     * TODO:510:o: Perform ifTable pre-request actions.     */    return MFD_SUCCESS;}                               /* ifTable_pre_request *//** * post-request callback * * Note: *   New rows have been inserted into the container, and *   deleted rows have been removed from the container and *   released. * * @param user_context * @param rc : MFD_SUCCESS if all requests succeeded * * @retval MFD_SUCCESS : success. * @retval MFD_ERROR   : other error (ignored) */intifTable_post_request(ifTable_registration * user_context, int rc){    DEBUGMSGTL(("verbose:ifTable:ifTable_post_request", "called\n"));    /*     * TODO:511:o: Perform ifTable post-request actions.     */    /*     * check to set if any rows were changed.     */    if (ifTable_dirty_get()) {        /*         * check if request was successful. If so, this would be         * a good place to save data to its persistent store.         */        if (MFD_SUCCESS == rc) {            /*             * save changed rows, if you haven't already             */            snmp_store(netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,                                             NETSNMP_DS_LIB_APPTYPE));        }        ifTable_dirty_set(0);   /* clear table dirty flag */    }    return MFD_SUCCESS;}                               /* ifTable_post_request *//********************************************************************** ********************************************************************** *** *** Table ifTable *** ********************************************************************** **********************************************************************//* * IF-MIB::ifTable is subid 2 of interfaces. * Its status is Current. * OID: .1.3.6.1.2.1.2.2, length: 8 *//* * --------------------------------------------------------------------- * * TODO:200:r: Implement ifTable data context functions. *//** * set mib index(es) * * @param tbl_idx mib index structure * @param ifIndex_val * * @retval MFD_SUCCESS     : success. * @retval MFD_ERROR       : other error. * * @remark *  This convenience function is useful for setting all the MIB index *  components with a single function call. It is assume that the C values *  have already been mapped from their native/rawformat to the MIB format. */intifTable_indexes_set_tbl_idx(ifTable_mib_index * tbl_idx, long ifIndex_val){    DEBUGMSGTL(("verbose:ifTable:ifTable_indexes_set_tbl_idx",                "called\n"));    /*     * ifIndex(1)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/w/e/R/d/H      */    tbl_idx->ifIndex = ifIndex_val;    return MFD_SUCCESS;}                               /* ifTable_indexes_set_tbl_idx *//** * @internal * set row context indexes * * @param reqreq_ctx the row context that needs updated indexes * @param ifIndex_val * * @retval MFD_SUCCESS     : success. * @retval MFD_ERROR       : other error. * * @remark *  This function sets the mib indexs, then updates the oid indexs *  from the mib index. */intifTable_indexes_set(ifTable_rowreq_ctx * rowreq_ctx, long ifIndex_val){    DEBUGMSGTL(("verbose:ifTable:ifTable_indexes_set", "called\n"));    if (MFD_SUCCESS !=        ifTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx, ifIndex_val))        return MFD_ERROR;    /*     * convert mib index to oid index     */    rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx->oid_tmp) / sizeof(oid);    if (0 != ifTable_index_to_oid(&rowreq_ctx->oid_idx,                                  &rowreq_ctx->tbl_idx)) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -