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

📄 stats.cpp

📁 AirFart监听 802.11流量
💻 CPP
字号:
/*   This file is part of AirFart.   AirFart is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.   AirFart is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with AirFart; if not, write to the Free Software   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#include "stats.h"Stats:: Stats(){	#ifdef DEBUG_STATS		printf("Creating Stats Object...\n");	#endif		// The vendor object is used to identify the device manufacturer	vendor = new Vendor();	use_gui = true;  // We use the GUI by default}Stats:: ~Stats(){	// I hope there aren't any memory leaks	// Delete all the Address objects	for (int i = 0; i < address_vector.size(); i++) {		delete address_vector[i];	}}void print_eth_addr( unsigned char *eth_addr ){	// Debug function	printf( "%x:%x:%x:%x:%x:%x",		eth_addr[0],eth_addr[1],eth_addr[2],		eth_addr[3],eth_addr[4],eth_addr[5] );}void Stats:: add_packet(unsigned char* ethaddr, char* ssid, int strength){	#ifdef DEBUG_STATS		printf("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");		printf("Calling Stats::add_packet()...\n");	#endif			/*		Add the MAC address to the vector if this is the first packet 		from that address; if it has already been detected add this		packet's stats to the address object		*/	// See if we have already received data from this address, if not it needs	// to be added	int address_index = find_address(ethaddr);	if (address_index == NOT_FOUND) 	{		#ifdef DEBUG_STATS			printf("MAC Address not found in list; adding to list...\n");		#endif		// First find the manufacturer of the device		char* vendor_info = vendor->get_vendor_info(ethaddr);					Address* new_packet = new Address(ethaddr,ssid,vendor_info);		// Set the signal strength of this first packet		new_packet->add_strength(strength);		address_vector.push_back(new_packet);		// Dave hacked this in as a temporary fix. Evan: FIXME		address_index = find_address( ethaddr );	} else {		#ifdef DEBUG_STATS			printf("MAC Address found in list at %d...\n", address_index);		#endif				// The MAC address has already sent a packet in the past; now		// just add another signal strength to the queue				address_vector[address_index]->add_strength(strength);	}	#ifdef DEBUG_STATS		printf("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");	#endif	#ifdef PRINT_AVERAGES		print_addresses();	#endif	if (use_gui)	{		gdk_threads_enter();		update_gui(ethaddr, address_vector[address_index]->get_ssid(), vendor->get_vendor_info(ethaddr), address_vector[address_index]->get_packet_count());		gdk_flush();		gdk_threads_leave();	}	else	{		// If we're not using the GUI just print out the address list		print_addresses();	}}void Stats:: print_addresses() {	printf("-----------------------------------\n");			for (int i = 0; i < address_vector.size(); i++) 	{		printf( "MAC Address: " );		print_eth_addr( address_vector[i]->get_macaddr() );		printf( "\tSSID: %s\t", address_vector[i]->get_ssid());		printf("Vendor: %s\n", address_vector[i]->get_vendor_info());		address_vector[i]->print_strengths();	}}int Stats:: find_address(unsigned char* newaddr) {	#ifdef DEBUG_STATS		printf("\nCalling Stats::find_address()...\n");	#endif			/*		See if this MAC address has already been detected; if it		has, return the index in the vector; if not return NOT_FOUND	*/	#ifdef DEBUG_STATS		printf("Vector size is: %d\n", address_vector.size());	#endif	for (int i = 0; i < address_vector.size(); i++)	{		#ifdef DEBUG_STATS			printf("i = %d\n", i);				printf("Macaddr is: %s\n",address_vector[i]->get_macaddr());		#endif				if( memcmp(newaddr, address_vector[i]->get_macaddr(),6) == 0) 		{			#ifdef DEBUG_STATS				printf("Addresses match\n");			#endif			return i;		} else {			#ifdef DEBUG_STATS				printf("Addresses do not match\n");			#endif		}		}		// Address was not found	return NOT_FOUND;}void Stats:: update_gui(unsigned char* ethaddr, char* ssid, char* vendor_id, int packet_count) {	#ifdef DEBUG_STATS		printf("\nCalling Stats::update_gui()...\n");	#endif	/*		Everytime there is an update (new packets in, etc) call the GUI and tell it of the		changes in the averages	*/	// Calc new averages	int strength = address_vector[find_address(ethaddr)]->calc_avg();		// Call the GUI	update_treeview(ethaddr,ssid,vendor_id, strength, packet_count);}void Stats:: unset_use_gui() {	#ifdef DEBUG_STATS		printf("\nCalling Stats::unset_use_gui()...\n");	#endif	/*		This is called to set the use_gui flag to false; if this flag is set it won't		call the GUI for updates		*/	use_gui = false;}

⌨️ 快捷键说明

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