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

📄 mapi.c

📁 MAPI: API for wireless cards under Linux 提供wireless的API函数。大家可以通过这个程序
💻 C
📖 第 1 页 / 共 4 页
字号:
			printf("%gGb/s", Info->bitrate.value / GIGA);		else			if(Info->bitrate.value >= MEGA)				printf("%gMb/s", Info->bitrate.value / MEGA);			else				printf("%gkb/s", Info->bitrate.value / KILO);			printf("   ");    }		/* Display the RTS threshold */	if(Info->has_rts)    {		/* Disabled ? */		if(Info->rts.disabled)			printf("RTS thr:off   ");		else		{			/* Fixed ? */			if(Info->rts.fixed)				printf("RTS thr=");			else				printf("RTS thr:");						printf("%d B   ", Info->rts.value);		}    }		/* Display the fragmentation threshold */	if(Info->has_frag)    {		/* Disabled ? */		if(Info->frag.disabled)			printf("Fragment thr:off   ");		else		{			/* Fixed ? */			if(Info->frag.fixed)				printf("Fragment thr=");			else				printf("Fragment thr:");						printf("%d B   ", Info->frag.value);		}    }		/* Formating */	if((Info->has_bitrate) || (Info->has_rts) || (Info->has_bitrate))		printf("\n          ");		/* Display encryption information */	/* Note : we display only the "current" key, use iwspy to list all keys */	if(Info->has_key)    {		printf("Encryption key:");		if((Info->key_flags & IW_ENCODE_DISABLED) || (Info->key_size == 0))			printf("off\n          ");		else		{			int	i;						printf("%.2X", Info->key[0]);			for(i = 1; i < Info->key_size; i++)			{				if((i & 0x1) == 0)					printf("-");				printf("%.2X", Info->key[i]);			}						/* Other Info... */			if((Info->key_flags & IW_ENCODE_INDEX) > 1)				printf(" [%d]", Info->key_flags & IW_ENCODE_INDEX);			if(Info->key_flags & IW_ENCODE_RESTRICTED)				printf("   Encryption mode:restricted");			if(Info->key_flags & IW_ENCODE_OPEN)				printf("   Encryption mode:open");			printf("\n          ");		}    }		/* Display Power Management information */	/* Note : we display only one parameter, period or timeout. If a device	* (such as HiperLan) has both, we would need to be a bit more clever... */	if(Info->has_power)	/* I hope the device has power ;-) */    { 		printf("Power Management");		/* Disabled ? */		if(Info->power.disabled)			printf(":off\n          ");		else		{			/* Let's check the value and its type */			if(Info->power.flags & IW_POWER_TYPE)			{				/* Type */				if(Info->power.flags & IW_POWER_TIMEOUT)					printf(" timeout:");				else					printf(" period:");								/* Display value with units */				if(Info->power.value >= (int) MEGA)					printf("%gs  ", ((double) Info->power.value) / MEGA);				else					if(Info->power.value  >= (int) KILO)						printf("%gms  ", ((double) Info->power.value) / KILO);					else						printf("%dus  ", Info->power.value);			}						/* Let's check the mode */			switch(Info->power.flags & IW_POWER_MODE)			{			case IW_POWER_UNICAST_R:				printf(" mode:Unicast received");				break;			case IW_POWER_MULTICAST_R:				printf(" mode:Multicast received");				break;			case IW_POWER_ALL_R:				printf(" mode:All packets received");				break;			case IW_POWER_FORCE_S:				printf(" mode:Force sending");				break;			case IW_POWER_REPEATER:				printf(" mode:Repeat multicasts");				break;			default:			}						/* Let's check if nothing (simply on) */			if(Info->power.flags == IW_POWER_ON)				printf(":on");			printf("\n          ");		}    }		if(Info->has_stats)    {		if(Info->has_range && (Info->stats.qual.level != 0))			/* If the statistics are in dBm */			if(Info->stats.qual.level > Info->range.max_qual.level)				printf("Link quality:%d/%d  Signal level:%d dBm  Noise level:%d dBm\n",				Info->stats.qual.qual, Info->range.max_qual.qual,				Info->stats.qual.level - 0x100,				Info->stats.qual.noise - 0x100);			else				/* Statistics are relative values (0 -> max) */				printf("Link quality:%d/%d  Signal level:%d/%d  Noise level:%d/%d\n",				Info->stats.qual.qual, Info->range.max_qual.qual,				Info->stats.qual.level, Info->range.max_qual.level,				Info->stats.qual.noise, Info->range.max_qual.noise);			else				/* We can't read the range, so we don't know... */				printf("Link quality:%d  Signal level:%d  Noise level:%d\n",				Info->stats.qual.qual,				Info->stats.qual.level,				Info->stats.qual.noise);						printf("          Rx invalid nwid:%d  invalid crypt:%d  invalid misc:%d\n",				Info->stats.discard.nwid,				Info->stats.discard.code,				Info->stats.discard.misc);    }		printf("\n");}/*------------------------------------------------------------------*//** Print on the screen in a neat fashion all the Info we have collected* on a device. MOS * Get Frequency *  Input: 		- InterfaceName: Interface name (e.g. eth0) 	Output: 		- None*/void PrintInfo(char* InterfaceName){	struct wireless_info	Info;		if(GetInterfaceInfo(InterfaceName, &Info) < 0)    {		fprintf(stderr, "%-8.8s  no wireless extensions.\n\n",			InterfaceName);		return;    }		/* Display it ! */	DisplayInfo(InterfaceName, &Info);}/*------------------------------------------------------------------*/ /* * Get Info on all devices and print it on the screen */ void PrintDevices() { 	char buff[1024]; 	struct ifconf ifc; 	struct ifreq *ifr; 	int i; 	 	/* Get list of active devices */ 	ifc.ifc_len = sizeof(buff); 	ifc.ifc_buf = buff; 	if(ioctl(SocketFileDescriptor, SIOCGIFCONF, &ifc) < 0)     { 		fprintf(stderr, "SIOCGIFCONF: %s\n", strerror(errno)); 		return;     } 	ifr = ifc.ifc_req; 	 	/* Print them */ 	for(i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; ifr++) 		PrintInfo(ifr->ifr_name); }  /*------------------------------------------------------------------*/ /* * MOS * Get All network interfaces names * Input: *	- None * Output: *	- Names: A list of interface names separated by the new line character *	- Number: Number of Interfaces found */ void GetNetworkInterfacesNames(char* Names, int* Number) { 	char buff[1024]; 	struct ifconf ifc; 	struct ifreq *ifr; 	int i; 	 	/* Get list of active devices */ 	ifc.ifc_len = sizeof(buff); 	ifc.ifc_buf = buff; 	if(ioctl(SocketFileDescriptor, SIOCGIFCONF, &ifc) < 0)     { 		fprintf(stderr, "SIOCGIFCONF: %s\n", strerror(errno)); 		return;     } 	ifr = ifc.ifc_req; 	 	/* Return them */ 	*Number= 0; 	Names[0]= '\0';  	for(i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; ifr++){ 		strcat(Names, ifr->ifr_name); 		strcat(Names, "\n"); 		(*Number)++; 	} }  /*------------------------------------------------------------------*/ /* * MOS * Get Wireless network interfaces names * Input: *	- None * Output: *	- Names: A list of wireless interface names separated by the new line character *	- Number: Number of wireless interfaces found */ void GetWirelessInterfacesNames(char* Names, int* Number) { 	char buff[1024]; 	struct ifconf ifc; 	struct ifreq *ifr; 	int i; 	 	/* Get list of active devices */ 	ifc.ifc_len = sizeof(buff); 	ifc.ifc_buf = buff; 	if(ioctl(SocketFileDescriptor, SIOCGIFCONF, &ifc) < 0)     { 		fprintf(stderr, "SIOCGIFCONF: %s\n", strerror(errno)); 		return;     } 	ifr = ifc.ifc_req; 	 	/* Return them */ 	*Number= 0; 	Names[0]= '\0';  	for(i = ifc.ifc_len / sizeof(struct ifreq); --i >= 0; ifr++){ 		struct iwreq wrq; 		/* Get wireless name */ 		strcpy(wrq.ifr_name, ifr->ifr_name);  		if(ioctl(SocketFileDescriptor, SIOCGIWNAME, &wrq) < 0) 			/* If no wireless name : no wireless extensions */ 			continue; 		strcat(Names, ifr->ifr_name); 		strcat(Names, "\n"); 		(*Number)++; 	} } /* * Print in a file in a neat fashion all the statistics we have collected * on an interface. *  MOS  *  Input:                 - F: File to output to.		- InterfaceName: Interface name (e.g. eth0) 		- Stats: Statistics collected.	Output: 		- None 	 */ void DisplayStatFile(FILE* F, char*	InterfaceName, iwstats*	Stats) {   iwrange	Range;  int		HasRange = 0;   /* Get range info if we can */  if(get_range_info(SocketFileDescriptor, InterfaceName, &(Range)) >= 0)    HasRange = 1;  	if(Stats->qual.level != 0){ 	  /*  If the statistics are in dBm */   	if(Stats->qual.level > Range.max_qual.level) 			fprintf(F, "Link quality:%d/%d  Signal level:%d dBm  Noise level:%d dBm\n", 			Stats->qual.qual, Range.max_qual.qual, 			Stats->qual.level - 0x100, 			Stats->qual.noise - 0x100); 		else 		  /* Statistics are relative values (0 -> max) */ 			fprintf(F, "Link quality:%d/%d  Signal level:%d/%d  Noise level:%d/%d\n", 			Stats->qual.qual, Range.max_qual.qual, 			Stats->qual.level, Range.max_qual.level, 			Stats->qual.noise, Range.max_qual.noise);  	} 	else      		/* We can't read the range, so we don't know... */ 		fprintf(F, "Link quality:%d  Signal level:%d  Noise level:%d\n", 		Stats->qual.qual, 		Stats->qual.level, 		Stats->qual.noise); 		 	fprintf(F," Rx invalid nwid:%d  invalid crypt:%d  invalid misc:%d\n", 		Stats->discard.nwid, 		Stats->discard.code, 		Stats->discard.misc); } /* * Print on the screen in a neat fashion all the statistics we have collected * on an interface. *  MOS  *  Input: 		- InterfaceName: Interface name (e.g. eth0) 		- Stats: Statistics collected.	Output: 		- None 	*/ void DisplayStat(char*	InterfaceName, iwstats*	Stats) {   iwrange	Range;  int		HasRange = 0;   /* Get range info if we can */  if(get_range_info(SocketFileDescriptor, InterfaceName, &(Range)) >= 0)    HasRange = 1;  	if(Stats->qual.level != 0){ 	  /*  If the statistics are in dBm */   	if(Stats->qual.level > Range.max_qual.level) 			printf("Link quality:%d/%d  Signal level:%d dBm  Noise level:%d dBm\n", 			Stats->qual.qual, Range.max_qual.qual, 			Stats->qual.level - 0x100, 			Stats->qual.noise - 0x100); 		else 		  /* Statistics are relative values (0 -> max) */ 			printf("Link quality:%d/%d  Signal level:%d/%d  Noise level:%d/%d\n", 			Stats->qual.qual, Range.max_qual.qual, 			Stats->qual.level, Range.max_qual.level, 			Stats->qual.noise, Range.max_qual.noise);  	} 	else      		/* We can't read the range, so we don't know... */ 		printf("Link quality:%d  Signal level:%d  Noise level:%d\n", 		Stats->qual.qual, 		Stats->qual.level, 		Stats->qual.noise); 		 	printf("          Rx invalid nwid:%d  invalid crypt:%d  invalid misc:%d\n", 		Stats->discard.nwid, 		Stats->discard.code, 		Stats->discard.misc); } /************************* SETTING ROUTINES **************************//* * Same as iwspy command line */intSetInfo(char *		InterfaceName,	/* Dev name */ 	char *		Args[],	        /* Command line Args */	int		Count)		/* Args Count */{	struct iwreq wrq;	int	i;		/* Set dev name */	strncpy(wrq.ifr_name, InterfaceName, IFNAMSIZ);		/* if nothing after the device name */	if(Count<1) ;	  //iw_usage();		/* The other Args on the line specify options to be set... */	for(i = 0; i < Count; i++)    {		/* ---------- Set network ID ---------- */		if((!strcasecmp(Args[i], "nwid")) ||			(!strcasecmp(Args[i], "domain")))		{			i++;			if(i >= Count) ;				//iw_usage();			if((!strcasecmp(Args[i], "off")) ||				(!strcasecmp(Args[i], "any")))				wrq.u.nwid.disabled = 1;			else				if(!strcasecmp(Args[i], "on"))				{					/* Get old nwid */					if(ioctl(SocketFileDescriptor, SIOCGIWNWID, &wrq) < 0)					{						fprintf(stderr, "SIOCGIWNWID: %s\n", strerror(errno));						return(-1);					}					strcpy(wrq.ifr_name, InterfaceName);					wrq.u.nwid.disabled = 0;				}				else					if(sscanf(Args[i], "%lX", (unsigned long *) &(wrq.u.nwid.value))					   != 1) ;			// iw_usage();					else						wrq.u.nwid.disabled = 0;					wrq.u.nwid.fixed = 1;										if(ioctl(SocketFileDescriptor, SIOCSIWNWID, &wrq) < 0)					{						fprintf(stderr, "SIOCSIWNWID: %s\n", strerror(errno));						return(-1);					}					continue;		}				/* ---------- Set frequency / channel ---------- */		if((!strncmp(Args[i], "freq", 4)) ||			(!strcmp(Args[i], "channel")))		{			double		freq;						if(++i >= Count) ;				// iw_usage();			if(sscanf(Args[i], "%lg", &(freq)) != 1) ;				// iw_usage();			if(index(Args[i], 'G')) freq *= GIGA;			if(index(Args[i], 'M')) freq *= MEGA;			if(index(Args[i], 'k')) freq *= KILO;						float2freq(freq, &(wrq.u.freq));						if(ioctl(SocketFileDescriptor, SIOCSIWFREQ, &wrq) < 0)			{				fprintf(stderr, "SIOCSIWFREQ: %s\n", strerror(errno));				return(-1);			}			continue;		}				/* ---------- Set sensitivity ---------- */		if(!strncmp(Args[i], "sens", 4))		{		  if(++i >= Count) ;

⌨️ 快捷键说明

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