📄 iftable.c
字号:
/* * Note: this file originally auto-generated by mib2c using * version : 1.32 $ of : mfd-top.m2c,v $ * * $Id: ifTable.c,v 1.17.2.1 2004/12/10 19:44:55 rstory Exp $ *//** \mainpage 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 <net-snmp/agent/mib_modules.h>#include "ifTable_interface.h"oid ifTable_oid[] = { IFTABLE_OID };int ifTable_oid_size = OID_LENGTH(ifTable_oid);void initialize_table_ifTable(void);/** * Initializes the ifTable module */voidinit_ifTable(void){ DEBUGMSGTL(("verbose:ifTable:init_ifTable", "called\n")); /* * TODO:300:o: Perform ifTable one-time module initialization. */ /* * here we initialize all the tables we're planning on supporting */ if (should_init("ifTable")) initialize_table_ifTable();} /* init_ifTable *//** * Initialize the table ifTable * (Define its contents and how it's structured) */voidinitialize_table_ifTable(void){ ifTable_registration_ptr 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);} /* initialize_table_ifTable *//** * extra context initialization * * @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. */ 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 * */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 * * * @retval MFD_SUCCESS : success. * @retval MFD_ERROR : other error */intifTable_pre_request(ifTable_registration_ptr 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 * * * @retval MFD_SUCCESS : success. * @retval MFD_ERROR : other error (ignored) */intifTable_post_request(ifTable_registration_ptr user_context){ DEBUGMSGTL(("verbose:ifTable:ifTable_post_request", "called\n")); /* * TODO:511:o: Perform ifTable pos-request actions. */ return MFD_SUCCESS;} /* ifTable_post_request *//********************************************************************** ********************************************************************** *** *** Table ifTable *** ********************************************************************** **********************************************************************//* * ifTable is subid 2 of interfaces. * Its status is Current. * OID: .1.3.6.1.2.1.2.2, length: 8 *//** * set mib index(es) * * @param tbl_idx mib index structure * * @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 * * @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)) { return MFD_ERROR; } return MFD_SUCCESS;} /* ifTable_indexes_set *//*--------------------------------------------------------------------- * IF-MIB::ifEntry.ifDescr * ifDescr is subid 2 of ifEntry. * Its status is Current, and its access level is ReadOnly. * OID: .1.3.6.1.2.1.2.2.1.2 * Description:A textual string containing information about the interface. This string should include the name of the manufacturer, the product name and the version of the interface hardware/software. * * Attributes: * accessible 1 isscalar 0 enums 0 hasdefval 0 * readable 1 iscolumn 1 ranges 1 hashint 1 * settable 0 * hint: 255a * * Ranges: 0 - 255; * * Its syntax is DisplayString (based on perltype OCTETSTR) * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) * This data type requires a length. (Max 255) *//** * Extract the current value of the ifDescr data. * * Set a value using the data context for the row. * * @param rowreq_ctx * Pointer to the row request context. * @param ifDescr_val_ptr_ptr * Pointer to storage for a char variable * @param ifDescr_val_ptr_len_ptr * Pointer to a size_t. On entry, it will contain the size (in bytes) * pointed to by ifDescr. * On exit, this value should contain the data size (in bytes). * * @retval MFD_SUCCESS : success * @retval MFD_SKIP : skip this node (no value for now) * @retval MFD_ERROR : Any other error* * @note If you need more than (*ifDescr_val_ptr_len_ptr) bytes of memory, * allocate it using malloc() and update ifDescr_val_ptr_ptr. * <b>DO NOT</b> free the previous pointer. * The MFD helper will release the memory you allocate. * * @remark If you call this function yourself, you are responsible * for checking if the pointer changed, and freeing any * previously allocated memory. (Not necessary if you pass * in a pointer to static memory, obviously.) */intifDescr_get(ifTable_rowreq_ctx * rowreq_ctx, char **ifDescr_val_ptr_ptr, size_t *ifDescr_val_ptr_len_ptr){ char *tmp_descr = NULL; u_char tmp_len = 0; /** we should have a non-NULL pointer and enough storage */ netsnmp_assert((NULL != ifDescr_val_ptr_ptr) && (NULL != *ifDescr_val_ptr_ptr)); netsnmp_assert(NULL != ifDescr_val_ptr_len_ptr); DEBUGMSGTL(("verbose:ifTable:ifDescr_get", "called\n")); netsnmp_assert(NULL != rowreq_ctx); /* * if ifDescr is NULL, use the ifName */ if (NULL == rowreq_ctx->data.ifDescr) {#ifdef USING_IF_MIB_IFXTABLE_IFXTABLE_MODULE tmp_descr = rowreq_ctx->data.ifName;#else tmp_descr = NULL;#endif } else tmp_descr = rowreq_ctx->data.ifDescr; if (NULL != tmp_descr) tmp_len = strlen(tmp_descr); else tmp_len = 0; /* * TODO:231:o: |-> Extract the current value of the ifDescr data. * set (* ifDescr_val_ptr_ptr ) and (* ifDescr_val_ptr_len_ptr ) from rowreq_ctx->data */ /* * make sure there is enough space for ifDescr data */ if ((NULL == (*ifDescr_val_ptr_ptr)) || ((*ifDescr_val_ptr_len_ptr) < tmp_len)) { /* * allocate space for ifDescr data */ (*ifDescr_val_ptr_ptr) = malloc(tmp_len * sizeof((*ifDescr_val_ptr_ptr)[0])); if (NULL == (*ifDescr_val_ptr_ptr)) { snmp_log(LOG_ERR, "could not allocate memory\n"); return MFD_ERROR;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -