📄 ssidtable.c
字号:
/* Copyright (c) 2003, Tijmen Moerland <moerland@yahoo.com> Code is licensed under the BSD license.*//*! \file SSIDTable.c \brief Implements the l80211IfaceHostAPSSIDTable table. \note This implementation has only been tested on systems with 1 SSID, but should work fine on multiple SSID interfaces. Also note that the implementation deals with GET's only. Since setting l80211IfaceDesiredSSID is the same as setting first SSID in this table, SET-ing has not been implemented here. For Wireless Leiden purposes it's not necessary. 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 "SSIDTable.h"#include "lib80211.h"long global_index, if_index;long max_index[IF_MAXNR], if_nr;char SSID[IF_MAXSSID][IF_MAXNR][IF_SSIDLEN];/** Initialize the SSIDTable table by defining its contents and how it's structured */voidinitialize_table_SSIDTable(void){ static oid SSIDTable_oid[] = {1,3,6,1,4,1,18003,2,1,1,2}; 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("SSIDTable", SSIDTable_handler, SSIDTable_oid, OID_LENGTH(SSIDTable_oid), HANDLER_CAN_RONLY); 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: l80211SSIDIndex */ 0); table_info->min_column = 2; table_info->max_column = 2; /* iterator access routines */ iinfo->get_first_data_point = SSIDTable_get_first_data_point; iinfo->get_next_data_point = SSIDTable_get_next_data_point; iinfo->table_reginfo = table_info; /*************************************************** * registering the table with the master agent */ DEBUGMSGTL(("SSIDTable", "Registering table SSIDTable as a table iterator\n")); netsnmp_register_table_iterator(my_handler, iinfo);}/** Initializes the SSIDTable module */voidinit_SSIDTable(void){ /* here we initialize all the tables we're planning on supporting */ initialize_table_SSIDTable();}netsnmp_variable_list *SSIDTable_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; int len; 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] = getNumSSIDs(getNameIf80211(j+1, buf)); *my_loop_context = (void *) &global_index; *my_data_context = (void *) SSID[global_index-1][if_index-1]; getSSID(getNameIf80211(if_index, buf), global_index-1, SSID[global_index-1][if_index-1], &len); DEBUGMSGTL(("SSIDTable", "SSID[%ld][%ld]=%s\n", global_index-1, if_index-1, SSID[global_index-1][if_index-1])); 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 *SSIDTable_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; int len; char buf[IF_NAMELEN]; 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 *) SSID[global_index-1][if_index-1]; getSSID(getNameIf80211(if_index, buf), global_index-1, SSID[global_index-1][if_index-1], &len); DEBUGMSGTL(("SSIDTable", "SSID[%ld][%ld]=%s\n", global_index-1, if_index-1, SSID[global_index-1][if_index-1])); 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 SSIDTable table, if anything else needs to be done */intSSIDTable_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; char *data_ptr; long index1, index2; 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 SSIDTable table in question */ data_ptr = (char *) netsnmp_extract_iterator_context(request); if (data_ptr == NULL) { if (reqinfo->mode == MODE_GET) { 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_STR: DEBUGMSGTL(("SSIDTable", "returns for (%ld, %ld) %s\n", index1, index2, data_ptr)); snmp_set_var_typed_value(var, ASN_OCTET_STR, (u_char *) data_ptr, IF_SSIDLEN * sizeof(char)); break; default: /* We shouldn't get here */ snmp_log(LOG_ERR, "problem encountered in SSIDTable_handler: unknown column\n"); } break; default: snmp_log(LOG_ERR, "problem encountered in SSIDTable_handler: unsupported mode\n"); } } return SNMP_ERR_NOERROR;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -