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

📄 iwlist.c

📁 This package contains the Wireless tools, used to manipulate the Wireless Extensions. The Wireless
💻 C
📖 第 1 页 / 共 3 页
字号:
  else    {      if((range.num_txpower <= 0) || (range.num_txpower > IW_MAX_TXPOWER))	printf("%-8.16s  unknown transmit-power information.\n\n", ifname);      else	{	  printf("%-8.16s  %d available transmit-powers :\n",		 ifname, range.num_txpower);	  /* Print them all */	  for(k = 0; k < range.num_txpower; k++)	    {	      /* Check for relative values */	      if(range.txpower_capa & IW_TXPOW_RELATIVE)		{		  printf("\t  %d (no units)\n", range.txpower[k]);		}	      else		{		  if(range.txpower_capa & IW_TXPOW_MWATT)		    {		      dbm = iw_mwatt2dbm(range.txpower[k]);		      mwatt = range.txpower[k];		    }		  else		    {		      dbm = range.txpower[k];		      mwatt = iw_dbm2mwatt(range.txpower[k]);		    }		  printf("\t  %d dBm  \t(%d mW)\n", dbm, mwatt);		}	    }	}      /* Get current Transmit Power */      if(iw_get_ext(skfd, ifname, SIOCGIWTXPOW, &wrq) >= 0)	{	  printf("          Current Tx-Power");	  /* Disabled ? */	  if(wrq.u.txpower.disabled)	    printf(":off\n\n");	  else	    {	      /* Fixed ? */	      if(wrq.u.txpower.fixed)		printf("=");	      else		printf(":");	      /* Check for relative values */	      if(wrq.u.txpower.flags & IW_TXPOW_RELATIVE)		{		  /* I just hate relative value, because they are		   * driver specific, so not very meaningfull to apps.		   * But, we have to support that, because		   * this is the way hardware is... */		  printf("\t  %d (no units)\n", wrq.u.txpower.value);		}	      else		{		  if(wrq.u.txpower.flags & IW_TXPOW_MWATT)		    {		      dbm = iw_mwatt2dbm(wrq.u.txpower.value);		      mwatt = wrq.u.txpower.value;		    }		  else		    {		      dbm = wrq.u.txpower.value;		      mwatt = iw_dbm2mwatt(wrq.u.txpower.value);		    }		  printf("%d dBm  \t(%d mW)\n\n", dbm, mwatt);		}	    }	}    }  return(0);}/*********************** RETRY LIMIT/LIFETIME ***********************//*------------------------------------------------------------------*//* * Print one retry value */static inline intget_retry_value(int		skfd,		char *		ifname,		struct iwreq *	pwrq,		int		flags,		char *		buffer,		int		buflen){  /* Get Another retry value */  pwrq->u.retry.flags = flags;  if(iw_get_ext(skfd, ifname, SIOCGIWRETRY, pwrq) >= 0)    {      /* Let's check the value and its type */      if(pwrq->u.retry.flags & IW_RETRY_TYPE)	{	  iw_print_retry_value(buffer, buflen,			       pwrq->u.retry.value, pwrq->u.retry.flags);	  printf("%s\n                 ", buffer);	}    }  return(pwrq->u.retry.flags);}/*------------------------------------------------------------------*//* * Print Retry info for each device */static intprint_retry_info(int		skfd,		 char *		ifname,		 char *		args[],		/* Command line args */		 int		count)		/* Args count */{  struct iwreq		wrq;  struct iw_range	range;  char			buffer[128];  /* Avoid "Unused parameter" warning */  args = args; count = count;  /* Extract range info */  if((iw_get_range_info(skfd, ifname, &range) < 0) ||     (range.we_version_compiled < 11))    fprintf(stderr, "%-8.16s  no retry limit/lifetime information.\n\n",	    ifname);  else    {      printf("%-8.16s  ", ifname);      /* Display min/max limit availables */      if(range.retry_flags & IW_RETRY_LIMIT)	{	  int	flags = (range.retry_flags & ~(IW_RETRY_MIN | IW_RETRY_MAX));	  /* Display if auto or fixed */	  if(range.retry_flags & IW_RETRY_MIN)	    printf("Auto  limit    ; ");	  else	    printf("Fixed limit    ; ");	  /* Print the range */	  iw_print_retry_value(buffer, sizeof(buffer),			       range.min_retry, flags | IW_RETRY_MIN);	  printf("%s\n                           ", buffer);	  iw_print_retry_value(buffer, sizeof(buffer),			       range.max_retry, flags | IW_RETRY_MAX);	  printf("%s\n          ", buffer);	  	}      /* Display min/max lifetime availables */      if(range.r_time_flags & IW_RETRY_LIFETIME)	{	  int	flags = (range.r_time_flags & ~(IW_RETRY_MIN | IW_RETRY_MAX));	  /* Display if auto or fixed */	  if(range.r_time_flags & IW_RETRY_MIN)	    printf("Auto  lifetime ; ");	  else	    printf("Fixed lifetime ; ");	  /* Print the range */	  iw_print_retry_value(buffer, sizeof(buffer),			       range.min_r_time, flags | IW_RETRY_MIN);	  printf("%s\n                           ", buffer);	  iw_print_retry_value(buffer, sizeof(buffer),			       range.max_r_time, flags | IW_RETRY_MAX);	  printf("%s\n          ", buffer);	  	}      /* Get current retry settings */      wrq.u.retry.flags = 0;      if(iw_get_ext(skfd, ifname, SIOCGIWRETRY, &wrq) >= 0)	{	  int	flags = wrq.u.retry.flags;	  /* Is it disabled ? */	  if(wrq.u.retry.disabled)	    printf("Current mode:off\n          ");	  else	    {	      int	retry_mask = 0;	      /* Let's check the mode */	      printf("Current mode:on\n                 ");	      /* Let's check the value and its type */	      if(wrq.u.retry.flags & IW_RETRY_TYPE)		{		  iw_print_retry_value(buffer, sizeof(buffer),				       wrq.u.retry.value, wrq.u.retry.flags);		  printf("%s\n                 ", buffer);		}	      /* If we have been returned a MIN value, ask for the MAX */	      if(flags & IW_RETRY_MIN)		retry_mask = IW_RETRY_MAX;	      /* If we have been returned a MAX value, ask for the MIN */	      if(flags & IW_RETRY_MAX)		retry_mask = IW_RETRY_MIN;	      /* If we have something to ask for... */	      if(retry_mask)		get_retry_value(skfd, ifname, &wrq, retry_mask,				buffer, sizeof(buffer));	      /* And if we have both a period and a timeout, ask the other */	      retry_mask = (range.retry_capa & (~(wrq.u.retry.flags) &					  IW_RETRY_TYPE));	      if(retry_mask)		{		  int	base_mask = retry_mask;		  flags = get_retry_value(skfd, ifname, &wrq, retry_mask,					  buffer, sizeof(buffer));		  retry_mask = 0;		  /* If we have been returned a MIN value, ask for the MAX */		  if(flags & IW_RETRY_MIN)		    retry_mask = IW_RETRY_MAX | base_mask;		  /* If we have been returned a MAX value, ask for the MIN */		  if(flags & IW_RETRY_MAX)		    retry_mask = IW_RETRY_MIN | base_mask;		  /* If we have something to ask for... */		  if(retry_mask)		    get_retry_value(skfd, ifname, &wrq, retry_mask,				    buffer, sizeof(buffer));		}	    }	}      printf("\n");    }  return(0);}/***************************** SCANNING *****************************//* * This one behave quite differently from the others * * Note that we don't use the scanning capability of iwlib (functions * iw_process_scan() and iw_scan()). The main reason is that * iw_process_scan() return only a subset of the scan data to the caller, * for example custom elements and bitrates are ommited. Here, we * do the complete job... *//*------------------------------------------------------------------*//* * Parse, and display the results of a WPA or WPA2 IE. * */static void iw_print_ie_unknown(unsigned char *	iebuf,		    int			buflen){  int	ielen = iebuf[1] + 2;  int	i;  if(ielen > buflen)    ielen = buflen;  printf("Unknown: ");  for(i = 0; i < ielen; i++)    printf("%02X", iebuf[i]);  printf("\n");}/*-----------------------------------------------------------------*//* * Display the cipher type for the value passed in. * */static inline void iw_print_ie_cipher(unsigned char	csuite){  switch (csuite)    {    case 0x00:      printf("None or same as Group ");      break;     case 0x01:      printf("WEP-40 ");      break;     case 0x02:      printf("TKIP ");      break;     case 0x03:      printf("WRAP ");      break;     case 0x04:      printf("CCMP ");      break;     case 0x05:      printf("WEP-104 ");      break;     default:      printf("Unknown ");      break;    } } /*------------------------------------------------------------------*//* * Parse, and display the results of a WPA or WPA2 IE. * */static inline void iw_print_ie_wpa(unsigned char *	iebuf,		int		buflen){  int			ielen = iebuf[1] + 2;  int			offset = 2;	/* Skip the IE id, and the length. */  unsigned char		wpa1_oui[3] = {0x00, 0x50, 0xf2};  unsigned char		wpa2_oui[3] = {0x00, 0x0f, 0xac};  unsigned char *	wpa_oui;  int			i;  uint16_t		ver = 0;  uint16_t		cnt = 0;  if(ielen > buflen)    ielen = buflen;  switch(iebuf[0])    {    case 0x30:		/* WPA2 */      /* Check if we have enough data */      if(ielen < 4)	{	  iw_print_ie_unknown(iebuf, buflen); 	  return;	}      wpa_oui = wpa2_oui;      break;    case 0xdd:		/* WPA or else */      wpa_oui = wpa1_oui;       /* Not all IEs that start with 0xdd are WPA.        * So check that the OUI is valid. */      if((ielen < 8)	 || ((memcmp(&iebuf[offset], wpa_oui, 3) != 0)	     && (iebuf[offset+3] == 0x01))) 	{	  iw_print_ie_unknown(iebuf, buflen); 	  return; 	}       offset += 4;       break;    default:      return;    }    /* Pick version number (little endian) */  ver = iebuf[offset] | (iebuf[offset + 1] << 8);  offset += 2;  if(iebuf[0] == 0xdd)    printf("WPA Version %d\n", ver);  if(iebuf[0] == 0x30)    printf("IEEE 802.11i/WPA2 Version %d\n", ver);  /* From here, everything is technically optional. */  /* Check if we are done */  if(ielen < (offset + 4))    {      /* We have a short IE.  So we should assume TKIP/TKIP. */      printf("                        Group Cipher : TKIP\n");      printf("                        Pairwise Cipher : TKIP\n");      return;    }   /* Next we have our group cipher. */  if(memcmp(&iebuf[offset], wpa_oui, 3) != 0)    {      printf("                        Group Cipher : Proprietary\n");    }  else    {      printf("                        Group Cipher : ");      iw_print_ie_cipher(iebuf[offset+3]);      printf("\n");    }  offset += 4;  /* Check if we are done */  if(ielen < (offset + 2))    {      /* We don't have a pairwise cipher, or auth method. Assume TKIP. */      printf("                        Pairwise Ciphers (1) : TKIP\n");      return;    }  /* Otherwise, we have some number of pairwise ciphers. */  cnt = iebuf[offset] | (iebuf[offset + 1] << 8);  offset += 2;  printf("                        Pairwise Ciphers (%d) : ", cnt);  if(ielen < (offset + 4*cnt))    return;  for(i = 0; i < cnt; i++)    {      if(memcmp(&iebuf[offset], wpa_oui, 3) != 0) 	{ 	  printf("Proprietary  "); 	}      else	{ 	  iw_print_ie_cipher(iebuf[offset+3]); 	}      offset+=4;    }  printf("\n");   /* Check if we are done */  if(ielen < (offset + 2))    return;  /* Now, we have authentication suites. */  cnt = iebuf[offset] | (iebuf[offset + 1] << 8);  offset += 2;  printf("                        Authentication Suites (%d) : ", cnt);  if(ielen < (offset + 4*cnt))    return;  for(i = 0; i < cnt; i++)    {      if(memcmp(&iebuf[offset], wpa_oui, 3) != 0) 	{ 	  printf("Proprietary  "); 	}      else	{ 	  switch(iebuf[offset+3]) 	    { 	    case 0x00: 	      printf("Reserved  "); 	      break; 	    case 0x01: 	      printf("802.1X  "); 	      break; 	    case 0x02: 	      printf("PSK  "); 	      break; 	    default: 	      printf("Unknown  "); 	      break; 	    } 	}       offset+=4;     }  printf("\n");   /* Check if we are done */  if(ielen < (offset + 1))    return;  /* Otherwise, we have capabilities bytes.   * For now, we only care about preauth which is in bit position 1 of the   * first byte.  (But, preauth with WPA version 1 isn't supposed to be    * allowed.) 8-) */  if(iebuf[offset] & 0x01)    {      printf("                       Preauthentication Supported\n");    }} /*------------------------------------------------------------------*//* * Process a generic IE and display the info in human readable form * for some of the most interesting ones. * For now, we only decode the WPA IEs. */static inline voidiw_print_gen_ie(unsigned char *	buffer,		int		buflen){  int offset = 0;  /* Loop on each IE, each IE is minimum 2 bytes */  while(offset <= (buflen - 2))    {      printf("                    IE: ");      /* Check IE type */      switch(buffer[offset])	{	case 0xdd:	/* WPA1 (and other) */	case 0x30:	/* WPA2 */	  iw_print_ie_wpa(buffer + offset, buflen);	  break;	default:	  iw_print_ie_unknown(buffer + offset, buflen);	}      /* Skip over this IE to the next one in the list. */      offset += buffer[offset+1] + 2;    }}/*------------------------------------------------------------------*//* * Print one element from the scanning results */static inline voidprint_scanning_token(struct stream_descr *	stream,	/* Stream of events */		     struct iw_event *		event,	/* Extracted token */		     struct iwscan_state *	state,		     struct iw_range *	iw_range,	/* Range info */		     int		has_range){  char		buffer[128];	/* Temporary buffer */  /* Now, let's decode the event */  switch(event->cmd)    {    case SIOCGIWAP:      printf("          Cell %02d - Address: %s\n", state->ap_num,	     iw_saether_ntop(&event->u.ap_addr, buffer));      state->ap_num++;      break;    case SIOCGIWNWID:      if(event->u.nwid.disabled)	printf("                    NWID:off/any\n");      else	printf("                    NWID:%X\n", event->u.nwid.value);      break;    case SIOCGIWFREQ:      {	double		freq;			/* Frequency/channel */	int		channel = -1;		/* Converted to channel */	freq = iw_freq2float(&(event->u.freq));	/* Convert to channel if possible */	if(has_range)	  channel = iw_freq_to_channel(freq, iw_range);	iw_print_freq(buffer, sizeof(buffer),		      freq, channel, event->u.freq.flags);	printf("                    %s\n", buffer);      }      break;    case SIOCGIWMODE:

⌨️ 快捷键说明

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