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

📄 iwpriv.c

📁 This package contains the Wireless tools, used to manipulate the Wireless Extensions. The Wireless
💻 C
📖 第 1 页 / 共 2 页
字号:
	{	case IW_PRIV_TYPE_BYTE:	  /* Display args */	  for(j = 0; j < n; j++)	    printf("%d  ", buffer[j]);	  printf("\n");	  break;	case IW_PRIV_TYPE_INT:	  /* Display args */	  for(j = 0; j < n; j++)	    printf("%d  ", ((__s32 *) buffer)[j]);	  printf("\n");	  break;	case IW_PRIV_TYPE_CHAR:	  /* Display args */	  buffer[n] = '\0';	  printf("%s\n", buffer);	  break;	case IW_PRIV_TYPE_FLOAT:	  {	    double		freq;	    /* Display args */	    for(j = 0; j < n; j++)	      {		freq = iw_freq2float(((struct iw_freq *) buffer) + j);		if(freq >= GIGA)		  printf("%gG  ", freq / GIGA);		else		  if(freq >= MEGA)		  printf("%gM  ", freq / MEGA);		else		  printf("%gk  ", freq / KILO);	      }	    printf("\n");	  }	  break;	case IW_PRIV_TYPE_ADDR:	  {	    char		scratch[128];	    struct sockaddr *	hwa;	    /* Display args */	    for(j = 0; j < n; j++)	      {		hwa = ((struct sockaddr *) buffer) + j;		if(j)		  printf("           %.*s", 			 (int) strlen(cmdname), "                ");		printf("%s\n", iw_saether_ntop(hwa, scratch));	      }	  }	  break;	default:	  fprintf(stderr, "Not yet implemented...\n");	  return(-1);	}    }	/* if args to set */  return(0);}/*------------------------------------------------------------------*//* * Execute a private command on the interface */static inline intset_private(int		skfd,		/* Socket */	    char *	args[],		/* Command line args */	    int		count,		/* Args count */	    char *	ifname)		/* Dev name */{  iwprivargs *	priv;  int		number;		/* Max of private ioctl */  int		ret;  /* Read the private ioctls */  number = iw_get_priv_info(skfd, ifname, &priv);  /* Is there any ? */  if(number <= 0)    {      /* Should I skip this message ? */      fprintf(stderr, "%-8.16s  no private ioctls.\n\n",	      ifname);      if(priv)	free(priv);      return(-1);    }  /* Do it */  ret = set_private_cmd(skfd, args + 1, count - 1, ifname, args[0],			priv, number);  free(priv);  return(ret);}/************************ CATALOG FUNCTIONS ************************//*------------------------------------------------------------------*//* * Print on the screen in a neat fashion the list of private ioctls * for the device. */static intprint_priv_info(int		skfd,		char *		ifname,		char *		args[],		int		count){  int		k;  iwprivargs *	priv;  int		n;  /* Avoid "Unused parameter" warning */  args = args; count = count;  /* Read the private ioctls */  n = iw_get_priv_info(skfd, ifname, &priv);  /* Is there any ? */  if(n <= 0)    {      /* Should I skip this message ? */      fprintf(stderr, "%-8.16s  no private ioctls.\n\n",	      ifname);    }  else    {      printf("%-8.16s  Available private ioctls :\n", ifname);      /* Print them all */      for(k = 0; k < n; k++)	if(priv[k].name[0] != '\0')	  printf("          %-16.16s (%.4X) : set %3d %s & get %3d %s\n",		 priv[k].name, priv[k].cmd,		 priv[k].set_args & IW_PRIV_SIZE_MASK,		 argtype[(priv[k].set_args & IW_PRIV_TYPE_MASK) >> 12],		 priv[k].get_args & IW_PRIV_SIZE_MASK,		 argtype[(priv[k].get_args & IW_PRIV_TYPE_MASK) >> 12]);      printf("\n");    }  /* Cleanup */  if(priv)    free(priv);  return(0);}/*------------------------------------------------------------------*//* * Print on the screen in a neat fashion the list of private GET ioctl * data for the device and data returned by those. */static intprint_priv_all(int		skfd,	       char *		ifname,	       char *		args[],	       int		count){  int		k;  iwprivargs *	priv;  int		n;  /* Avoid "Unused parameter" warning */  args = args; count = count;  /* Read the private ioctls */  n = iw_get_priv_info(skfd, ifname, &priv);  /* Is there any ? */  if(n <= 0)    {      /* Should I skip this message ? */      fprintf(stderr, "%-8.16s  no private ioctls.\n\n",	      ifname);    }  else    {      printf("%-8.16s  Available read-only private ioctl :\n", ifname);      /* Print them all */      for(k = 0; k < n; k++)	/* We call all ioctls that don't have a null name, don't require	 * args and return some (avoid triggering "reset" commands) */	if((priv[k].name[0] != '\0') && (priv[k].set_args == 0) &&	   (priv[k].get_args != 0))	  set_private_cmd(skfd, NULL, 0, ifname, priv[k].name,			  priv, n);      printf("\n");    }  /* Cleanup */  if(priv)    free(priv);  return(0);}/********************** PRIVATE IOCTLS MANIPS ***********************//* * Convenient access to some private ioctls of some devices *//*------------------------------------------------------------------*//* * Set roaming mode on and off * Found in wavelan_cs driver * Note : this is obsolete, most 802.11 devices should use the * SIOCSIWAP request. */static intset_roaming(int		skfd,		/* Socket */	    char *	args[],		/* Command line args */	    int		count,		/* Args count */	    char *	ifname)		/* Dev name */{  u_char	buffer[1024];  struct iwreq		wrq;  int		i = 0;		/* Start with first arg */  int		k;  iwprivargs *	priv;  int		number;  int		roamcmd;  char		RoamState;		/* buffer to hold new roam state */  char		ChangeRoamState=0;	/* whether or not we are going to					   change roam states */  /* Read the private ioctls */  number = iw_get_priv_info(skfd, ifname, &priv);  /* Is there any ? */  if(number <= 0)    {      /* Should I skip this message ? */      fprintf(stderr, "%-8.16s  no private ioctls.\n\n",	      ifname);      if(priv)	free(priv);      return(-1);    }  /* Get the ioctl number */  k = -1;  while((++k < number) && strcmp(priv[k].name, "setroam"));  if(k == number)    {      fprintf(stderr, "This device doesn't support roaming\n");      free(priv);      return(-1);    }  roamcmd = priv[k].cmd;  /* Cleanup */  free(priv);  if(count != 1)    {      iw_usage();      return(-1);    }  if(!strcasecmp(args[i], "on"))    {      printf("%-8.16s  enable roaming\n", ifname);      if(!number)	{	  fprintf(stderr, "This device doesn't support roaming\n");	  return(-1);	}      ChangeRoamState=1;      RoamState=1;    }  else    if(!strcasecmp(args[i], "off"))      {	i++;	printf("%-8.16s  disable roaming\n",  ifname);	if(!number)	  {	    fprintf(stderr, "This device doesn't support roaming\n");	    return(-1);	  }	ChangeRoamState=1;	RoamState=0;      }    else      {	iw_usage();	return(-1);      }  if(ChangeRoamState)    {      strncpy(wrq.ifr_name, ifname, IFNAMSIZ);      buffer[0]=RoamState;      memcpy(wrq.u.name, &buffer, IFNAMSIZ);      if(ioctl(skfd, roamcmd, &wrq) < 0)	{	  fprintf(stderr, "Roaming support is broken.\n");	  return(-1);	}    }  return(0);}/*------------------------------------------------------------------*//* * Get and set the port type * Found in wavelan2_cs and wvlan_cs drivers * TODO : Add support for HostAP ? */static intport_type(int		skfd,		/* Socket */	  char *	args[],		/* Command line args */	  int		count,		/* Args count */	  char *	ifname)		/* Dev name */{  struct iwreq	wrq;  int		i = 0;		/* Start with first arg */  int		k;  iwprivargs *	priv;  int		number;  char		ptype = 0;  char *	modes[] = { "invalid", "managed (BSS)", "reserved", "ad-hoc" };  /* Read the private ioctls */  number = iw_get_priv_info(skfd, ifname, &priv);  /* Is there any ? */  if(number <= 0)    {      /* Should I skip this message ? */      fprintf(stderr, "%-8.16s  no private ioctls.\n\n", ifname);      if(priv)	free(priv);      return(-1);    }  /* Arguments ? */  if(count == 0)    {      /* So, we just want to see the current value... */      k = -1;      while((++k < number) && strcmp(priv[k].name, "gport_type") &&	     strcmp(priv[k].name, "get_port"));      if(k == number)	{	  fprintf(stderr, "This device doesn't support getting port type\n");	  goto err;	}      strncpy(wrq.ifr_name, ifname, IFNAMSIZ);      /* Get it */      if(ioctl(skfd, priv[k].cmd, &wrq) < 0)	{	  fprintf(stderr, "Port type support is broken.\n");	  goto err;	}      ptype = *wrq.u.name;      /* Display it */      printf("%-8.16s  Current port mode is %s <port type is %d>.\n\n",	     ifname, modes[(int) ptype], ptype);      free(priv);      return(0);    }  if(count != 1)    {      iw_usage();      goto err;    }  /* Read it */  /* As a string... */  k = 0;  while((k < 4) && strncasecmp(args[i], modes[k], 2))    k++;  if(k < 4)    ptype = k;  else    /* ...or as an integer */    if(sscanf(args[i], "%i", (int *) &ptype) != 1)      {	iw_usage();	goto err;      }    k = -1;  while((++k < number) && strcmp(priv[k].name, "sport_type") &&	strcmp(priv[k].name, "set_port"));  if(k == number)    {      fprintf(stderr, "This device doesn't support setting port type\n");      goto err;    }  strncpy(wrq.ifr_name, ifname, IFNAMSIZ);  *(wrq.u.name) = ptype;  if(ioctl(skfd, priv[k].cmd, &wrq) < 0)    {      fprintf(stderr, "Invalid port type (or setting not allowed)\n");      goto err;    }  free(priv);  return(0); err:  free(priv);  return(-1);}/******************************* MAIN ********************************//*------------------------------------------------------------------*//* * The main ! */intmain(int	argc,     char **	argv){  int skfd;		/* generic raw socket desc.	*/  int goterr = 0;  /* Create a channel to the NET kernel. */  if((skfd = iw_sockets_open()) < 0)    {      perror("socket");      return(-1);    }  /* No argument : show the list of all devices + ioctl list */  if(argc == 1)    iw_enum_devices(skfd, &print_priv_info, NULL, 0);  else    /* Special cases take one... */    /* All */    if((!strncmp(argv[1], "-a", 2)) || (!strcmp(argv[1], "--all")))      iw_enum_devices(skfd, &print_priv_all, NULL, 0);    else      /* Help */      if((!strncmp(argv[1], "-h", 2)) || (!strcmp(argv[1], "--help")))	iw_usage();      else	/* Version */	if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))	  goterr = iw_print_version_info("iwpriv");	else	  /* The device name must be the first argument */	  /* Name only : show for that device only */	  if(argc == 2)	    print_priv_info(skfd, argv[1], NULL, 0);	  else	    /* Special cases take two... */	    /* All */	    if((!strncmp(argv[2], "-a", 2)) ||	       (!strcmp(argv[2], "--all")))	      print_priv_all(skfd, argv[1], NULL, 0);	    else	      /* Roaming */	      if(!strncmp(argv[2], "roam", 4))		goterr = set_roaming(skfd, argv + 3, argc - 3, argv[1]);	      else		/* Port type */		if(!strncmp(argv[2], "port", 4))		  goterr = port_type(skfd, argv + 3, argc - 3, argv[1]);		else		  /*-------------*/		  /* Otherwise, it's a private ioctl */		  goterr = set_private(skfd, argv + 2, argc - 2, argv[1]);  /* Close the socket. */  iw_sockets_close(skfd);  return(goterr);}

⌨️ 快捷键说明

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