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

📄 iwconfig.c

📁 执行无线网卡的扫描命令的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
            }

          IW_SET_EXT_ERR(skfd, ifname, SIOCSIWFREQ, &wrq,
                         "Set Frequency");
          continue;
        }

      /* ---------- Set sensitivity ---------- */
      if(!strncmp(args[i], "sens", 4))
        {
          if(++i >= count)
            ABORT_ARG_NUM("Set Sensitivity", SIOCSIWSENS);
          if(sscanf(args[i], "%i", &(wrq.u.sens.value)) != 1)
            ABORT_ARG_TYPE("Set Sensitivity", SIOCSIWSENS, args[i]);

          IW_SET_EXT_ERR(skfd, ifname, SIOCSIWSENS, &wrq,
                         "Set Sensitivity");
          continue;
        }

      /* ---------- Set encryption stuff ---------- */
      if((!strncmp(args[i], "enc", 3)) ||
         (!strcmp(args[i], "key")))
        {
          unsigned char	key[IW_ENCODING_TOKEN_MAX];

          if(++i >= count)
            ABORT_ARG_NUM("Set Encode", SIOCSIWENCODE);

          if(!strcasecmp(args[i], "on"))
            {
              /* Get old encryption information */
              wrq.u.data.pointer = (caddr_t) key;
              wrq.u.data.length = IW_ENCODING_TOKEN_MAX;
              wrq.u.data.flags = 0;
              IW_GET_EXT_ERR(skfd, ifname, SIOCGIWENCODE, &wrq,
                             "Set Encode");
              wrq.u.data.flags &= ~IW_ENCODE_DISABLED;	/* Enable */
            }
          else
            {
              int	gotone = 0;
              int	oldone;
              int	keylen;
              int	temp;

              wrq.u.data.pointer = (caddr_t) NULL;
              wrq.u.data.flags = 0;
              wrq.u.data.length = 0;

              /* Allow arguments in any order (it's safe) */
              do
                {
                  oldone = gotone;

                  /* -- Check for the key -- */
                  if(i < count)
                    {
                      keylen = iw_in_key_full(skfd, ifname,
                                              args[i], key, &wrq.u.data.flags);
                      if(keylen > 0)
                        {
                          wrq.u.data.length = keylen;
                          wrq.u.data.pointer = (caddr_t) key;
                          ++i;
                          gotone++;
                        }
                    }

                  /* -- Check for token index -- */
                  if((i < count) &&
                     (sscanf(args[i], "[%i]", &temp) == 1) &&
                     (temp > 0) && (temp < IW_ENCODE_INDEX))
                    {
                      wrq.u.encoding.flags |= temp;
                      ++i;
                      gotone++;
                    }

                  /* -- Check the various flags -- */
                  if((i < count) && (!strcasecmp(args[i], "off")))
                    {
                      wrq.u.data.flags |= IW_ENCODE_DISABLED;
                      ++i;
                      gotone++;
                    }
                  if((i < count) && (!strcasecmp(args[i], "open")))
                    {
                      wrq.u.data.flags |= IW_ENCODE_OPEN;
                      ++i;
                      gotone++;
                    }
                  if((i < count) && (!strncasecmp(args[i], "restricted", 5)))
                    {
                      wrq.u.data.flags |= IW_ENCODE_RESTRICTED;
                      ++i;
                      gotone++;
                    }
                  if((i < count) && (!strncasecmp(args[i], "temporary", 4)))
                    {
                      wrq.u.data.flags |= IW_ENCODE_TEMP;
                      ++i;
                      gotone++;
                    }
                }
              while(gotone != oldone);

              /* Pointer is absent in new API */
              if(wrq.u.data.pointer == NULL)
                wrq.u.data.flags |= IW_ENCODE_NOKEY;

              /* Check if we have any invalid argument */
              if(!gotone)
                ABORT_ARG_TYPE("Set Encode", SIOCSIWENCODE, args[i]);
              /* Get back to last processed argument */
              --i;
            }

          IW_SET_EXT_ERR(skfd, ifname, SIOCSIWENCODE, &wrq,
                         "Set Encode");
          continue;
          }

      /* ---------- Set ESSID ---------- */
      if(!strcasecmp(args[i], "essid"))
        {
          char		essid[IW_ESSID_MAX_SIZE + 1];
          int		we_kernel_version;

          i++;
          if(i >= count)
            ABORT_ARG_NUM("Set ESSID", SIOCSIWESSID);
          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 */
                memset(essid, '\0', sizeof(essid));
                wrq.u.essid.pointer = (caddr_t) essid;
                wrq.u.essid.length = IW_ESSID_MAX_SIZE + 1;
                wrq.u.essid.flags = 0;
                IW_GET_EXT_ERR(skfd, ifname, SIOCGIWESSID, &wrq,
                               "Set ESSID");
                wrq.u.essid.flags = 1;
              }
            else
              {
                /* '-' or '--' allow to escape the ESSID string, allowing
                 * to set it to the string "any" or "off".
                 * This is a big ugly, but it will do for now */
                if((!strcmp(args[i], "-")) || (!strcmp(args[i], "--")))
                  {
                    i++;
                    if(i >= count)
                      ABORT_ARG_NUM("Set ESSID", SIOCSIWESSID);
                  }

                /* Check the size of what the user passed us to avoid
                 * buffer overflows */
                if(strlen(args[i]) > IW_ESSID_MAX_SIZE)
                  ABORT_ARG_SIZE("Set ESSID", SIOCSIWESSID, IW_ESSID_MAX_SIZE);
                else
                  {
                    int		temp;

                    wrq.u.essid.flags = 1;
                    strcpy(essid, args[i]);	/* Size checked, all clear */

                    /* Check for ESSID index */
                    if(((i+1) < count) &&
                       (sscanf(args[i+1], "[%i]", &temp) == 1) &&
                       (temp > 0) && (temp < IW_ENCODE_INDEX))
                      {
                        wrq.u.essid.flags = temp;
                        ++i;
                      }
                  }
              }

          /* Get version from kernel, device may not have range... */
          we_kernel_version = iw_get_kernel_we_version();

          /* Finally set the ESSID value */
          wrq.u.essid.pointer = (caddr_t) essid;
          wrq.u.essid.length = strlen(essid) + 1;
          if(we_kernel_version > 20)
            wrq.u.essid.length--;
          IW_SET_EXT_ERR(skfd, ifname, SIOCSIWESSID, &wrq,
                         "Set ESSID");
          continue;
        }

      /* ---------- Set AP address ---------- */
      if(!strcasecmp(args[i], "ap"))
        {
          if(++i >= count)
            ABORT_ARG_NUM("Set AP Address", SIOCSIWAP);

          if((!strcasecmp(args[i], "auto")) ||
             (!strcasecmp(args[i], "any")))
            {
              /* Send a broadcast address */
              iw_broad_ether(&(wrq.u.ap_addr));
            }
          else
            {
              if(!strcasecmp(args[i], "off"))
                {
                  /* Send a NULL address */
                  iw_null_ether(&(wrq.u.ap_addr));
                }
              else
                {
                  /* Get the address and check if the interface supports it */
                  if(iw_in_addr(skfd, ifname, args[i++], &(wrq.u.ap_addr)) < 0)
                    ABORT_ARG_TYPE("Set AP Address", SIOCSIWAP, args[i-1]);
                }
            }

          IW_SET_EXT_ERR(skfd, ifname, SIOCSIWAP, &wrq,
                         "Set AP Address");
          continue;
        }

      /* ---------- Set NickName ---------- */
      if(!strncmp(args[i], "nick", 4))
        {
          int		we_kernel_version;

          i++;
          if(i >= count)
            ABORT_ARG_NUM("Set Nickname", SIOCSIWNICKN);
          if(strlen(args[i]) > IW_ESSID_MAX_SIZE)
            ABORT_ARG_SIZE("Set Nickname", SIOCSIWNICKN, IW_ESSID_MAX_SIZE);

          we_kernel_version = iw_get_kernel_we_version();

          wrq.u.essid.pointer = (caddr_t) args[i];
          wrq.u.essid.length = strlen(args[i]) + 1;
          if(we_kernel_version > 20)
            wrq.u.essid.length--;
          IW_SET_EXT_ERR(skfd, ifname, SIOCSIWNICKN, &wrq,
                         "Set Nickname");
          continue;
        }

      /* ---------- Set Bit-Rate ---------- */
      if((!strncmp(args[i], "bit", 3)) ||
         (!strcmp(args[i], "rate")))
        {
          if(++i >= count)
            ABORT_ARG_NUM("Set Bit Rate", SIOCSIWRATE);
          if(!strcasecmp(args[i], "auto"))
            {
              wrq.u.bitrate.value = -1;
              wrq.u.bitrate.fixed = 0;
            }
          else
            {
              if(!strcasecmp(args[i], "fixed"))
                {
                  /* Get old bitrate */
                  IW_GET_EXT_ERR(skfd, ifname, SIOCGIWRATE, &wrq,
                                 "Set Bit Rate");
                  wrq.u.bitrate.fixed = 1;
                }
              else			/* Should be a numeric value */
                {
                  double		brate;

                  if(sscanf(args[i], "%lg", &(brate)) != 1)
                    ABORT_ARG_TYPE("Set Bit Rate", SIOCSIWRATE, args[i]);
                  if(index(args[i], 'G')) brate *= GIGA;
                  if(index(args[i], 'M')) brate *= MEGA;
                  if(index(args[i], 'k')) brate *= KILO;
                  wrq.u.bitrate.value = (long) brate;
                  wrq.u.bitrate.fixed = 1;

                  /* Check for an additional argument */
                  if(((i+1) < count) &&
                     (!strcasecmp(args[i+1], "auto")))
                    {
                      wrq.u.bitrate.fixed = 0;
                      ++i;
                    }
                  if(((i+1) < count) &&
                     (!strcasecmp(args[i+1], "fixed")))
                    {
                      wrq.u.bitrate.fixed = 1;
                      ++i;
                    }
                }
            }

          IW_SET_EXT_ERR(skfd, ifname, SIOCSIWRATE, &wrq,
                         "Set Bit Rate");
          continue;
        }

      /* ---------- Set RTS threshold ---------- */
      if(!strncasecmp(args[i], "rts", 3))
        {
          i++;
          if(i >= count)
            ABORT_ARG_NUM("Set RTS Threshold", SIOCSIWRTS);
          wrq.u.rts.value = -1;
          wrq.u.rts.fixed = 1;
          wrq.u.rts.disabled = 0;
          if(!strcasecmp(args[i], "off"))
            wrq.u.rts.disabled = 1;	/* i.e. max size */
          else
            if(!strcasecmp(args[i], "auto"))
              wrq.u.rts.fixed = 0;
            else
              {
                if(!strcasecmp(args[i], "fixed"))
                  {
                    /* Get old RTS threshold */
                    IW_GET_EXT_ERR(skfd, ifname, SIOCGIWRTS, &wrq,
                                   "Set RTS Threshold");
                    wrq.u.rts.fixed = 1;
                  }
                else			/* Should be a numeric value */
                  if(sscanf(args[i], "%li", (unsigned long *) &(wrq.u.rts.value))
                     != 1)
                    ABORT_ARG_TYPE("Set RTS Threshold", SIOCSIWRTS, args[i]);
            }

          IW_SET_EXT_ERR(skfd, ifname, SIOCSIWRTS, &wrq,
                         "Set RTS Threshold");
          continue;
        }

      /* ---------- Set fragmentation threshold ---------- */
      if(!strncmp(args[i], "frag", 4))
        {
          i++;
          if(i >= count)
            ABORT_ARG_NUM("Set Fragmentation Threshold", SIOCSIWFRAG);
          wrq.u.frag.value = -1;
          wrq.u.frag.fixed = 1;
          wrq.u.frag.disabled = 0;
          if(!strcasecmp(args[i], "off"))
            wrq.u.frag.disabled = 1;	/* i.e. max size */
          else
            if(!strcasecmp(args[i], "auto"))
              wrq.u.frag.fixed = 0;
            else
              {
                if(!strcasecmp(args[i], "fixed"))
                  {
                    /* Get old fragmentation threshold */
                    IW_GET_EXT_ERR(skfd, ifname, SIOCGIWFRAG, &wrq,
                                   "Set Fragmentation Threshold");
                    wrq.u.frag.fixed = 1;
                  }
                else			/* Should be a numeric value */
                  if(sscanf(args[i], "%li",
                            (unsigned long *) &(wrq.u.frag.value))
                     != 1)
                    ABORT_ARG_TYPE("Set Fragmentation Threshold", SIOCSIWFRAG,
                                   args[i]);
            }

⌨️ 快捷键说明

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