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

📄 weptable.c

📁 一个学习SNMP项目:tmoerlan.
💻 C
字号:
/*	Copyright (c) 2003, Tijmen Moerland <moerland@yahoo.com>	Code is licensed under the BSD license.*//*!	\file WEPTable.c	\brief Implements the l80211IfaceWEPTable table.			Since the structure of this implementation is similar to if80211Table.c, please refer to that file.	Do note that this table is double-indexed, the first index being the wireless interface number, the second a simple increasing counter starting at one.*//* * Note: this file originally auto-generated by mib2c using *        : mib2c.iterate.conf,v 5.4 2002/09/11 22:42:04 hardaker Exp $ */#include <net-snmp/net-snmp-config.h>#include <net-snmp/net-snmp-includes.h>#include <net-snmp/agent/net-snmp-agent-includes.h>#include "WEPTable.h"#include "lib80211.h"long global_index, if_index;long max_index[IF_MAXNR], if_nr;struct WEPkey_info_s {	char key[20];	int len;};struct WEPkey_info_s WEPkey_info[IF_MAXWEPKEYS][IF_MAXNR];/** Initialize the WEPTable table by defining its contents and how it's structured */voidinitialize_table_WEPTable(void){    static oid WEPTable_oid[] = {1,3,6,1,4,1,18003,2,1,1,3};    netsnmp_table_registration_info *table_info;    netsnmp_handler_registration *my_handler;    netsnmp_iterator_info *iinfo;    /* create the table structure itself */    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);    iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);    /* if your table is read only, it's easiest to change the       HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */    my_handler = netsnmp_create_handler_registration("WEPTable",                                             WEPTable_handler,                                             WEPTable_oid,                                             OID_LENGTH(WEPTable_oid),                                             HANDLER_CAN_RWRITE);                if (!my_handler || !table_info || !iinfo)        return; /* mallocs failed */    /***************************************************     * Setting up the table's definition     */    netsnmp_table_helper_add_indexes(table_info,                                  ASN_INTEGER, /* index: ifIndex */				  ASN_INTEGER, /* index: l80211WEPIndex */                             0);    table_info->min_column = 2;    table_info->max_column = 2;    /* iterator access routines */    iinfo->get_first_data_point = WEPTable_get_first_data_point;    iinfo->get_next_data_point = WEPTable_get_next_data_point;    iinfo->table_reginfo = table_info;    /***************************************************     * registering the table with the master agent     */    DEBUGMSGTL(("WEPTable",                "Registering table WEPTable as a table iterator\n"));		     netsnmp_register_table_iterator(my_handler, iinfo);}/** Initializes the WEPTable module */voidinit_WEPTable(void){  /* here we initialize all the tables we're planning on supporting */    initialize_table_WEPTable();}netsnmp_variable_list *WEPTable_get_first_data_point(void **my_loop_context, void **my_data_context,                          netsnmp_variable_list *put_index_data,                          netsnmp_iterator_info *mydata){    netsnmp_variable_list *vptr;    global_index = 1;    if_index = 1;    if_nr = getNumIf80211();    if (if_nr <= 0)	    return NULL;    int j;    char buf[IF_NAMELEN];    for (j = 0; j < if_nr; j++)	max_index[j] = getNumWEPkeys(getNameIf80211(j + 1, buf));        *my_loop_context = (void *) &global_index;    *my_data_context = (void *) &WEPkey_info[global_index-1][if_index-1];    getWEPkey(getNameIf80211(if_index, buf), global_index-1, WEPkey_info[global_index-1][if_index-1].key, &WEPkey_info[global_index-1][if_index-1].len);    DEBUGMSGTL(("WEPTable", "WEPkey[%ld][%ld]=%s\n", global_index-1, if_index-1, WEPkey_info[global_index-1][if_index-1].key));    vptr = put_index_data;        static long ifIndex;    ifIndex = getPtrIf80211(if_index);    snmp_set_var_value(vptr, (u_char *) &ifIndex, sizeof(long));    vptr = vptr->next_variable;    snmp_set_var_value(vptr, (u_char *) &global_index, sizeof(long));    return put_index_data;}netsnmp_variable_list *WEPTable_get_next_data_point(void **my_loop_context, void **my_data_context,                         netsnmp_variable_list *put_index_data,                         netsnmp_iterator_info *mydata){    netsnmp_variable_list *vptr;    if (global_index >= max_index[if_index-1])	if (if_index >= if_nr)	    return NULL;	else {		if_index++;		global_index = 1;	}   else        global_index++;    *my_loop_context = (void *) &global_index;    *my_data_context = (void *) &WEPkey_info[global_index-1][if_index-1];    char buf[IF_NAMELEN];    getWEPkey(getNameIf80211(if_index, buf), global_index-1, WEPkey_info[global_index-1][if_index-1].key, &WEPkey_info[global_index-1][if_index-1].len);    DEBUGMSGTL(("WEPTable", "WEPkey[%ld][%ld]=%s\n", global_index-1, if_index-1, WEPkey_info[global_index-1][if_index-1].key));    vptr = put_index_data;        static long ifIndex;    ifIndex = getPtrIf80211(if_index);    snmp_set_var_value(vptr, (u_char *) &ifIndex, sizeof(long));    vptr = vptr->next_variable;    snmp_set_var_value(vptr, (u_char *) &global_index, sizeof(long));    return put_index_data;}/** handles requests for the WEPTable table, if anything else needs to be done */intWEPTable_handler(    netsnmp_mib_handler               *handler,    netsnmp_handler_registration      *reginfo,    netsnmp_agent_request_info        *reqinfo,    netsnmp_request_info              *requests) {    netsnmp_request_info *request;    netsnmp_table_request_info *table_info;    netsnmp_variable_list *var;    struct WEPkey_info_s *data_ptr;    char buf[IF_NAMELEN];    long index1, index2, index_wifi;    for(request = requests; request; request = request->next) {        var = request->requestvb;        if (request->processed != 0)            continue;        /* perform anything here that you need to do.  The request 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. */        /* the following extracts the my_data_context pointer set in           the loop functions above.  You can then use the results to           help return data for the columns of the WEPTable table in question */        data_ptr = (struct WEPkey_info_s *) netsnmp_extract_iterator_context(request);        if (data_ptr == NULL) {                netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE);                continue;            /* XXX: no row existed, if you support creation and this is a               set, start dealing with it here, else continue */        }        /* extracts the information about the table from the request */        table_info = netsnmp_extract_table_info(request);        /* table_info->colnum contains the column number requested */        /* table_info->indexes contains a linked list of snmp variable           bindings for the indexes of the table.  Values in the list           have been set corresponding to the indexes of the           request */        if (table_info==NULL) {            continue;        }	index1 = *table_info->indexes->val.integer;	index2 = *table_info->indexes->next_variable->val.integer;        switch(reqinfo->mode) {            /* the table_iterator helper should change all GETNEXTs               into GETs for you automatically, so you don't have to               worry about the GETNEXT case.  Only GETs and SETs need               to be dealt with here */            case MODE_GET:                switch(table_info->colnum) {                    case COLUMN_WEPSTR:			DEBUGMSGTL(("WEPTable", "getting WEP for (%ld, %ld): %s(%d)\n",				index1, index2, data_ptr->key, data_ptr->len));                        snmp_set_var_typed_value(var, ASN_OCTET_STR, (u_char *) data_ptr->key, data_ptr->len);                        break;                    default:                        /* We shouldn't get here */                        snmp_log(LOG_ERR, "problem encountered in WEPTable_handler: unknown column\n");                }                break;            case MODE_SET_RESERVE1:		/* this check has already been done by data_ptr == NULL *//*		if (index2 < 1 || index2 > getNumIf80211() ||			index1 < 0 || index1 >= max_index[index2-1]) {			snmp_log(LOG_ERR, "WEPTable: (%ld, %ld) is not a valid index pair\n",				index1, index2);			netsnmp_set_request_error(reqinfo, requests, SNMP_NOSUCHINSTANCE);			continue;		}*/		switch(table_info->colnum) {                    case COLUMN_WEPSTR:                        //var points to request->requestvb			if (var->type != ASN_OCTET_STR)				netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGTYPE);//			if (var->val.string == NULL)//				netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGVALUE);			if (var->val_len != 0 && var->val_len != 5 && var->val_len != 13)				//only support keys of size 40 bits and 104 bits				netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGLENGTH);			break;                    default:                        /* We shouldn't get here */                        snmp_log(LOG_ERR, "problem encountered in WEPTable_handler: unknown column\n");                }                break;	    case MODE_SET_RESERVE2:		break;	    case MODE_SET_FREE:		break;	    case MODE_SET_ACTION:		switch (table_info->colnum) {			case COLUMN_WEPSTR:				index_wifi = getWifiIndex(index1) - 1;				bzero(WEPkey_info[index2-1][index_wifi].key, sizeof(WEPkey_info[index2-1][index_wifi].key));				//copy key in our memory cache				memcpy(WEPkey_info[index2-1][index_wifi].key, var->val.string, var->val_len * sizeof(char));				//set keylength of this cache				WEPkey_info[index2-1][index_wifi].len = var->val_len;				DEBUGMSGTL(("WEPTable", "setting WEPkey for (%ld, %ld): %s(%d)\n", 					index1, index2, WEPkey_info[index2-1][index_wifi].key, var->val_len));				DEBUGMSGTL(("WEPTable", "index_wifi=%d, iface=%s\n", index_wifi, getNameIf80211(index_wifi+1, buf)));				setWEPkey(getNameIf80211(index_wifi + 1, buf), WEPkey_info[index2-1][index_wifi].key, index2-1);				break;			default:				snmp_log(LOG_ERR, "WEPTable_handler SET_ACTION: unknown column\n");		}	    case MODE_SET_COMMIT:		break;	    case MODE_SET_UNDO:		break;            default:                snmp_log(LOG_ERR, "problem encountered in WEPTable_handler: unsupported mode\n");        }    }    return SNMP_ERR_NOERROR;}

⌨️ 快捷键说明

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