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

📄 wicontrol.c

📁 一个学习SNMP项目:tmoerlan.
💻 C
📖 第 1 页 / 共 2 页
字号:
			printf("* %2.1f *", res->wi_rate == 0xa ? 1 :			    (res->wi_rate == 0x14 ? 2 :			    (res->wi_rate == 0x37 ? 5.5 :			    (res->wi_rate == 0x6e ? 11 : 0))));		}		putchar('\n');	}	return;}#define WI_STRING		0x01#define WI_BOOL			0x02#define WI_WORDS		0x03#define WI_HEXBYTES		0x04#define WI_KEYSTRUCT		0x05#define WI_SWORDS		0x06#define WI_HEXWORDS		0x07#define WI_REGDOMS		0x08struct wi_table {	int			wi_code;	int			wi_type;	const char		*wi_str;};static struct wi_table wi_table[] = {	{ WI_RID_SERIALNO, WI_STRING, "NIC serial number:\t\t\t" },	{ WI_RID_NODENAME, WI_STRING, "Station name:\t\t\t\t" },	{ WI_RID_OWN_SSID, WI_STRING, "SSID for IBSS creation:\t\t\t" },	{ WI_RID_CURRENT_SSID, WI_STRING, "Current netname (SSID):\t\t\t" },	{ WI_RID_DESIRED_SSID, WI_STRING, "Desired netname (SSID):\t\t\t" },	{ WI_RID_CURRENT_BSSID, WI_HEXBYTES, "Current BSSID:\t\t\t\t" },	{ WI_RID_CHANNEL_LIST, WI_HEXWORDS, "Channel list:\t\t\t\t" },	{ WI_RID_OWN_CHNL, WI_WORDS, "IBSS channel:\t\t\t\t" },	{ WI_RID_CURRENT_CHAN, WI_WORDS, "Current channel:\t\t\t" },	{ WI_RID_COMMS_QUALITY, WI_WORDS, "Comms quality/signal/noise:\t\t" },	{ WI_RID_DBM_COMMS_QUAL, WI_SWORDS, "dBm Coms Quality:\t\t\t" },	{ WI_RID_PROMISC, WI_BOOL, "Promiscuous mode:\t\t\t" },	{ WI_RID_PROCFRAME, WI_BOOL, "Process 802.11b Frame:\t\t\t" },	{ WI_RID_PRISM2, WI_WORDS, "Intersil-Prism2 based card:\t\t" },	{ WI_RID_PORTTYPE, WI_WORDS, "Port type (1=BSS, 3=ad-hoc):\t\t"},	{ WI_RID_MAC_NODE, WI_HEXBYTES, "MAC address:\t\t\t\t"},	{ WI_RID_TX_RATE, WI_WORDS, "TX rate (selection):\t\t\t"},	{ WI_RID_CUR_TX_RATE, WI_WORDS, "TX rate (actual speed):\t\t\t"},	{ WI_RID_RTS_THRESH, WI_WORDS, "RTS/CTS handshake threshold:\t\t"},	{ WI_RID_CREATE_IBSS, WI_BOOL, "Create IBSS:\t\t\t\t" },	{ WI_RID_SYSTEM_SCALE, WI_WORDS, "Access point density:\t\t\t" },	{ WI_RID_PM_ENABLED, WI_WORDS, "Power Mgmt (1=on, 0=off):\t\t" },	{ WI_RID_MAX_SLEEP, WI_WORDS, "Max sleep time:\t\t\t\t" },	{ WI_RID_PRI_IDENTITY, WI_WORDS, "PRI Identity:\t\t\t\t" },	{ WI_RID_STA_IDENTITY, WI_WORDS, "STA Identity:\t\t\t\t" } ,	{ WI_RID_CARD_ID, WI_HEXWORDS, "Card ID register:\t\t\t" },	{ WI_RID_REG_DOMAINS, WI_REGDOMS, "Regulatory Domains:\t\t\t" },	{ WI_RID_TEMP_TYPE, WI_WORDS, "Temperature Range:\t\t\t" },#ifdef WI_EXTRA_INFO	{ WI_RID_PRI_SUP_RANGE, WI_WORDS, "PRI Sup Range:\t\t\t\t" },	{ WI_RID_CIF_ACT_RANGE, WI_WORDS, "CFI Act Sup Range:\t\t\t" },	{ WI_RID_STA_SUP_RANGE, WI_WORDS, "STA Sup Range:\t\t\t\t" } ,	{ WI_RID_MFI_ACT_RANGE, WI_WORDS, "MFI Act Sup Range:\t\t\t" } ,#endif	{ 0, 0, NULL }};static struct wi_table wi_crypt_table[] = {	{ WI_RID_ENCRYPTION, WI_BOOL, "WEP encryption:\t\t\t\t" },	{ WI_RID_TX_CRYPT_KEY, WI_WORDS, "TX encryption key:\t\t\t" },	{ WI_RID_DEFLT_CRYPT_KEYS, WI_KEYSTRUCT, "Encryption keys:\t\t\t" },	{ 0, 0, NULL }};static voidwi_dumpinfo(const char *iface){	struct wi_req		wreq;	int			i, has_wep;	struct wi_table		*w;	bzero((char *)&wreq, sizeof(wreq));	wreq.wi_len = WI_MAX_DATALEN;	wreq.wi_type = WI_RID_WEP_AVAIL;	wi_getval(iface, &wreq);	has_wep = wreq.wi_val[0];	w = wi_table;	for (i = 0; w[i].wi_type; i++) {		bzero((char *)&wreq, sizeof(wreq));		wreq.wi_len = WI_MAX_DATALEN;		wreq.wi_type = w[i].wi_code;		wi_getval(iface, &wreq);		printf("%s", w[i].wi_str);		switch(w[i].wi_type) {		case WI_STRING:			wi_printstr(&wreq);			break;		case WI_WORDS:			wi_printwords(&wreq);			break;		case WI_SWORDS:			wi_printswords(&wreq);			break;		case WI_HEXWORDS:			wi_printhexwords(&wreq);			break;		case WI_REGDOMS:			wi_printregdoms(&wreq);			break;		case WI_BOOL:			wi_printbool(&wreq);			break;		case WI_HEXBYTES:			wi_printhex(&wreq);			break;		default:			break;		}			printf("\n");	}	if (has_wep) {		w = wi_crypt_table;		for (i = 0; w[i].wi_type; i++) {			bzero((char *)&wreq, sizeof(wreq));			wreq.wi_len = WI_MAX_DATALEN;			wreq.wi_type = w[i].wi_code;			wi_getval(iface, &wreq);			printf("%s", w[i].wi_str);			switch(w[i].wi_type) {			case WI_STRING:				wi_printstr(&wreq);				break;			case WI_WORDS:				if (wreq.wi_type == WI_RID_TX_CRYPT_KEY)					wreq.wi_val[0]++;				wi_printwords(&wreq);				break;			case WI_BOOL:				wi_printbool(&wreq);				break;			case WI_HEXBYTES:				wi_printhex(&wreq);				break;			case WI_KEYSTRUCT:				wi_printkeys(&wreq);				break;			default:				break;			}				printf("\n");		}	}	if (listaps)		wi_printaplist(iface);	return;}static voidwi_dumpstats(const char *iface){	struct wi_req		wreq;	struct wi_counters	*c;	if (iface == NULL)		errx(1, "must specify interface name");	bzero((char *)&wreq, sizeof(wreq));	wreq.wi_len = WI_MAX_DATALEN;	wreq.wi_type = WI_RID_IFACE_STATS;	wi_getval(iface, &wreq);	c = (struct wi_counters *)&wreq.wi_val;	printf("Transmitted unicast frames:\t\t%d\n",	    c->wi_tx_unicast_frames);	printf("Transmitted multicast frames:\t\t%d\n",	    c->wi_tx_multicast_frames);	printf("Transmitted fragments:\t\t\t%d\n",	    c->wi_tx_fragments);	printf("Transmitted unicast octets:\t\t%d\n",	    c->wi_tx_unicast_octets);	printf("Transmitted multicast octets:\t\t%d\n",	    c->wi_tx_multicast_octets);	printf("Single transmit retries:\t\t%d\n",	    c->wi_tx_single_retries);	printf("Multiple transmit retries:\t\t%d\n",	    c->wi_tx_multi_retries);	printf("Transmit retry limit exceeded:\t\t%d\n",	    c->wi_tx_retry_limit);	printf("Transmit discards:\t\t\t%d\n",	    c->wi_tx_discards);	printf("Transmit discards due to wrong SA:\t%d\n",	    c->wi_tx_discards_wrong_sa);	printf("Received unicast frames:\t\t%d\n",	    c->wi_rx_unicast_frames);	printf("Received multicast frames:\t\t%d\n",	    c->wi_rx_multicast_frames);	printf("Received fragments:\t\t\t%d\n",	    c->wi_rx_fragments);	printf("Received unicast octets:\t\t%d\n",	    c->wi_rx_unicast_octets);	printf("Received multicast octets:\t\t%d\n",	    c->wi_rx_multicast_octets);	printf("Receive FCS errors:\t\t\t%d\n",	    c->wi_rx_fcs_errors);	printf("Receive discards due to no buffer:\t%d\n",	    c->wi_rx_discards_nobuf);	printf("Can't decrypt WEP frame:\t\t%d\n",	    c->wi_rx_WEP_cant_decrypt);	printf("Received message fragments:\t\t%d\n",	    c->wi_rx_msg_in_msg_frags);	printf("Received message bad fragments:\t\t%d\n",	    c->wi_rx_msg_in_bad_msg_frags);	return;}static voidusage(const char *p){	fprintf(stderr, "usage:  %s -i iface\n", p);	fprintf(stderr, "\t%s -i iface -o\n", p);	fprintf(stderr, "\t%s -i iface -l\n", p);	fprintf(stderr, "\t%s -i iface -t tx rate\n", p);	fprintf(stderr, "\t%s -i iface -n network name\n", p);	fprintf(stderr, "\t%s -i iface -s station name\n", p);	fprintf(stderr, "\t%s -i iface -c 0|1\n", p);	fprintf(stderr, "\t%s -i iface -q SSID\n", p);	fprintf(stderr, "\t%s -i iface -p port type\n", p);	fprintf(stderr, "\t%s -i iface -a access point density\n", p);	fprintf(stderr, "\t%s -i iface -m mac address\n", p);	fprintf(stderr, "\t%s -i iface -d max data length\n", p);	fprintf(stderr, "\t%s -i iface -e 0|1\n", p);	fprintf(stderr, "\t%s -i iface -k encryption key [-v 1|2|3|4]\n", p);	fprintf(stderr, "\t%s -i iface -r RTS threshold\n", p);	fprintf(stderr, "\t%s -i iface -f frequency\n", p);	fprintf(stderr, "\t%s -i iface -F 0|1\n", p);	fprintf(stderr, "\t%s -i iface -P 0|1\n", p);	fprintf(stderr, "\t%s -i iface -S max sleep duration\n", p);	fprintf(stderr, "\t%s -i iface -T 1|2|3|4\n", p);#ifdef WICACHE	fprintf(stderr, "\t%s -i iface -Z zero out signal cache\n", p);	fprintf(stderr, "\t%s -i iface -C print signal cache\n", p);#endif	exit(1);}static voidwi_dumpstations(const char *iface){	struct hostap_getall    reqall;	struct hostap_sta       stas[WIHAP_MAX_STATIONS];	struct ifreq		ifr;	int i, s;	bzero(&ifr, sizeof(ifr));	strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));	ifr.ifr_data = (caddr_t) & reqall;	bzero(&reqall, sizeof(reqall));	reqall.size = sizeof(stas);	reqall.addr = stas;	bzero(&stas, sizeof(stas));	s = socket(AF_INET, SOCK_DGRAM, 0);	if (s == -1)		err(1, "socket");	if (ioctl(s, SIOCHOSTAP_GETALL, &ifr) < 0)		err(1, "SIOCHOSTAP_GETALL");	printf("%d station%s:\n", reqall.nstations, reqall.nstations>1?"s":"");	for (i = 0; i < reqall.nstations; i++) {		struct hostap_sta *info = &stas[i];	        printf("%02x:%02x:%02x:%02x:%02x:%02x  asid=%04x",			info->addr[0], info->addr[1], info->addr[2],			info->addr[3], info->addr[4], info->addr[5],			info->asid - 0xc001);		printb(", flags", info->flags, HOSTAP_FLAGS_BITS);		printb(", caps", info->capinfo, IEEE80211_CAPINFO_BITS);		printb(", rates", info->rates, WI_RATES_BITS);		if (info->sig_info)			printf(", sig=%d/%d",			    info->sig_info >> 8, info->sig_info & 0xff);		putchar('\n');	}}#ifdef WICACHEstatic voidwi_zerocache(const char *iface){	struct wi_req		wreq;	if (iface == NULL)		errx(1, "must specify interface name");	bzero((char *)&wreq, sizeof(wreq));	wreq.wi_len = 0;	wreq.wi_type = WI_RID_ZERO_CACHE;	wi_getval(iface, &wreq);}static voidwi_readcache(const char *iface){	struct wi_req		wreq;	int 			*wi_sigitems;	struct wi_sigcache 	*sc;	char *			pt;	int 			i;	if (iface == NULL)		errx(1, "must specify interface name");	bzero((char *)&wreq, sizeof(wreq));	wreq.wi_len = WI_MAX_DATALEN;	wreq.wi_type = WI_RID_READ_CACHE;	wi_getval(iface, &wreq);	wi_sigitems = (int *) &wreq.wi_val; 	pt = ((char *) &wreq.wi_val);	pt += sizeof(int);	sc = (struct wi_sigcache *) pt;	for (i = 0; i < *wi_sigitems; i++) {		printf("[%d/%d]:", i+1, *wi_sigitems);		printf(" %02x:%02x:%02x:%02x:%02x:%02x,",		  		    	sc->macsrc[0]&0xff,		  		    	sc->macsrc[1]&0xff,		   		    	sc->macsrc[2]&0xff,		   			sc->macsrc[3]&0xff,		   			sc->macsrc[4]&0xff,		   			sc->macsrc[5]&0xff);        	printf(" %d.%d.%d.%d,",((sc->ipsrc >> 0) & 0xff),				        ((sc->ipsrc >> 8) & 0xff),				        ((sc->ipsrc >> 16) & 0xff),				        ((sc->ipsrc >> 24) & 0xff));		printf(" sig: %d, noise: %d, qual: %d\n",		   			sc->signal,		   			sc->noise,		   			sc->quality);		sc++;	}	return;}static voidwi_zeroextcache(const char *iface){	struct wi_req		wreq;	if (iface == NULL)		errx(1, "must specify interface name");	bzero((char *)&wreq, sizeof(wreq));	wreq.wi_len = 0;	wreq.wi_type = WI_RID_ZERO_EXTCACHE;	wi_getval(iface, &wreq);}static voidwi_readextcache(const char *iface){	struct wi_req		wreq;	int 			*wi_sigitems;	struct wi_sigextcache 	*sc;	char *			pt;	int 			i;	if (iface == NULL)		errx(1, "must specify interface name");	bzero((char *)&wreq, sizeof(wreq));	wreq.wi_len = WI_MAX_DATALEN;	wreq.wi_type = WI_RID_READ_EXTCACHE;	wi_getval(iface, &wreq);	wi_sigitems = (int *) &wreq.wi_val; 	pt = ((char *) &wreq.wi_val);	pt += sizeof(int);	sc = (struct wi_sigextcache *) pt;	for (i = 0; i < *wi_sigitems; i++) {		printf("[%d/%d]:", i+1, *wi_sigitems);		printf(" %02x:%02x:%02x:%02x:%02x:%02x,",		  		    	sc->macsrc[0]&0xff,		  		    	sc->macsrc[1]&0xff,		   		    	sc->macsrc[2]&0xff,		   			sc->macsrc[3]&0xff,		   			sc->macsrc[4]&0xff,		   			sc->macsrc[5]&0xff);/*        	printf(" %d.%d.%d.%d,",((sc->ipsrc >> 0) & 0xff),				        ((sc->ipsrc >> 8) & 0xff),				        ((sc->ipsrc >> 16) & 0xff),				        ((sc->ipsrc >> 24) & 0xff));*/		printf("\tReceived pkts: %lu, Timeout: %u\n", sc->rcvpkts, sc->remove_ctr);		printf("\tSent pkts: %lu\n", sc->sndpkts);/*		printf("\tAvg S/N/Q: %.3f/%.3f/%.3f\n", sc->EWMAvg[0],			sc->EWMAvg[1], sc->EWMAvg[2]);		printf("\tDev S/N/Q: %.3f/%.3f/%.3f\n", sc->deviation[0],			sc->deviation[1], sc->deviation[2]);*/		sc++;	}	return;}#endifintmain(int argc, char *argv[]){	int			ch;	const char		*iface = NULL;	char			*p = argv[0];	char			*key = NULL;	int			modifier = 0;	/* Get the interface name */	opterr = 0;	ch = getopt(argc, argv, "i:");	if (ch == 'i') {		iface = optarg;	} else {		if (argc > 1 && *argv[1] != '-') {			iface = argv[1];			optind = 2; 		} else {			iface = "wi0";			optind = 1;		}		optreset = 1;	}	opterr = 1;			while((ch = getopt(argc, argv,	    "a:hoc:d:e:f:i:k:lp:r:q:t:n:s:m:v:F:LP:S:T:ZC")) != -1) {		switch(ch) {		case 'Z':#ifdef WICACHE			wi_zerocache(iface);			wi_zeroextcache(iface);#else			printf("WICACHE not available\n");#endif			exit(0);			break;		case 'C':#ifdef WICACHE			wi_readcache(iface);			wi_readextcache(iface);#else			printf("WICACHE not available\n");#endif			exit(0);			break;		case 'o':			wi_dumpstats(iface);			exit(0);			break;		case 'c':			wi_setword(iface, WI_RID_CREATE_IBSS, atoi(optarg));			exit(0);			break;		case 'd':			wi_setword(iface, WI_RID_MAX_DATALEN, atoi(optarg));			exit(0);			break;		case 'e':			wi_setword(iface, WI_RID_ENCRYPTION, atoi(optarg));			exit(0);			break;		case 'f':			wi_setword(iface, WI_RID_OWN_CHNL, atoi(optarg));			exit(0);			break;		case 'F':			wi_setword(iface, WI_RID_PROCFRAME, atoi(optarg));			exit(0);			break; 		case 'k': 			key = optarg;			break;		case 'L':			listaps = 1;			break;		case 'l':			wi_dumpstations(iface);			exit(0);			break;		case 'p':			wi_setword(iface, WI_RID_PORTTYPE, atoi(optarg));			exit(0);			break;		case 'r':			wi_setword(iface, WI_RID_RTS_THRESH, atoi(optarg));			exit(0);			break;		case 't':			wi_setword(iface, WI_RID_TX_RATE, atoi(optarg));			exit(0);			break;		case 'n':			wi_setstr(iface, WI_RID_DESIRED_SSID, optarg);			exit(0);			break;		case 's':			wi_setstr(iface, WI_RID_NODENAME, optarg);			exit(0);			break;		case 'm':			wi_sethex(iface, WI_RID_MAC_NODE, optarg);			exit(0);			break;		case 'q':			wi_setstr(iface, WI_RID_OWN_SSID, optarg);			exit(0);			break;		case 'S':			wi_setword(iface, WI_RID_MAX_SLEEP, atoi(optarg));			exit(0);			break;		case 'T':			wi_setword(iface,			    WI_RID_TX_CRYPT_KEY, atoi(optarg) - 1);			exit(0);			break;		case 'P':			wi_setword(iface, WI_RID_PM_ENABLED, atoi(optarg));			exit(0);			break;		case 'a':			wi_setword(iface, WI_RID_SYSTEM_SCALE, atoi(optarg));			exit(0);			break;		case 'v':			modifier = atoi(optarg);			modifier--;			break;		case 'h':		default:			usage(p);			break;		}	}	if (iface == NULL)		usage(p);	if (key != NULL) {		wi_setkeys(iface, key, modifier);		exit(0);	}	wi_dumpinfo(iface);	exit(0);}

⌨️ 快捷键说明

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