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

📄 iwconfig.c

📁 wireless tools: used to manipulate the Wireless Extensions. The Wireless Extensions is an interface
💻 C
📖 第 1 页 / 共 4 页
字号:
/* *	Wireless Tools * *		Jean II - HPLB 97->99 - HPL 99->07 * * Main code for "iwconfig". This is the generic tool for most * manipulations... * You need to link this code against "iwlib.c" and "-lm". * * This file is released under the GPL license. *     Copyright (c) 1997-2007 Jean Tourrilhes <jt@hpl.hp.com> */#include "iwlib.h"		/* Header *//**************************** CONSTANTS ****************************//* * Error codes defined for setting args */#define IWERR_ARG_NUM		-2#define IWERR_ARG_TYPE		-3#define IWERR_ARG_SIZE		-4#define IWERR_ARG_CONFLICT	-5#define IWERR_SET_EXT		-6#define IWERR_GET_EXT		-7/**************************** VARIABLES ****************************//* * Ugly, but deal with errors in set_info() efficiently... */static int	errarg;static int	errmax;/************************* DISPLAY ROUTINES **************************//*------------------------------------------------------------------*//* * Get wireless informations & config from the device driver * We will call all the classical wireless ioctl on the driver through * the socket to know what is supported and to get the settings... */static intget_info(int			skfd,	 char *			ifname,	 struct wireless_info *	info){  struct iwreq		wrq;  memset((char *) info, 0, sizeof(struct wireless_info));  /* Get basic information */  if(iw_get_basic_config(skfd, ifname, &(info->b)) < 0)    {      /* If no wireless name : no wireless extensions */      /* But let's check if the interface exists at all */      struct ifreq ifr;      strncpy(ifr.ifr_name, ifname, IFNAMSIZ);      if(ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0)	return(-ENODEV);      else	return(-ENOTSUP);    }  /* Get ranges */  if(iw_get_range_info(skfd, ifname, &(info->range)) >= 0)    info->has_range = 1;  /* Get AP address */  if(iw_get_ext(skfd, ifname, SIOCGIWAP, &wrq) >= 0)    {      info->has_ap_addr = 1;      memcpy(&(info->ap_addr), &(wrq.u.ap_addr), sizeof (sockaddr));    }  /* Get bit rate */  if(iw_get_ext(skfd, ifname, SIOCGIWRATE, &wrq) >= 0)    {      info->has_bitrate = 1;      memcpy(&(info->bitrate), &(wrq.u.bitrate), sizeof(iwparam));    }  /* Get Power Management settings */  wrq.u.power.flags = 0;  if(iw_get_ext(skfd, ifname, SIOCGIWPOWER, &wrq) >= 0)    {      info->has_power = 1;      memcpy(&(info->power), &(wrq.u.power), sizeof(iwparam));    }  /* Get stats */  if(iw_get_stats(skfd, ifname, &(info->stats),		  &info->range, info->has_range) >= 0)    {      info->has_stats = 1;    }#ifndef WE_ESSENTIAL  /* Get NickName */  wrq.u.essid.pointer = (caddr_t) info->nickname;  wrq.u.essid.length = IW_ESSID_MAX_SIZE + 1;  wrq.u.essid.flags = 0;  if(iw_get_ext(skfd, ifname, SIOCGIWNICKN, &wrq) >= 0)    if(wrq.u.data.length > 1)      info->has_nickname = 1;  if((info->has_range) && (info->range.we_version_compiled > 9))    {      /* Get Transmit Power */      if(iw_get_ext(skfd, ifname, SIOCGIWTXPOW, &wrq) >= 0)	{	  info->has_txpower = 1;	  memcpy(&(info->txpower), &(wrq.u.txpower), sizeof(iwparam));	}    }  /* Get sensitivity */  if(iw_get_ext(skfd, ifname, SIOCGIWSENS, &wrq) >= 0)    {      info->has_sens = 1;      memcpy(&(info->sens), &(wrq.u.sens), sizeof(iwparam));    }  if((info->has_range) && (info->range.we_version_compiled > 10))    {      /* Get retry limit/lifetime */      if(iw_get_ext(skfd, ifname, SIOCGIWRETRY, &wrq) >= 0)	{	  info->has_retry = 1;	  memcpy(&(info->retry), &(wrq.u.retry), sizeof(iwparam));	}    }  /* Get RTS threshold */  if(iw_get_ext(skfd, ifname, SIOCGIWRTS, &wrq) >= 0)    {      info->has_rts = 1;      memcpy(&(info->rts), &(wrq.u.rts), sizeof(iwparam));    }  /* Get fragmentation threshold */  if(iw_get_ext(skfd, ifname, SIOCGIWFRAG, &wrq) >= 0)    {      info->has_frag = 1;      memcpy(&(info->frag), &(wrq.u.frag), sizeof(iwparam));    }#endif	/* WE_ESSENTIAL */  return(0);}/*------------------------------------------------------------------*//* * Print on the screen in a neat fashion all the info we have collected * on a device. */static voiddisplay_info(struct wireless_info *	info,	     char *			ifname){  char		buffer[128];	/* Temporary buffer */  /* One token is more of less 5 characters, 14 tokens per line */  int	tokens = 3;	/* For name */  /* Display device name and wireless name (name of the protocol used) */  printf("%-8.16s  %s  ", ifname, info->b.name);  /* Display ESSID (extended network), if any */  if(info->b.has_essid)    {      if(info->b.essid_on)	{	  /* Does it have an ESSID index ? */	  if((info->b.essid_on & IW_ENCODE_INDEX) > 1)	    printf("ESSID:\"%s\" [%d]  ", info->b.essid,		   (info->b.essid_on & IW_ENCODE_INDEX));	  else	    printf("ESSID:\"%s\"  ", info->b.essid);	}      else	printf("ESSID:off/any  ");    }#ifndef WE_ESSENTIAL  /* Display NickName (station name), if any */  if(info->has_nickname)    printf("Nickname:\"%s\"", info->nickname);#endif	/* WE_ESSENTIAL */  /* Formatting */  if(info->b.has_essid || info->has_nickname)    {      printf("\n          ");      tokens = 0;    }#ifndef WE_ESSENTIAL  /* Display Network ID */  if(info->b.has_nwid)    {      /* Note : should display proper number of digits according to info       * in range structure */      if(info->b.nwid.disabled)	printf("NWID:off/any  ");      else	printf("NWID:%X  ", info->b.nwid.value);      tokens +=2;    }#endif	/* WE_ESSENTIAL */  /* Display the current mode of operation */  if(info->b.has_mode)    {      printf("Mode:%s  ", iw_operation_mode[info->b.mode]);      tokens +=3;    }  /* Display frequency / channel */  if(info->b.has_freq)    {      double		freq = info->b.freq;	/* Frequency/channel */      int		channel = -1;		/* Converted to channel */      /* Some drivers insist of returning channel instead of frequency.       * This fixes them up. Note that, driver should still return       * frequency, because other tools depend on it. */      if(info->has_range && (freq < KILO))	channel = iw_channel_to_freq((int) freq, &freq, &info->range);      /* Display */      iw_print_freq(buffer, sizeof(buffer), freq, -1, info->b.freq_flags);      printf("%s  ", buffer);      tokens +=4;    }  /* Display the address of the current Access Point */  if(info->has_ap_addr)    {      /* A bit of clever formatting */      if(tokens > 8)	{	  printf("\n          ");	  tokens = 0;	}      tokens +=6;      /* Oups ! No Access Point in Ad-Hoc mode */      if((info->b.has_mode) && (info->b.mode == IW_MODE_ADHOC))	printf("Cell:");      else	printf("Access Point:");      printf(" %s   ", iw_sawap_ntop(&info->ap_addr, buffer));    }  /* Display the currently used/set bit-rate */  if(info->has_bitrate)    {      /* A bit of clever formatting */      if(tokens > 11)	{	  printf("\n          ");	  tokens = 0;	}      tokens +=3;      /* Display it */      iw_print_bitrate(buffer, sizeof(buffer), info->bitrate.value);      printf("Bit Rate%c%s   ", (info->bitrate.fixed ? '=' : ':'), buffer);    }#ifndef WE_ESSENTIAL  /* Display the Transmit Power */  if(info->has_txpower)    {      /* A bit of clever formatting */      if(tokens > 11)	{	  printf("\n          ");	  tokens = 0;	}      tokens +=3;      /* Display it */      iw_print_txpower(buffer, sizeof(buffer), &info->txpower);      printf("Tx-Power%c%s   ", (info->txpower.fixed ? '=' : ':'), buffer);    }  /* Display sensitivity */  if(info->has_sens)    {      /* A bit of clever formatting */      if(tokens > 10)	{	  printf("\n          ");	  tokens = 0;	}      tokens +=4;      /* Fixed ? */      printf("Sensitivity%c", info->sens.fixed ? '=' : ':');      if(info->has_range)	/* Display in dBm ? */	if(info->sens.value < 0)	  printf("%d dBm  ", info->sens.value);	else	  printf("%d/%d  ", info->sens.value, info->range.sensitivity);      else	printf("%d  ", info->sens.value);    }#endif	/* WE_ESSENTIAL */  printf("\n          ");  tokens = 0;#ifndef WE_ESSENTIAL  /* Display retry limit/lifetime information */  if(info->has_retry)    {       printf("Retry");      /* Disabled ? */      if(info->retry.disabled)	printf(":off");      else	{	  /* Let's check the value and its type */	  if(info->retry.flags & IW_RETRY_TYPE)	    {	      iw_print_retry_value(buffer, sizeof(buffer),				   info->retry.value, info->retry.flags,				   info->range.we_version_compiled);	      printf("%s", buffer);	    }	  /* Let's check if nothing (simply on) */	  if(info->retry.flags == IW_RETRY_ON)	    printf(":on"); 	}      printf("   ");      tokens += 5;	/* Between 3 and 5, depend on flags */    }  /* Display the RTS threshold */  if(info->has_rts)    {      /* Disabled ? */      if(info->rts.disabled)	printf("RTS thr:off   ");      else	{	  /* Fixed ? */	  printf("RTS thr%c%d B   ",		 info->rts.fixed ? '=' : ':',		 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 ? */	  printf("Fragment thr%c%d B   ",		 info->frag.fixed ? '=' : ':',		 info->frag.value);	}    }  /* Formating */  if(tokens > 0)    printf("\n          ");#endif	/* WE_ESSENTIAL */  /* Display encryption information */  /* Note : we display only the "current" key, use iwlist to list all keys */  if(info->b.has_key)    {      printf("Encryption key:");      if((info->b.key_flags & IW_ENCODE_DISABLED) || (info->b.key_size == 0))	printf("off");      else	{	  /* Display the key */	  iw_print_key(buffer, sizeof(buffer),		       info->b.key, info->b.key_size, info->b.key_flags);	  printf("%s", buffer);	  /* Other info... */	  if((info->b.key_flags & IW_ENCODE_INDEX) > 1)	    printf(" [%d]", info->b.key_flags & IW_ENCODE_INDEX);	  if(info->b.key_flags & IW_ENCODE_RESTRICTED)	    printf("   Security mode:restricted");	  if(info->b.key_flags & IW_ENCODE_OPEN)	    printf("   Security 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");      else	{	  /* Let's check the value and its type */	  if(info->power.flags & IW_POWER_TYPE)	    {	      iw_print_pm_value(buffer, sizeof(buffer),				info->power.value, info->power.flags,				info->range.we_version_compiled);	      printf("%s  ", buffer);	    }	  /* Let's check the mode */	  iw_print_pm_mode(buffer, sizeof(buffer), info->power.flags);	  printf("%s", buffer);	  /* Let's check if nothing (simply on) */	  if(info->power.flags == IW_POWER_ON)	    printf(":on"); 	}      printf("\n          ");    }  /* Display statistics */  if(info->has_stats)    {      iw_print_stats(buffer, sizeof(buffer),		     &info->stats.qual, &info->range, info->has_range);      printf("Link %s\n", buffer);      if(info->range.we_version_compiled > 11)	printf("          Rx invalid nwid:%d  Rx invalid crypt:%d  Rx invalid frag:%d\n          Tx excessive retries:%d  Invalid misc:%d   Missed beacon:%d\n",	       info->stats.discard.nwid,	       info->stats.discard.code,	       info->stats.discard.fragment,	       info->stats.discard.retries,	       info->stats.discard.misc,	       info->stats.miss.beacon);      else	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 intprint_info(int		skfd,	   char *	ifname,	   char *	args[],	   int		count){  struct wireless_info	info;  int			rc;  /* Avoid "Unused parameter" warning */  args = args; count = count;  rc = get_info(skfd, ifname, &info);  switch(rc)    {    case 0:	/* Success */

⌨️ 快捷键说明

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