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

📄 iwconfig.c

📁 uclinux下802.11网卡的配置工具源码
💻 C
📖 第 1 页 / 共 3 页
字号:
      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);	}      tokens += 3;    }  /* Display the fragmentation threshold */  if(info->has_frag)    {      /* A bit of clever formatting */      if(tokens > 10)	{	  printf("\n          ");	  tokens = 0;	}      tokens +=4;      /* 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(tokens > 0)    printf("\n          ");  /* Display encryption information */  /* Note : we display only the "current" key, use iwlist 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	{	  /* Display the key */	  print_key(stdout, info->key, info->key_size, info->key_flags);	  /* 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, the user need to use iwlist... */  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)	    print_pm_value(stdout, info->power.value, info->power.flags);	  /* Let's check the mode */	  print_pm_mode(stdout, info->power.flags);	  /* Let's check if nothing (simply on) */	  if(info->power.flags == IW_POWER_ON)	    printf(":on");	  printf("\n          "); 	}    }  /* Display statistics */  if(info->has_stats)    {      info->stats.qual.updated = 0x0;	/* Not that reliable, disable */      printf("Link ");      print_stats(stdout, &info->stats.qual, &info->range, info->has_range);      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. */static voidprint_info(int		skfd,	   char *	ifname){  struct wireless_info	info;  if(get_info(skfd, ifname, &info) < 0)    {      fprintf(stderr, "%-8.8s  no wireless extensions.\n\n",	      ifname);      return;    }  /* Display it ! */  display_info(&info, ifname);}/*------------------------------------------------------------------*//* * Get info on all devices and print it on the screen */static voidprint_devices(int	skfd){  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(skfd, 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++)    print_info(skfd, ifr->ifr_name);}/************************* SETTING ROUTINES **************************//*------------------------------------------------------------------*//* * Set the wireless options requested on command line * This function is too long and probably should be split, * because it look like the perfect definition of spaghetti code, * but I'm way to lazy */static intset_info(int		skfd,		/* The socket */	 char *		args[],		/* Command line args */	 int		count,		/* Args count */	 char *		ifname)		/* Dev name */{  struct iwreq		wrq;  int			i;  /* Set dev name */  strncpy(wrq.ifr_name, ifname, 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(skfd, SIOCGIWNWID, &wrq) < 0)		  {		    fprintf(stderr, "SIOCGIWNWID: %s\n", strerror(errno));		    return(-1);		  }		strcpy(wrq.ifr_name, ifname);		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(skfd, 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(skfd, SIOCSIWFREQ, &wrq) < 0)	    {	      fprintf(stderr, "SIOCSIWFREQ: %s\n", strerror(errno));	      return(-1);	    }	  continue;	}      /* ---------- Set sensitivity ---------- */      if(!strncmp(args[i], "sens", 4))	{	  if(++i >= count)	    iw_usage();	  if(sscanf(args[i], "%d", &(wrq.u.sens.value)) != 1)	    iw_usage();	  if(ioctl(skfd, SIOCSIWSENS, &wrq) < 0)	    {	      fprintf(stderr, "SIOCSIWSENS: %s\n", strerror(errno));	      return(-1);	    }	  continue;	}      /* ---------- Set encryption stuff ---------- */      if((!strncmp(args[i], "enc", 3)) ||	 (!strcmp(args[i], "key")))	{	  unsigned char	key[IW_ENCODING_TOKEN_MAX];	  if(++i >= count)	    iw_usage();	  if(!strcasecmp(args[i], "on"))	    {	      /* Get old encryption information */	      wrq.u.data.pointer = (caddr_t) key;	      wrq.u.data.length = 0;	      wrq.u.data.flags = 0;	      if(ioctl(skfd, SIOCGIWENCODE, &wrq) < 0)		{		  fprintf(stderr, "SIOCGIWENCODE: %s\n", strerror(errno));		  return(-1);		}	      strcpy(wrq.ifr_name, ifname);	      wrq.u.data.flags &= ~IW_ENCODE_DISABLED;	/* Enable */	    }	  else	    {	      char *	buff;	      char *	p;	      int		temp;	      int		k = 0;	      int		gotone = 1;	      wrq.u.data.pointer = (caddr_t) NULL;	      wrq.u.data.flags = 0;	      wrq.u.data.length = 0;	      /* -- Check for the key -- */	      if(!strncmp(args[i], "s:", 2))		{		  /* First case : as an ASCII string */		  wrq.u.data.length = strlen(args[i] + 2);		  if(wrq.u.data.length > IW_ENCODING_TOKEN_MAX)		    wrq.u.data.length = IW_ENCODING_TOKEN_MAX;		  strncpy(key, args[i] + 2, wrq.u.data.length);		  wrq.u.data.pointer = (caddr_t) key;		  ++i;		  gotone = 1;		}	      else		{		  /* Second case : has hexadecimal digits */		  p = buff = malloc(strlen(args[i]) + 1);		  strcpy(buff, args[i]);		  p = strtok(buff, "-:;.,");		  while(p != (char *) NULL)		    {		      if(sscanf(p, "%2X", &temp) != 1)			{			  gotone = 0;			  break;			}		      key[k++] = (unsigned char) (temp & 0xFF);		      if(strlen(p) > 2)	/* Token not finished yet */			p += 2;		      else			p = strtok((char *) NULL, "-:;.,");		    }		  free(buff);		  if(gotone)		    {		      ++i;		      wrq.u.data.length = k;		      wrq.u.data.pointer = (caddr_t) key;		    }		}	      /* -- Check for token index -- */	      if((i < count) &&		 (sscanf(args[i], "[%d]", &temp) == 1) &&		 (temp > 0) && (temp < IW_ENCODE_INDEX))		{		  wrq.u.encoding.flags |= temp;		  ++i;		  gotone = 1;		}	      /* -- Check the various flags -- */	      if(i < count)		{		  if(!strcasecmp(args[i], "off"))		    wrq.u.data.flags |= IW_ENCODE_DISABLED;		  if(!strcasecmp(args[i], "open"))		    wrq.u.data.flags |= IW_ENCODE_OPEN;		  if(!strncasecmp(args[i], "restricted", 5))		    wrq.u.data.flags |= IW_ENCODE_RESTRICTED;		  if(wrq.u.data.flags & IW_ENCODE_FLAGS)		    {		      ++i;		      gotone = 1;		    }		}	      if(!gotone)		iw_usage();	      --i;	    }	  if(ioctl(skfd, SIOCSIWENCODE, &wrq) < 0)	    {	      fprintf(stderr, "SIOCSIWENCODE(%d): %s\n",		      errno, strerror(errno));	      return(-1);	    }	  continue;  	}      /* ---------- Set ESSID ---------- */      if(!strcasecmp(args[i], "essid"))	{	  char		essid[IW_ESSID_MAX_SIZE + 1];	  i++;	  if(i >= count)	    iw_usage();	  if((!strcasecmp(args[i], "off")) ||	     (!strcasecmp(args[i], "any")))	    {	      wrq.u.essid.flags = 0;	      essid[0] = '\0';	    }	  else	    if(!strcasecmp(args[i], "on"))	      {		/* Get old essid */		wrq.u.essid.pointer = (caddr_t) essid;		wrq.u.essid.length = 0;		wrq.u.essid.flags = 0;		if(ioctl(skfd, SIOCGIWESSID, &wrq) < 0)		  {		    fprintf(stderr, "SIOCGIWESSID: %s\n", strerror(errno));		    return(-1);		  }		strcpy(wrq.ifr_name, ifname);		wrq.u.essid.flags = 1;	      }	    else	      if(strlen(args[i]) > IW_ESSID_MAX_SIZE)		{		  fprintf(stderr, "ESSID too long (max %d): ``%s''\n",			  IW_ESSID_MAX_SIZE, args[i]);		  iw_usage();		}	      else		{		  int		temp;		  wrq.u.essid.flags = 1;		  strcpy(essid, args[i]);		  /* Check for ESSID index */		  if(((i+1) < count) &&		     (sscanf(args[i+1], "[%d]", &temp) == 1) &&		     (temp > 0) && (temp < IW_ENCODE_INDEX))		    {		      wrq.u.essid.flags = temp;		      ++i;		    }		}	  wrq.u.essid.pointer = (caddr_t) essid;	  wrq.u.essid.length = strlen(essid) + 1;	  if(ioctl(skfd, SIOCSIWESSID, &wrq) < 0)	    {	      fprintf(stderr, "SIOCSIWESSID: %s\n", strerror(errno));	      return(-1);	    }	  continue;	}      /* ---------- Set AP address ---------- */      if(!strcasecmp(args[i], "ap"))	{	  if(++i >= count)	    iw_usage();	  /* Check if we have valid address types */	  if(check_addr_type(skfd, ifname) < 0)	    {	      fprintf(stderr, "%-8.8s  Interface doesn't support MAC & IP addresses\n", ifname);	      return(-1);	    }	  /* Get the address */	  if(in_addr(skfd, ifname, args[i++], &(wrq.u.ap_addr)) < 0)	    iw_usage();	  if(ioctl(skfd, SIOCSIWAP, &wrq) < 0)	    {	      fprintf(stderr, "SIOCSIWAP: %s\n", strerror(errno));	      return(-1);	    }	  continue;	}      /* ---------- Set NickName ---------- */      if(!strncmp(args[i], "nick", 4))	{	  i++;	  if(i >= count)	    iw_usage();	  if(strlen(args[i]) > IW_ESSID_MAX_SIZE)	    {	      fprintf(stderr, "Name too long (max %d) : ``%s''\n",		      IW_ESSID_MAX_SIZE, args[i]);	      iw_usage();	    }	  wrq.u.essid.pointer = (caddr_t) args[i];	  wrq.u.essid.length = strlen(args[i]) + 1;	  if(ioctl(skfd, SIOCSIWNICKN, &wrq) < 0)	    {	      fprintf(stderr, "SIOCSIWNICKN: %s\n", strerror(errno));	      return(-1);	    }	  continue;	}      /* ---------- Set Bit-Rate ---------- */      if((!strncmp(args[i], "bit", 3)) ||	 (!strcmp(args[i], "rate")))

⌨️ 快捷键说明

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