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

📄 iwlist.c

📁 iwconfig iwlist iwpriv
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *	Wireless Tools * *		Jean II - HPLB '99 - HPL 99->01 * * This tool can access various piece of information on the card * not part of iwconfig... * You need to link this code against "iwlist.c" and "-lm". * * This file is released under the GPL license. *     Copyright (c) 1997-2002 Jean Tourrilhes <jt@hpl.hp.com> */#include "iwlib.h"		/* Header */#include <sys/time.h>/*********************** FREQUENCIES/CHANNELS ***********************//*------------------------------------------------------------------*//* * Print the number of channels and available frequency for the device */static intprint_freq_info(int		skfd,		char *		ifname,		char *		args[],		/* Command line args */		int		count)		/* Args count */{  struct iwreq		wrq;  struct iw_range	range;  double		freq;  int			k;  int			channel;  char			buffer[128];	/* Temporary buffer */  /* Avoid "Unused parameter" warning */  args = args; count = count;  /* Get list of frequencies / channels */  if(iw_get_range_info(skfd, ifname, &range) < 0)      fprintf(stderr, "%-8.8s  no frequency information.\n\n",		      ifname);  else    {      if(range.num_frequency > 0)	{	  printf("%-8.8s  %d channels in total; available frequencies :\n",		 ifname, range.num_channels);	  /* Print them all */	  for(k = 0; k < range.num_frequency; k++)	    {	      printf("          Channel %.2d : ", range.freq[k].i);	      freq = iw_freq2float(&(range.freq[k]));	      if(freq >= GIGA)		printf("%g GHz\n", freq / GIGA);	      else		if(freq >= MEGA)		  printf("%g MHz\n", freq / MEGA);		else		  printf("%g kHz\n", freq / KILO);	    }	}      else	printf("%-8.8s  %d channels\n",	       ifname, range.num_channels);      /* Get current frequency / channel and display it */      if(iw_get_ext(skfd, ifname, SIOCGIWFREQ, &wrq) >= 0)	{	  freq = iw_freq2float(&(wrq.u.freq));	  iw_print_freq(buffer, freq);	  channel = iw_freq_to_channel(freq, &range);	  if(channel >= 0)	    printf("          Current %s (channel %.2d)\n\n", buffer, channel);	  else	    printf("          Current %s\n\n", buffer);	}    }  return(0);}/************************ ACCESS POINT LIST ************************//* * Note : now that we have scanning support, this is depracted and * won't survive long. Actually, next version it's out ! *//*------------------------------------------------------------------*//* * Display the list of ap addresses and the associated stats * Exacly the same as the spy list, only with different IOCTL and messages */static intprint_ap_info(int	skfd,	      char *	ifname,	      char *	args[],		/* Command line args */	      int	count)		/* Args count */{  struct iwreq		wrq;  char		buffer[(sizeof(struct iw_quality) +			sizeof(struct sockaddr)) * IW_MAX_AP];  char		temp[128];  struct sockaddr *	hwa;  struct iw_quality *	qual;  iwrange	range;  int		has_range = 0;  int		has_qual = 0;  int		n;  int		i;  /* Avoid "Unused parameter" warning */  args = args; count = count;  /* Collect stats */  wrq.u.data.pointer = (caddr_t) buffer;  wrq.u.data.length = IW_MAX_AP;  wrq.u.data.flags = 0;  if(iw_get_ext(skfd, ifname, SIOCGIWAPLIST, &wrq) < 0)    {      fprintf(stderr, "%-8.8s  Interface doesn't have a list of Peers/Access-Points\n\n", ifname);      return(-1);    }  /* Number of addresses */  n = wrq.u.data.length;  has_qual = wrq.u.data.flags;  /* The two lists */  hwa = (struct sockaddr *) buffer;  qual = (struct iw_quality *) (buffer + (sizeof(struct sockaddr) * n));  /* Check if we have valid mac address type */  if(iw_check_mac_addr_type(skfd, ifname) < 0)    {      fprintf(stderr, "%-8.8s  Interface doesn't support MAC addresses\n\n", ifname);      return(-2);    }  /* Get range info if we can */  if(iw_get_range_info(skfd, ifname, &(range)) >= 0)    has_range = 1;  /* Display it */  if(n == 0)    printf("%-8.8s  No Peers/Access-Point in range\n", ifname);  else    printf("%-8.8s  Peers/Access-Points in range:\n", ifname);  for(i = 0; i < n; i++)    {      if(has_qual)	{	  /* Print stats for this address */	  printf("    %s : ", iw_pr_ether(temp, hwa[i].sa_data));	  iw_print_stats(temp, &qual[i], &range, has_range);	  printf("%s\n", temp);	}      else	/* Only print the address */	printf("    %s\n", iw_pr_ether(temp, hwa[i].sa_data));    }  printf("\n");  return(0);}/***************************** BITRATES *****************************//*------------------------------------------------------------------*//* * Print the number of available bitrates for the device */static intprint_bitrate_info(int		skfd,		   char *	ifname,		   char *	args[],		/* Command line args */		   int		count)		/* Args count */{  struct iwreq		wrq;  struct iw_range	range;  int			k;  char			buffer[128];  /* Avoid "Unused parameter" warning */  args = args; count = count;  /* Extract range info */  if(iw_get_range_info(skfd, ifname, &range) < 0)      fprintf(stderr, "%-8.8s  no bit-rate information.\n\n",		      ifname);  else    {      if((range.num_bitrates > 0) && (range.num_bitrates <= IW_MAX_BITRATES))	{	  printf("%-8.8s  %d available bit-rates :\n",		 ifname, range.num_bitrates);	  /* Print them all */	  for(k = 0; k < range.num_bitrates; k++)	    {	      iw_print_bitrate(buffer, range.bitrate[k]);	      /* Maybe this should be %10s */	      printf("\t  %s\n", buffer);	    }	}      else	printf("%-8.8s  No bit-rates ? Please update driver...\n", ifname);      /* Get current bit rate */      if(iw_get_ext(skfd, ifname, SIOCGIWRATE, &wrq) >= 0)	{	  iw_print_bitrate(buffer, wrq.u.bitrate.value);	  printf("          Current Bit Rate%c%s\n\n",		 (wrq.u.bitrate.fixed ? '=' : ':'), buffer);	}    }  return(0);}/************************* ENCRYPTION KEYS *************************//*------------------------------------------------------------------*//* * Print the number of available encryption key for the device */static intprint_keys_info(int		skfd,		char *		ifname,		char *		args[],		/* Command line args */		int		count)		/* Args count */{  struct iwreq		wrq;  struct iw_range	range;  unsigned char		key[IW_ENCODING_TOKEN_MAX];  int			k;  char			buffer[128];  /* Avoid "Unused parameter" warning */  args = args; count = count;  /* Extract range info */  if(iw_get_range_info(skfd, ifname, &range) < 0)      fprintf(stderr, "%-8.8s  no encryption keys information.\n\n",		      ifname);  else    {      printf("%-8.8s  ", ifname);      /* Print key sizes */      if((range.num_encoding_sizes > 0) &&	 (range.num_encoding_sizes < IW_MAX_ENCODING_SIZES))	{	  printf("%d key sizes : %d", range.num_encoding_sizes,		 range.encoding_size[0] * 8);	  /* Print them all */	  for(k = 1; k < range.num_encoding_sizes; k++)	    printf(", %d", range.encoding_size[k] * 8);	  printf("bits\n          ");	}      /* Print the keys and associate mode */      printf("%d keys available :\n", range.max_encoding_tokens);      for(k = 1; k <= range.max_encoding_tokens; k++)	{	  wrq.u.data.pointer = (caddr_t) key;	  wrq.u.data.length = IW_ENCODING_TOKEN_MAX;	  wrq.u.data.flags = k;	  if(iw_get_ext(skfd, ifname, SIOCGIWENCODE, &wrq) < 0)	    {	      fprintf(stderr, "SIOCGIWENCODE: %s\n", strerror(errno));	      break;	    }	  if((wrq.u.data.flags & IW_ENCODE_DISABLED) ||	     (wrq.u.data.length == 0))	    printf("\t\t[%d]: off\n", k);	  else	    {	      /* Display the key */	      iw_print_key(buffer, key, wrq.u.data.length, wrq.u.data.flags);	      printf("\t\t[%d]: %s", k, buffer);	      /* Other info... */	      printf(" (%d bits)", wrq.u.data.length * 8);	      printf("\n");	    }	}      /* Print current key and mode */      wrq.u.data.pointer = (caddr_t) key;      wrq.u.data.length = IW_ENCODING_TOKEN_MAX;      wrq.u.data.flags = 0;	/* Set index to zero to get current */      if(iw_get_ext(skfd, ifname, SIOCGIWENCODE, &wrq) < 0)	{	  fprintf(stderr, "SIOCGIWENCODE: %s\n", strerror(errno));	  return(-1);	}      printf("          Current Transmit Key: [%d]\n",	     wrq.u.data.flags & IW_ENCODE_INDEX);      if(wrq.u.data.flags & IW_ENCODE_RESTRICTED)	printf("          Security mode:restricted\n");      if(wrq.u.data.flags & IW_ENCODE_OPEN)	printf("          Security mode:open\n");      printf("\n\n");    }  return(0);}/************************* POWER MANAGEMENT *************************//*------------------------------------------------------------------*//* * Print Power Management info for each device */static inline intget_pm_value(int		skfd,	     char *		ifname,	     struct iwreq *	pwrq,	     int		flags,	     char *		buffer){  /* Get Another Power Management value */  pwrq->u.power.flags = flags;  if(iw_get_ext(skfd, ifname, SIOCGIWPOWER, pwrq) >= 0)    {      /* Let's check the value and its type */      if(pwrq->u.power.flags & IW_POWER_TYPE)	{	  iw_print_pm_value(buffer, pwrq->u.power.value, pwrq->u.power.flags);	  printf("\n                 %s", buffer);	}    }  return(pwrq->u.power.flags);}/*------------------------------------------------------------------*//* * Print Power Management info for each device */static intprint_pm_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)      fprintf(stderr, "%-8.8s  no power management information.\n\n",		      ifname);  else    {      printf("%-8.8s  ", ifname);#if WIRELESS_EXT > 9      /* Display modes availables */      if(range.pm_capa & IW_POWER_MODE)	{	  printf("Supported modes :\n          ");	  if(range.pm_capa & (IW_POWER_UNICAST_R | IW_POWER_MULTICAST_R))	    printf("\t\to Receive all packets (unicast & multicast)\n          ");	  if(range.pm_capa & IW_POWER_UNICAST_R)	    printf("\t\to Receive Unicast only (discard multicast)\n          ");	  if(range.pm_capa & IW_POWER_MULTICAST_R)	    printf("\t\to Receive Multicast only (discard unicast)\n          ");	  if(range.pm_capa & IW_POWER_FORCE_S)	    printf("\t\to Force sending using Power Management\n          ");	  if(range.pm_capa & IW_POWER_REPEATER)	    printf("\t\to Repeat multicast\n          ");	}      /* Display min/max period availables */      if(range.pmp_flags & IW_POWER_PERIOD)	{	  int	flags = (range.pmp_flags & ~(IW_POWER_MIN | IW_POWER_MAX));	  /* Display if auto or fixed */	  if(range.pmp_flags & IW_POWER_MIN)	    printf("Auto  period  ; ");	  else	    printf("Fixed period  ; ");	  /* Print the range */	  iw_print_pm_value(buffer, range.min_pmp, flags | IW_POWER_MIN);	  printf("%s\n                          ", buffer);	  iw_print_pm_value(buffer, range.max_pmp, flags | IW_POWER_MAX);	  printf("%s\n          ", buffer);

⌨️ 快捷键说明

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