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

📄 statable.c

📁 一个学习SNMP项目:tmoerlan.
💻 C
📖 第 1 页 / 共 2 页
字号:
//    DEBUGMSGTL(("staTable", "NEXT: index(%ld, %ld)\n", global_index, if_index));    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 staTable table, if anything else needs to be done */intstaTable_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 staInfo *data_ptr;	// longs are for casting purposes	static long l_ret;	static u_long ul_ret;	static long index;	long index1, index2;	char buf[IF_NAMELEN];	struct timeval now;	        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 staTable table in question */        data_ptr = (struct staInfo *) 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://		DEBUGMSGTL(("staTable", "MODE_GET: column %d\n", //				table_info->colnum));		switch(table_info->colnum) {                    case COLUMN_STAINDEX:			index = data_ptr->index;                        snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &index, sizeof(long));                        break;		    case COLUMN_STAMAC:                        snmp_set_var_typed_value(var, ASN_OCTET_STR, (u_char *) data_ptr->cache->macsrc, 6);                        break;		    		    case COLUMN_STAASSOC:                        snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &data_ptr->assoc, sizeof(long));                        break;					    case COLUMN_STAAUTH:                        snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &data_ptr->auth, sizeof(long));                        break;					    case COLUMN_STADELETE:			//always false			ul_ret = 2;			snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &ul_ret, sizeof(u_long));			break;		    case COLUMN_STADISASSOC:			//again, always false			ul_ret = 2;			snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &ul_ret, sizeof(u_long));			break;                    case COLUMN_STAINPKTS:                        snmp_set_var_typed_value(var, ASN_COUNTER, (u_char *) &data_ptr->cache->rcvpkts, sizeof(u_long));                        break;		    case COLUMN_STAINBYTES:			snmp_set_var_typed_value(var, ASN_COUNTER, (u_char *) &data_ptr->cache->rcvbytes, sizeof(u_long));			break;		    case COLUMN_STAOUTPKTS:			snmp_set_var_typed_value(var, ASN_COUNTER, (u_char *) &data_ptr->cache->sndpkts, sizeof(u_long));			break;		    case COLUMN_STAOUTBYTES:			snmp_set_var_typed_value(var, ASN_COUNTER, (u_char *) &data_ptr->cache->sndbytes, sizeof(u_long));			break;		    case COLUMN_STAAVGINBANDWIDTH:			/* because of the volatility of this variable			we safely save it to our own static u_long 			oh, and it's a float too*/			l_ret = (long) data_ptr->cache->EWMAInBandwidth;			snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &l_ret, sizeof(long));			break;				     case COLUMN_STAAVGOUTBANDWIDTH:			/* because of the volatility of this variable			we safely save it to our own static u_long 			oh, and it's a float too*/			l_ret = (long) data_ptr->cache->EWMAOutBandwidth;			snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &l_ret, sizeof(long));			break;		    case COLUMN_STADEVINBANDWIDTH:			/* because of the volatility of this variable			we safely save it to our own static u_long 			oh, and it's a float too*/			l_ret = (long) data_ptr->cache->devInBandwidth;			snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &l_ret, sizeof(long));			break;				    case COLUMN_STADEVOUTBANDWIDTH:			/* because of the volatility of this variable			we safely save it to our own static u_long 			oh, and it's a float too*/			l_ret = (long) data_ptr->cache->devOutBandwidth;			snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &l_ret, sizeof(long));			break;                    case COLUMN_STAAVGSIGNAL:			l_ret = (long) data_ptr->cache->EWMAvg[0];                        snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &l_ret, sizeof(long));                        break;                    case COLUMN_STAAVGNOISE:			l_ret = (long) data_ptr->cache->EWMAvg[1];                        snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &l_ret, sizeof(long));                        break;                    case COLUMN_STAAVGQUALITY:			l_ret = (long) data_ptr->cache->EWMAvg[2];                        snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &l_ret, sizeof(long));                        break;		    case COLUMN_STADEVSIGNAL:			l_ret = (long) data_ptr->cache->deviation[0];                        snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &l_ret, sizeof(long));                        break;                    case COLUMN_STADEVNOISE:			l_ret = (long) data_ptr->cache->deviation[1];                        snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &l_ret, sizeof(long));                        break;                    case COLUMN_STADEVQUALITY:			l_ret = (long) data_ptr->cache->deviation[2];                        snmp_set_var_typed_value(var, ASN_INTEGER, (u_char *) &l_ret, sizeof(long));                        break;		    case COLUMN_STALASTASSOC:			gettimeofday(&now, NULL);			ul_ret = 100 * (now.tv_sec - data_ptr->cache->assoctime.tv_sec);			ul_ret += 0.0001 * (now.tv_usec - data_ptr->cache->assoctime.tv_usec);//			DEBUGMSGTL(("staTable", "curr time=%lu, %lu\n", tv.tv_sec, tv.tv_usec));//			DEBUGMSGTL(("staTable", "time interval=%lu\n", ul_ret));			// interval is now the time since recent association			// measured in 0.01 seconds			snmp_set_var_typed_value(var, ASN_TIMETICKS, (u_char *) &ul_ret, sizeof(u_long));			break;		    case COLUMN_STALASTDISASSOC:			gettimeofday(&now, NULL);			ul_ret = 100 * (now.tv_sec - data_ptr->cache->disassoctime.tv_sec);	                ul_ret += 0.0001 * (now.tv_usec - data_ptr->cache->disassoctime.tv_usec);//                      DEBUGMSGTL(("staTable", "curr time=%lu, %lu\n", tv.tv_sec, tv.tv_usec));//                      DEBUGMSGTL(("staTable", "time interval=%lu\n", ul_ret));                        // interval is now the time since mostrecent disassociation                        // measured in 0.01 seconds                        snmp_set_var_typed_value(var, ASN_TIMETICKS, (u_char *) &ul_ret, sizeof(u_long));	                break;		    case COLUMN_STANR_ASSOCS:			ul_ret = (u_long) data_ptr->cache->nr_assocs;			snmp_set_var_typed_value(var, ASN_COUNTER, (u_char *) &ul_ret, sizeof(u_long));                        break;                    default:                        /* We shouldn't get here */                        snmp_log(LOG_ERR, "problem encountered in staTable_handler: unknown column\n");                }                break;            case MODE_SET_RESERVE1:		/* *wi_sigitems might be a problem.....		   however we rely on the check data_ptr == NULL above		   anyway *//*		if (index2 < 1 || index2 > getNumIf80211() ||			index1 < 1 || index1 > *wi_sigitems) {			snmp_log(LOG_ERR, "staTable: invalid index (%ld, %ld)\n", index1, index2);			netsnmp_set_request_error(reqinfo, requests, SNMP_NOSUCHINSTANCE);		}*/                /* set handling... */		switch (table_info->colnum) {			case COLUMN_STADELETE:			case COLUMN_STADISASSOC://				DEBUGMSGTL(("staTable", "SET_RESERVE1: staDelete\n"));				//var points to request->requestvb				if (getPortType(getIfName(index1, buf)) != 6) {					//can't do if not hostap					snmp_log(LOG_ERR, "can't do disassoc/delete station when not in HostAP\n");					netsnmp_set_request_error(reqinfo, request, SNMP_ERR_GENERR);				}				if (var->type != ASN_INTEGER)					netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGTYPE);				int val = *(var->val.integer);				if (val < 1 || val > 2)					netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGVALUE);				break;			default:				snmp_log(LOG_ERR, "staTable_handler SET_RESERVE1: unknown column (probably readonly)\n");				netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_READONLY);		}		break;	    case MODE_SET_RESERVE2:		break;	    case MODE_SET_FREE:		break;	    case MODE_SET_ACTION:		switch (table_info->colnum) {			case COLUMN_STADELETE:				DEBUGMSGTL(("staTable", "SET_ACTION: staDelete\n"));				DEBUGMSGTL(("staTable", "for MAC %x:%x:%x\n", data_ptr->cache->macsrc[3]&0xff,					data_ptr->cache->macsrc[4]&0xff, data_ptr->cache->macsrc[5]&0xff));				if (*(var->val.integer) == 1)	//true					setStaDelete(getNameIf80211(getWifiIndex(index1), buf), data_ptr->cache->macsrc);				break;			case COLUMN_STADISASSOC:				DEBUGMSGTL(("staTable", "SET_ACTION: staDisassoc\n"));				if (*(var->val.integer) == 1)	//true					setStaDisassoc(getNameIf80211(getWifiIndex(index1), buf), data_ptr->cache->macsrc);				//DEBUGMSGTL(("staTable", "survived...\n"));				break;			default:				snmp_log(LOG_ERR, "staTable_handler SET_ACTION: unknown column\n");		}	    case MODE_SET_COMMIT:		break;	    case MODE_SET_UNDO:		break;            default:                snmp_log(LOG_ERR, "problem encountered in staTable_handler: unsupported mode\n");        }    }    return SNMP_ERR_NOERROR;}

⌨️ 快捷键说明

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