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

📄 iwcommon.c

📁 uclinux下802.11网卡的配置工具源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    case IW_POWER_UNICAST_R:      fprintf(stream, " mode:Unicast only received");      break;    case IW_POWER_MULTICAST_R:      fprintf(stream, " mode:Multicast only received");      break;    case IW_POWER_ALL_R:      fprintf(stream, " mode:All packets received");      break;    case IW_POWER_FORCE_S:      fprintf(stream, " mode:Force sending");      break;    case IW_POWER_REPEATER:      fprintf(stream, " mode:Repeat multicasts");      break;    default:      break;    }}/***************** RETRY LIMIT/LIFETIME SUBROUTINES *****************/#if WIRELESS_EXT > 10/*------------------------------------------------------------------*//* * Output a retry value with all attributes... */voidprint_retry_value(FILE *	stream,		  int		value,		  int		flags){  /* Modifiers */  if(flags & IW_RETRY_MIN)    fprintf(stream, " min");  if(flags & IW_RETRY_MAX)    fprintf(stream, " max");  /* Type lifetime of limit */  if(flags & IW_RETRY_LIFETIME)    {      fprintf(stream, " lifetime:");      /* Display value without units */      if(flags & IW_POWER_RELATIVE)	fprintf(stream, "%g", ((double) value) / MEGA);      else	{	  /* Display value with units */	  if(value >= (int) MEGA)	    fprintf(stream, "%gs", ((double) value) / MEGA);	  else	    if(value >= (int) KILO)	      fprintf(stream, "%gms", ((double) value) / KILO);	    else	      fprintf(stream, "%dus", value);	}    }  else    fprintf(stream, " limit:%d", value);}#endif	/* WIRELESS_EXT > 10 *//*********************** ADDRESS SUBROUTINES ************************//* * This section is mostly a cut & past from net-tools-1.2.0 * manage address display and input... *//*------------------------------------------------------------------*//* * Check if interface support the right address types... */intcheck_addr_type(int	skfd,		char *	ifname){  struct ifreq		ifr;  /* Get the type of interface address */  strcpy(ifr.ifr_name, ifname);  if((ioctl(skfd, SIOCGIFADDR, &ifr) < 0) ||     (ifr.ifr_addr.sa_family !=  AF_INET))    {      /* Deep trouble... */      fprintf(stderr, "Interface %s doesn't support IP addresses\n", ifname);      return(-1);    }#ifdef DEBUG  printf("Interface : %d - 0x%lX\n", ifr.ifr_addr.sa_family,	 *((unsigned long *) ifr.ifr_addr.sa_data));#endif  /* Get the type of hardware address */  strcpy(ifr.ifr_name, ifname);  if((ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0) ||     (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER))    {      /* Deep trouble... */      fprintf(stderr, "Interface %s doesn't support MAC addresses\n",	     ifname);      return(-1);    }#ifdef DEBUG  printf("Hardware : %d - %s\n", ifr.ifr_hwaddr.sa_family,	 pr_ether(ifr.ifr_hwaddr.sa_data));#endif  return(0);}/*------------------------------------------------------------------*//* * Display an Ethernet address in readable format. */char *pr_ether(unsigned char *ptr){  static char buff[64];  sprintf(buff, "%02X:%02X:%02X:%02X:%02X:%02X",	(ptr[0] & 0xFF), (ptr[1] & 0xFF), (ptr[2] & 0xFF),	(ptr[3] & 0xFF), (ptr[4] & 0xFF), (ptr[5] & 0xFF)  );  return(buff);}/*------------------------------------------------------------------*//* * Input an Ethernet address and convert to binary. */intin_ether(char *bufp, struct sockaddr *sap){  unsigned char *ptr;  char c, *orig;  int i, val;  sap->sa_family = ARPHRD_ETHER;  ptr = sap->sa_data;  i = 0;  orig = bufp;  while((*bufp != '\0') && (i < ETH_ALEN)) {	val = 0;	c = *bufp++;	if (isdigit(c)) val = c - '0';	  else if (c >= 'a' && c <= 'f') val = c - 'a' + 10;	  else if (c >= 'A' && c <= 'F') val = c - 'A' + 10;	  else {#ifdef DEBUG		fprintf(stderr, "in_ether(%s): invalid ether address!\n", orig);#endif		errno = EINVAL;		return(-1);	}	val <<= 4;	c = *bufp++;	if (isdigit(c)) val |= c - '0';	  else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10;	  else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10;	  else {#ifdef DEBUG		fprintf(stderr, "in_ether(%s): invalid ether address!\n", orig);#endif		errno = EINVAL;		return(-1);	}	*ptr++ = (unsigned char) (val & 0377);	i++;	/* We might get a semicolon here - not required. */	if (*bufp == ':') {		if (i == ETH_ALEN) {#ifdef DEBUG			fprintf(stderr, "in_ether(%s): trailing : ignored!\n",				orig)#endif						; /* nothing */		}		bufp++;	}  }  /* That's it.  Any trailing junk? */  if ((i == ETH_ALEN) && (*bufp != '\0')) {#ifdef DEBUG	fprintf(stderr, "in_ether(%s): trailing junk!\n", orig);	errno = EINVAL;	return(-1);#endif  }#ifdef DEBUG  fprintf(stderr, "in_ether(%s): %s\n", orig, pr_ether(sap->sa_data));#endif  return(0);}/*------------------------------------------------------------------*//* * Input an Internet address and convert to binary. */intin_inet(char *bufp, struct sockaddr *sap){  struct hostent *hp;  struct netent *np;  char *name = bufp;  struct sockaddr_in *sin = (struct sockaddr_in *) sap;  /* Grmpf. -FvK */  sin->sin_family = AF_INET;  sin->sin_port = 0;  /* Default is special, meaning 0.0.0.0. */  if (!strcmp(name, "default")) {	sin->sin_addr.s_addr = INADDR_ANY;	return(1);  }  /* Try the NETWORKS database to see if this is a known network. */  if ((np = getnetbyname(name)) != (struct netent *)NULL) {	sin->sin_addr.s_addr = htonl(np->n_net);	strcpy(name, np->n_name);	return(1);  }  if ((hp = gethostbyname(name)) == (struct hostent *)NULL) {	errno = h_errno;	return(-1);  }  memcpy((char *) &sin->sin_addr, (char *) hp->h_addr_list[0], hp->h_length);  strcpy(name, hp->h_name);  return(0);}/*------------------------------------------------------------------*//* * Input an address and convert to binary. */intin_addr(int		skfd,	char *		ifname,	char *		bufp,	struct sockaddr *sap){  /* Check if it is a hardware or IP address */  if(index(bufp, ':') == NULL)    {      struct sockaddr	if_address;      struct arpreq	arp_query;      /* Read interface address */      if(in_inet(bufp, &if_address) < 0)	{	  fprintf(stderr, "Invalid interface address %s\n", bufp);	  return(-1);	}      /* Translate IP addresses to MAC addresses */      memcpy((char *) &(arp_query.arp_pa),	     (char *) &if_address,	     sizeof(struct sockaddr));      arp_query.arp_ha.sa_family = 0;      arp_query.arp_flags = 0;      /* The following restrict the search to the interface only */      /* For old kernels which complain, just comment it... */      strcpy(arp_query.arp_dev, ifname);      if((ioctl(skfd, SIOCGARP, &arp_query) < 0) ||	 !(arp_query.arp_flags & ATF_COM))	{	  fprintf(stderr, "Arp failed for %s on %s... (%d)\nTry to ping the address before setting it.\n",		  bufp, ifname, errno);	  return(-1);	}      /* Store new MAC address */      memcpy((char *) sap,	     (char *) &(arp_query.arp_ha),	     sizeof(struct sockaddr));#ifdef DEBUG      printf("IP Address %s => Hw Address = %s\n",	     bufp, pr_ether(sap->sa_data));#endif    }  else	/* If it's an hardware address */    /* Get the hardware address */    if(in_ether(bufp, sap) < 0)      {	fprintf(stderr, "Invalid hardware address %s\n", bufp);	return(-1);      }#ifdef DEBUG  printf("Hw Address = %s\n", pr_ether(sap->sa_data));#endif  return(0);}/************************* MISC SUBROUTINES **************************//*------------------------------------------------------------------*//* */intbyte_size(int	args){  int	ret = args & IW_PRIV_SIZE_MASK;  if(((args & IW_PRIV_TYPE_MASK) == IW_PRIV_TYPE_INT) ||     ((args & IW_PRIV_TYPE_MASK) == IW_PRIV_TYPE_FLOAT))    ret <<= 2;  if((args & IW_PRIV_TYPE_MASK) == IW_PRIV_TYPE_NONE)    return 0;  return ret;}

⌨️ 快捷键说明

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