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

📄 iwlist.c

📁 wireless tools, 目前的最新版
💻 C
📖 第 1 页 / 共 4 页
字号:
static const char *	event_capa_req[] ={  [SIOCSIWNWID	- SIOCIWFIRST] = "Set NWID (kernel generated)",  [SIOCSIWFREQ	- SIOCIWFIRST] = "Set Frequency/Channel (kernel generated)",  [SIOCGIWFREQ	- SIOCIWFIRST] = "New Frequency/Channel",  [SIOCSIWMODE	- SIOCIWFIRST] = "Set Mode (kernel generated)",  [SIOCGIWTHRSPY - SIOCIWFIRST] = "Spy threshold crossed",  [SIOCGIWAP	- SIOCIWFIRST] = "New Access Point/Cell address - roaming",  [SIOCGIWSCAN	- SIOCIWFIRST] = "Scan request completed",  [SIOCSIWESSID	- SIOCIWFIRST] = "Set ESSID (kernel generated)",  [SIOCGIWESSID	- SIOCIWFIRST] = "New ESSID",  [SIOCGIWRATE	- SIOCIWFIRST] = "New bit-rate",  [SIOCSIWENCODE - SIOCIWFIRST] = "Set Encoding (kernel generated)",  [SIOCGIWPOWER	- SIOCIWFIRST] = NULL,};static const char *	event_capa_evt[] ={  [IWEVTXDROP	- IWEVFIRST] = "Tx packet dropped - retry exceeded",  [IWEVCUSTOM	- IWEVFIRST] = "Custom driver event",  [IWEVREGISTERED - IWEVFIRST] = "Registered node",  [IWEVEXPIRED	- IWEVFIRST] = "Expired node",};/*------------------------------------------------------------------*//* * Print the event capability for the device */static intprint_event_capa_info(int		skfd,		      char *		ifname,		      char *		args[],		/* Command line args */		      int		count)		/* Args count */{  struct iw_range	range;  int			cmd;  /* Avoid "Unused parameter" warning */  args = args; count = count;  /* Extract range info */  if((iw_get_range_info(skfd, ifname, &range) < 0) ||     (range.we_version_compiled < 10))      fprintf(stderr, "%-8.16s  no wireless event capability information.\n\n",		      ifname);  else    {#ifdef DEBUG      /* Debugging ;-) */      for(cmd = 0x8B00; cmd < 0x8C0F; cmd++)	{	  int idx = IW_EVENT_CAPA_INDEX(cmd);	  int mask = IW_EVENT_CAPA_MASK(cmd);	  printf("0x%X - %d - %X\n", cmd, idx, mask);	}#endif      printf("%-8.16s  Wireless Events supported :\n", ifname);      for(cmd = SIOCIWFIRST; cmd <= SIOCGIWPOWER; cmd++)	{	  int idx = IW_EVENT_CAPA_INDEX(cmd);	  int mask = IW_EVENT_CAPA_MASK(cmd);	  if(range.event_capa[idx] & mask)	    printf("          0x%04X : %s\n",		   cmd, event_capa_req[cmd - SIOCIWFIRST]);	}      for(cmd = IWEVFIRST; cmd <= IWEVEXPIRED; cmd++)	{	  int idx = IW_EVENT_CAPA_INDEX(cmd);	  int mask = IW_EVENT_CAPA_MASK(cmd);	  if(range.event_capa[idx] & mask)	    printf("          0x%04X : %s\n",		   cmd, event_capa_evt[cmd - IWEVFIRST]);	}      printf("\n");    }  return(0);}/*************************** WPA SUPPORT ***************************//*------------------------------------------------------------------*//* * Print the authentication parameters for the device */static intprint_auth_info(int		skfd,		char *		ifname,		char *		args[],		/* Command line args */		int		count)		/* Args count */{  struct iwreq		wrq;  struct iw_range	range;  unsigned int		k;  /* Avoid "Unused parameter" warning */  args = args; count = count;  /* Extract range info */  if((iw_get_range_info(skfd, ifname, &range) < 0) ||     (range.we_version_compiled < 18))      fprintf(stderr, "%-8.16s  no authentication information.\n\n",		      ifname);  else    {      /* Print WPA/802.1x/802.11i security parameters */      if(!range.enc_capa)	{	printf("%-8.16s  unknown authentication information.\n\n", ifname);	}      else	{	  /* Display advanced encryption capabilities */	  printf("%-8.16s  Authentication capabilities :", ifname);	  iw_print_mask_name(range.enc_capa,			     iw_auth_capa_name, IW_AUTH_CAPA_NUM,				 "\n\t\t");	  printf("\n");	  /* Extract all auth settings */	  for(k = 0; k < IW_AUTH_SETTINGS_NUM; k++)	    { 	      wrq.u.param.flags = iw_auth_settings[k].value;	      if(iw_get_ext(skfd, ifname, SIOCGIWAUTH, &wrq) >= 0)		{		  printf("          Current %s :", iw_auth_settings[k].label);		  if(iw_auth_settings[k].names != NULL)		    iw_print_mask_name(wrq.u.param.value,				       iw_auth_settings[k].names,				       iw_auth_settings[k].num_names,				       "\n\t\t");		  else		    printf((wrq.u.param.value) ? " yes" : " no");		  printf("\n");		}	    }	}      printf("\n\n");    }  return(0);}/*------------------------------------------------------------------*//* * Print all the available wpa keys for the device */static intprint_wpakeys_info(int		skfd,		   char *	ifname,		   char *	args[],		/* Command line args */		   int		count)		/* Args count */{  struct iwreq		wrq;  struct iw_range	range;  unsigned char         extbuf[IW_EXTKEY_SIZE];  struct iw_encode_ext  *extinfo;  unsigned int		k;  char			buffer[128];  /* Avoid "Unused parameter" warning */  args = args; count = count;  /* This always point to the same place */  extinfo = (struct iw_encode_ext *) extbuf;  /* Extract range info */  if(iw_get_range_info(skfd, ifname, &range) < 0)      fprintf(stderr, "%-8.16s  no wpa key information.\n\n",		      ifname);  else    {      printf("%-8.16s  ", 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 */      printf("%d keys available :\n", range.max_encoding_tokens);      for(k = 1; k <= range.max_encoding_tokens; k++)	{	  /* Cleanup. Driver may not fill everything */	  memset(extbuf, '\0', IW_EXTKEY_SIZE);	  /* Get whole struct containing one WPA key */	  wrq.u.data.pointer = (caddr_t) extbuf;	  wrq.u.data.length = IW_EXTKEY_SIZE;	  wrq.u.data.flags = k;	  if(iw_get_ext(skfd, ifname, SIOCGIWENCODEEXT, &wrq) < 0)	    {	      fprintf(stderr, "Error reading wpa keys (SIOCGIWENCODEEXT): %s\n", strerror(errno));	      break;	    }	  /* Sanity check */	  if(wrq.u.data.length < 	     (sizeof(struct iw_encode_ext) + extinfo->key_len))	    break;	  /* Check if key is disabled */	  if((wrq.u.data.flags & IW_ENCODE_DISABLED) ||	     (extinfo->key_len == 0))	    printf("\t\t[%d]: off\n", k);	  else	    {	      /* Display the key */	      iw_print_key(buffer, sizeof(buffer),			   extinfo->key, extinfo->key_len, wrq.u.data.flags);	      printf("\t\t[%d]: %s", k, buffer);	      /* Key size */	      printf(" (%d bits)", extinfo->key_len * 8);	      printf("\n");	      /* Other info... */	      printf("\t\t     Address: %s\n",		     iw_saether_ntop(&extinfo->addr, buffer));	      printf("\t\t     Algorithm:");	      iw_print_value_name(extinfo->alg,				  iw_encode_alg_name, IW_ENCODE_ALG_NUM);	      printf("\n\t\t     Flags: 0x%08x\n", extinfo->ext_flags);	      if (extinfo->ext_flags & IW_ENCODE_EXT_TX_SEQ_VALID)		printf("\t\t        tx-seq-valid\n");	      if (extinfo->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)		printf("\t\t        rx-seq-valid\n");	      if (extinfo->ext_flags & IW_ENCODE_EXT_GROUP_KEY)		printf("\t\t        group-key\n");	    }	}      /* Print current key index and mode */      wrq.u.data.pointer = (caddr_t) extbuf;      wrq.u.data.length = IW_EXTKEY_SIZE;      wrq.u.data.flags = 0;	/* Set index to zero to get current */      if(iw_get_ext(skfd, ifname, SIOCGIWENCODEEXT, &wrq) >= 0)	{	  /* Note : if above fails, we have already printed an error	   * message int the loop above */	  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);}/*------------------------------------------------------------------*//* * Print the Generic IE for the device * Note : indentation is broken. We need to fix that. */static intprint_gen_ie_info(int		skfd,		  char *	ifname,		  char *	args[],		/* Command line args */		  int		count)		/* Args count */{  struct iwreq		wrq;  unsigned char         buf[IW_GENERIC_IE_MAX];  /* Avoid "Unused parameter" warning */  args = args; count = count;  wrq.u.data.pointer = (caddr_t)buf;  wrq.u.data.length = IW_GENERIC_IE_MAX;  wrq.u.data.flags = 0;  if(iw_get_ext(skfd, ifname, SIOCGIWGENIE, &wrq) < 0)    fprintf(stderr, "%-8.16s  no generic IE (%s).\n\n",	    ifname, strerror(errno));  else    {      fprintf(stderr, "%-8.16s\n", ifname);      if(wrq.u.data.length == 0)	printf("          empty generic IE\n");      else	iw_print_gen_ie(buf, wrq.u.data.length);      printf("\n");    }  return(0);}/**************************** MODULATION ****************************//*------------------------------------------------------------------*//* * Print Modulation info for each device */static intprint_modul_info(int		skfd,		 char *		ifname,		 char *		args[],		/* Command line args */		 int		count)		/* Args count */{  struct iwreq		wrq;  struct iw_range	range;  /* 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 modulation information.\n\n",	    ifname);  else    {      if(range.modul_capa == 0x0)	printf("%-8.16s  unknown modulation information.\n\n", ifname);      else	{	  int i;	  printf("%-8.16s  Modulations available :\n", ifname);	  /* Display each modulation available */	  for(i = 0; i < IW_SIZE_MODUL_LIST; i++)	    {	      if((range.modul_capa & iw_modul_list[i].mask)		 == iw_modul_list[i].mask)		printf("              %-8s: %s\n",		       iw_modul_list[i].cmd, iw_modul_list[i].verbose);	    }	  /* Get current modulations settings */	  wrq.u.param.flags = 0;	  if(iw_get_ext(skfd, ifname, SIOCGIWMODUL, &wrq) >= 0)	    {	      unsigned int	modul = wrq.u.param.value;	      int		n = 0;	      printf("          Current modulations %c",		     wrq.u.param.fixed ? '=' : ':');	      /* Display each modulation enabled */	      for(i = 0; i < IW_SIZE_MODUL_LIST; i++)		{		  if((modul & iw_modul_list[i].mask) == iw_modul_list[i].mask)		    {		      if((n++ % 8) == 0)			printf("\n              ");		      else			printf(" ; ");		      printf("%s", iw_modul_list[i].cmd);		    }		}	      printf("\n");	    }	  printf("\n");	}    }  return(0);}#endif	/* WE_ESSENTIAL *//************************* COMMON UTILITIES *************************//* * This section was initially written by Michael Tokarev <mjt@tls.msk.ru> * but heavily modified by me ;-) *//*------------------------------------------------------------------*//* * Map command line arguments to the proper procedure... */typedef struct iwlist_entry {  const char *		cmd;		/* Command line shorthand */  iw_enum_handler	fn;		/* Subroutine */  int			max_count;  const char *		argsname;	/* Args as human readable string */} iwlist_cmd;static const struct iwlist_entry iwlist_cmds[] = {  { "scanning",		print_scanning_info,	-1, "[essid NNN] [last]" },  { "frequency",	print_freq_info,	0, NULL },  { "channel",		print_freq_info,	0, NULL },  { "bitrate",		print_bitrate_info,	0, NULL },  { "rate",		print_bitrate_info,	0, NULL },  { "encryption",	print_keys_info,	0, NULL },  { "keys",		print_keys_info,	0, NULL },  { "power",		print_pm_info,		0, NULL },#ifndef WE_ESSENTIAL  { "txpower",		print_txpower_info,	0, NULL },  { "retry",		print_retry_info,	0, NULL },  { "ap",		print_ap_info,		0, NULL },  { "accesspoints",	print_ap_info,		0, NULL },  { "peers",		print_ap_info,		0, NULL },  { "event",		print_event_capa_info,	0, NULL },  { "auth",		print_auth_info,	0, NULL },  { "wpakeys",		print_wpakeys_info,	0, NULL },  { "genie",		print_gen_ie_info,	0, NULL },  { "modulation",	print_modul_info,	0, NULL },#endif	/* WE_ESSENTIAL */  { NULL, NULL, 0, 0 },};/*------------------------------------------------------------------*//* * Find the most appropriate command matching the command line */static inline const iwlist_cmd *find_command(const char *	cmd){  const iwlist_cmd *	found = NULL;  int			ambig = 0;  unsigned int		len = strlen(cmd);  int			i;  /* Go through all commands */  for(i = 0; iwlist_cmds[i].cmd != NULL; ++i)    {      /* No match -> next one */      if(strncasecmp(iwlist_cmds[i].cmd, cmd, len) != 0)	continue;      /* Exact match -> perfect */      if(len == strlen(iwlist_cmds[i].cmd))	return &iwlist_cmds[i];      /* Partial match */      if(found == NULL)	/* First time */	found = &iwlist_cmds[i];      else	/* Another time */	if (iwlist_cmds[i].fn != found->fn)	  ambig = 1;    }  if(found == NULL)    {      fprintf(stderr, "iwlist: unknown command `%s' (check 'iwlist --help').\n", cmd);      return NULL;    }  if(ambig)    {      fprintf(stderr, "iwlist: command `%s' is ambiguous (check 'iwlist --help').\n", cmd);      return NULL;    }  return found;}/*------------------------------------------------------------------*//* * Display help */static void iw_usage(int status){  FILE *		f = status ? stderr : stdout;  int			i;  for(i = 0; iwlist_cmds[i].cmd != NULL; ++i)    {      fprintf(f, "%s [interface] %s %s\n",	      (i ? "             " : "Usage: iwlist"),	      iwlist_cmds[i].cmd,	      iwlist_cmds[i].argsname ? iwlist_cmds[i].argsname : "");    }  exit(status);}/******************************* MAIN ********************************//*------------------------------------------------------------------*//* * The main ! */intmain(int	argc,     char **	argv){  int skfd;			/* generic raw socket desc.	*/  char *dev;			/* device name			*/  char *cmd;			/* command			*/  char **args;			/* Command arguments */  int count;			/* Number of arguments */  const iwlist_cmd *iwcmd;  if(argc < 2)    iw_usage(1);  /* Those don't apply to all interfaces */  if((argc == 2) && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))    iw_usage(0);  if((argc == 2) && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")))    return(iw_print_version_info("iwlist"));  if(argc == 2)    {      cmd = argv[1];      dev = NULL;      args = NULL;      count = 0;    }  else    {      cmd = argv[2];      dev = argv[1];      args = argv + 3;      count = argc - 3;    }  /* find a command */  iwcmd = find_command(cmd);  if(iwcmd == NULL)    return 1;  /* Check arg numbers */  if((iwcmd->max_count >= 0) && (count > iwcmd->max_count))    {      fprintf(stderr, "iwlist: command `%s' needs fewer arguments (max %d)\n",	      iwcmd->cmd, iwcmd->max_count);      return 1;    }  /* Create a channel to the NET kernel. */  if((skfd = iw_sockets_open()) < 0)    {      perror("socket");      return -1;    }  /* do the actual work */  if (dev)    (*iwcmd->fn)(skfd, dev, args, count);  else    iw_enum_devices(skfd, iwcmd->fn, args, count);  /* Close the socket. */  iw_sockets_close(skfd);  return 0;}

⌨️ 快捷键说明

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