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

📄 vendor.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 "vendor.h"Vendor:: Vendor(){	#ifdef DEBUG_VENDOR		printf("Calling Vendor::Vendor()...\n");	#endif	read_file("/usr/share/airfart/manuf");	//print_vendor_vector();}Vendor:: ~Vendor() {	// I hope there aren't any memory leaks}int Vendor:: read_file(char* filename){	#ifdef DEBUG_VENDOR		printf("Calling Vendor::read_file()...\n");	#endif	/*		This method reads in the ethereal manuf file. It loads them into a vector for		future access.		If you have a better way of doing this, please code it up and send us the changes; 		this should work for now...			Clean this puppy up!	*/	ifstream infile(filename, ios::in);	char line_string[80];	char* token_ptr;	int i = 0;	Vendor_Struct* tmp_vendor_struct;	if (!infile) {		printf("File not found: %s",filename);		return 0;	}	// Read in file, line by line	while (!infile.eof()) {		infile.getline(line_string, 80);					// Get rid of comments		if (line_string[0] != '#' && line_string[0] != NULL)		{			// Create a new Vendor_Struct			tmp_vendor_struct = new Vendor_Struct();						// Pull out ethaddr			token_ptr = strtok(line_string, "\t");			memcpy(tmp_vendor_struct->macaddr, token_ptr, 8);						// Pull out vendor info			token_ptr = strtok(NULL, "\t");			tmp_vendor_struct->vendor_name = strdup(token_ptr);			// Now add it to the vector			vendor_vector.push_back(tmp_vendor_struct);		}		i++;	}	#ifdef DEBUG_VENDOR		printf("Done reading in file...\n");	#endif	infile.close();	return 1;}void Vendor:: print_vendor_vector(){	#ifdef DEBUG_VENDOR		printf("Calling Vendor::print_vendor_vector()...\n");	#endif	/*		This is used for debugging purposes	*/	for (int i = 0; i < vendor_vector.size(); i++)	{		printf("macaddr: %s\t vendor info: %s\n", vendor_vector[i]->macaddr, vendor_vector[i]->vendor_name);	}}char* Vendor:: get_vendor_info(unsigned char* ethaddr){	#ifdef DEBUG_VENDOR		printf("Calling Vendor::get_vendor_info()...\n");	#endif	/*		Pull out the vendor info string for using a modified version		of ethaddr.	*/	char* new_ethaddr = new char[8];	sprintf(new_ethaddr,"%02x:%02x:%02x", ethaddr[0], ethaddr[1], ethaddr[2]);	#ifdef DEBUG_VENDOR		printf("new_ethaddr = %s\n",new_ethaddr);	#endif	///////////////////	// Now go through the vector and find the match; if not found return the string "unknown"	for (int i = 0; i < vendor_vector.size(); i++) {		if (memcmp(new_ethaddr,vendor_vector[i]->macaddr,8) == 0)		{			#ifdef DEBUG_VENDOR 				printf("It matched!!! %s\n", vendor_vector[i]->vendor_name);			#endif							return vendor_vector[i]->vendor_name;		}	}		return "unknown";		delete new_ethaddr;}

⌨️ 快捷键说明

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