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

📄 nslogging.c

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <net-snmp/net-snmp-config.h>#include <net-snmp/net-snmp-includes.h>#include <net-snmp/agent/net-snmp-agent-includes.h>#include <net-snmp/agent/scalar.h>#ifdef HAVE_STRING_H#include <string.h>#else#include <strings.h>#endif#include <net-snmp/library/snmp_logging.h>#include "agent/nsLogging.h"#include "util_funcs.h"/* * OID and columns for the logging table. */#define  NSLOGGING_TYPE		3#define  NSLOGGING_MAXLEVEL	4#define  NSLOGGING_STATUS	5oid nsLoggingTable_oid[]      = { 1, 3, 6, 1, 4, 1, 8072, 1, 7, 2, 1};voidinit_nsLogging(void){    netsnmp_table_registration_info *table_info;    netsnmp_iterator_info           *iinfo;    /*     * Register the table.     * We need to define the column structure and indexing....     */    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);    if (!table_info) {        return;    }    netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER,                                                 ASN_PRIV_IMPLIED_OCTET_STR, 0);    table_info->min_column = NSLOGGING_TYPE;    table_info->max_column = NSLOGGING_STATUS;    /*     * .... and the iteration information ....     */    iinfo      = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);    if (!iinfo) {        return;    }    iinfo->get_first_data_point = get_first_logging_entry;    iinfo->get_next_data_point  = get_next_logging_entry;    iinfo->table_reginfo        = table_info;    /*     * .... and register the table with the agent.     */    netsnmp_register_table_iterator(        netsnmp_create_handler_registration(            "tzLoggingTable", handle_nsLoggingTable,            nsLoggingTable_oid, OID_LENGTH(nsLoggingTable_oid),            HANDLER_CAN_RWRITE),        iinfo);}/* * nsLoggingTable handling */netsnmp_variable_list *get_first_logging_entry(void **loop_context, void **data_context,                      netsnmp_variable_list *index,                      netsnmp_iterator_info *data){    long temp;    netsnmp_log_handler  *logh_head = get_logh_head();    if ( !logh_head )        return NULL;    temp = logh_head->priority;    snmp_set_var_value(index, (u_char*)&temp,		                 sizeof(temp));    if ( logh_head->token )        snmp_set_var_value(index->next_variable, (const u_char*)logh_head->token,		                                   strlen(logh_head->token));    else        snmp_set_var_value(index->next_variable, NULL, 0);    *loop_context = (void*)logh_head;    *data_context = (void*)logh_head;    return index;}netsnmp_variable_list *get_next_logging_entry(void **loop_context, void **data_context,                      netsnmp_variable_list *index,                      netsnmp_iterator_info *data){    long temp;    netsnmp_log_handler *logh = (netsnmp_log_handler *)*loop_context;    logh = logh->next;    if ( !logh )        return NULL;    temp = logh->priority;    snmp_set_var_value(index, (u_char*)&temp,		                 sizeof(temp));    if ( logh->token )        snmp_set_var_value(index->next_variable, (const u_char*)logh->token,		                                   strlen(logh->token));    else        snmp_set_var_value(index->next_variable, NULL, 0);    *loop_context = (void*)logh;    *data_context = (void*)logh;    return index;}inthandle_nsLoggingTable(netsnmp_mib_handler *handler,                netsnmp_handler_registration *reginfo,                netsnmp_agent_request_info *reqinfo,                netsnmp_request_info *requests){    long temp;    netsnmp_request_info       *request     = NULL;    netsnmp_table_request_info *table_info  = NULL;    netsnmp_log_handler        *logh        = NULL;    netsnmp_variable_list      *idx         = NULL;    switch (reqinfo->mode) {    case MODE_GET:        for (request=requests; request; request=request->next) {            if (requests->processed != 0)                continue;            logh = (netsnmp_log_handler*)netsnmp_extract_iterator_context(request);            table_info  =                netsnmp_extract_table_info(request);            switch (table_info->colnum) {            case NSLOGGING_TYPE:                if (!logh) {                    netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);                    continue;		}		temp = logh->type;	        snmp_set_var_typed_value(request->requestvb, ASN_INTEGER,                                         (u_char*)&temp,                                            sizeof(temp));	        break;            case NSLOGGING_MAXLEVEL:                if (!logh) {                    netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);                    continue;		}		temp = logh->pri_max;	        snmp_set_var_typed_value(request->requestvb, ASN_INTEGER,                                         (u_char*)&temp,                                            sizeof(temp));	        break;            case NSLOGGING_STATUS:                if (!logh) {                    netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);                    continue;		}		temp = (logh->type ?	                   (logh->enabled ?	                      RS_ACTIVE:	                      RS_NOTINSERVICE) :	                    RS_NOTREADY);	        snmp_set_var_typed_value(request->requestvb, ASN_INTEGER,                                         (u_char*)&temp, sizeof(temp));	        break;            default:                netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHOBJECT);                continue;	    }	}	break;    case MODE_SET_RESERVE1:        for (request=requests; request; request=request->next) {            if ( request->status != 0 ) {                return SNMP_ERR_NOERROR;	/* Already got an error */            }            logh = (netsnmp_log_handler*)netsnmp_extract_iterator_context(request);            table_info  =                 netsnmp_extract_table_info(request);            switch (table_info->colnum) {            case NSLOGGING_TYPE:                if ( request->requestvb->type != ASN_INTEGER ) {                    netsnmp_set_request_error(reqinfo, request, SNMP_ERR_WRONGTYPE);                    return SNMP_ERR_WRONGTYPE;                }                if (*request->requestvb->val.integer < 0 ) {                    netsnmp_set_request_error(reqinfo, request, SNMP_ERR_WRONGVALUE);                    return SNMP_ERR_WRONGVALUE;                }		/*		 * It's OK to create a new logging entry		 *  (either in one go, or built up using createAndWait)		 *  but it's not possible to change the type of an entry		 *  once it's been created.		 */                if (logh && logh->type) {                    netsnmp_set_request_error(reqinfo, request, SNMP_ERR_NOTWRITABLE);                    return SNMP_ERR_NOTWRITABLE;		}	        break;            case NSLOGGING_MAXLEVEL:                if ( request->requestvb->type != ASN_INTEGER ) {                    netsnmp_set_request_error(reqinfo, request, SNMP_ERR_WRONGTYPE);                    return SNMP_ERR_WRONGTYPE;                }                if (*request->requestvb->val.integer < 0 ||                    *request->requestvb->val.integer > 7 ) {                    netsnmp_set_request_error(reqinfo, request, SNMP_ERR_WRONGVALUE);                    return SNMP_ERR_WRONGVALUE;                }	        break;            case NSLOGGING_STATUS:

⌨️ 快捷键说明

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