📄 iwconfig.c
字号:
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]); } IW_SET_EXT_ERR(skfd, ifname, SIOCSIWFRAG, &wrq, "Set Fragmentation Threshold"); continue; } /* ---------- Set operation mode ---------- */ if(!strcmp(args[i], "mode")) { int k; i++; if(i >= count) ABORT_ARG_NUM("Set Mode", SIOCSIWMODE); if(sscanf(args[i], "%i", &k) != 1) { k = 0; while((k < IW_NUM_OPER_MODE) && strncasecmp(args[i], iw_operation_mode[k], 3)) k++; } if((k >= IW_NUM_OPER_MODE) || (k < 0)) ABORT_ARG_TYPE("Set Mode", SIOCSIWMODE, args[i]); wrq.u.mode = k; IW_SET_EXT_ERR(skfd, ifname, SIOCSIWMODE, &wrq, "Set Mode"); continue; } /* ---------- Set Power Management ---------- */ if(!strncmp(args[i], "power", 3)) { if(++i >= count) ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER); if(!strcasecmp(args[i], "off")) wrq.u.power.disabled = 1; /* i.e. max size */ else if(!strcasecmp(args[i], "on")) { /* Get old Power info */ wrq.u.power.flags = 0; IW_GET_EXT_ERR(skfd, ifname, SIOCGIWPOWER, &wrq, "Set Power Management"); wrq.u.power.disabled = 0; } else { double temp; int gotone = 0; /* Default - nope */ wrq.u.power.flags = IW_POWER_ON; wrq.u.power.disabled = 0; /* Check value modifier */ if(!strcasecmp(args[i], "min")) { wrq.u.power.flags |= IW_POWER_MIN; if(++i >= count) ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER); } else if(!strcasecmp(args[i], "max")) { wrq.u.power.flags |= IW_POWER_MAX; if(++i >= count) ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER); } /* Check value type */ if(!strcasecmp(args[i], "period")) { wrq.u.power.flags |= IW_POWER_PERIOD; if(++i >= count) ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER); } else if(!strcasecmp(args[i], "timeout")) { wrq.u.power.flags |= IW_POWER_TIMEOUT; if(++i >= count) ABORT_ARG_NUM("Set Power Management", SIOCSIWPOWER); } /* Is there any value to grab ? */ if(sscanf(args[i], "%lg", &(temp)) == 1) { temp *= MEGA; /* default = s */ if(index(args[i], 'u')) temp /= MEGA; if(index(args[i], 'm')) temp /= KILO; wrq.u.power.value = (long) temp; if((wrq.u.power.flags & IW_POWER_TYPE) == 0) wrq.u.power.flags |= IW_POWER_PERIOD; ++i; gotone = 1; } /* Now, check the mode */ if(i < count) { if(!strcasecmp(args[i], "all")) wrq.u.power.flags |= IW_POWER_ALL_R; if(!strncasecmp(args[i], "unicast", 4)) wrq.u.power.flags |= IW_POWER_UNICAST_R; if(!strncasecmp(args[i], "multicast", 5)) wrq.u.power.flags |= IW_POWER_MULTICAST_R; if(!strncasecmp(args[i], "force", 5)) wrq.u.power.flags |= IW_POWER_FORCE_S; if(!strcasecmp(args[i], "repeat")) wrq.u.power.flags |= IW_POWER_REPEATER; if(wrq.u.power.flags & IW_POWER_MODE) { ++i; gotone = 1; } } if(!gotone) ABORT_ARG_TYPE("Set Power Management", SIOCSIWPOWER, args[i]); --i; } IW_SET_EXT_ERR(skfd, ifname, SIOCSIWPOWER, &wrq, "Set Power Management"); continue; } /* ---------- Set Transmit-Power ---------- */ if(!strncmp(args[i], "txpower", 3)) { struct iw_range range; if(++i >= count) ABORT_ARG_NUM("Set Tx Power", SIOCSIWTXPOW); /* Extract range info */ if(iw_get_range_info(skfd, ifname, &range) < 0) memset(&range, 0, sizeof(range)); /* Prepare the request */ wrq.u.txpower.value = -1; wrq.u.txpower.fixed = 1; wrq.u.txpower.disabled = 0; wrq.u.txpower.flags = IW_TXPOW_DBM; if(!strcasecmp(args[i], "off")) wrq.u.txpower.disabled = 1; /* i.e. turn radio off */ else if(!strcasecmp(args[i], "auto")) wrq.u.txpower.fixed = 0; /* i.e. use power control */ else { if(!strcasecmp(args[i], "on")) { /* Get old tx-power */ IW_GET_EXT_ERR(skfd, ifname, SIOCGIWTXPOW, &wrq, "Set Tx Power"); wrq.u.txpower.disabled = 0; } else { if(!strcasecmp(args[i], "fixed")) { /* Get old tx-power */ IW_GET_EXT_ERR(skfd, ifname, SIOCGIWTXPOW, &wrq, "Set Tx Power"); wrq.u.txpower.fixed = 1; wrq.u.txpower.disabled = 0; } else /* Should be a numeric value */ { int power; int ismwatt = 0; /* Get the value */ if(sscanf(args[i], "%i", &(power)) != 1) ABORT_ARG_TYPE("Set Tx Power", SIOCSIWTXPOW, args[i]); /* Check if milliWatt * We authorise a single 'm' as a shorthand for 'mW', * on the other hand a 'd' probably means 'dBm'... */ ismwatt = ((index(args[i], 'm') != NULL) && (index(args[i], 'd') == NULL)); /* We could check 'W' alone... Another time... */ /* Convert */ if(range.txpower_capa & IW_TXPOW_RELATIVE) { /* Can't convert */ if(ismwatt) ABORT_ARG_TYPE("Set Tx Power", SIOCSIWTXPOW, args[i]); } else if(range.txpower_capa & IW_TXPOW_MWATT) { if(!ismwatt) power = iw_dbm2mwatt(power); wrq.u.txpower.flags = IW_TXPOW_MWATT; } else { if(ismwatt) power = iw_mwatt2dbm(power); wrq.u.txpower.flags = IW_TXPOW_DBM; } wrq.u.txpower.value = power; /* Check for an additional argument */ if(((i+1) < count) && (!strcasecmp(args[i+1], "auto"))) { wrq.u.txpower.fixed = 0; ++i; } if(((i+1) < count) && (!strcasecmp(args[i+1], "fixed"))) { wrq.u.txpower.fixed = 1; ++i; } } } } IW_SET_EXT_ERR(skfd, ifname, SIOCSIWTXPOW, &wrq, "Set Tx Power"); continue; } /* ---------- Set Retry limit ---------- */ if(!strncmp(args[i], "retry", 3)) { double temp; int gotone = 0; if(++i >= count) ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY); /* Default - nope */ wrq.u.retry.flags = IW_RETRY_LIMIT; wrq.u.retry.disabled = 0; /* Check value modifier */ if(!strcasecmp(args[i], "min")) { wrq.u.retry.flags |= IW_RETRY_MIN; if(++i >= count) ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY); } else if(!strcasecmp(args[i], "max")) { wrq.u.retry.flags |= IW_RETRY_MAX; if(++i >= count) ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY); } /* Check value type */ if(!strcasecmp(args[i], "limit")) { wrq.u.retry.flags |= IW_RETRY_LIMIT; if(++i >= count) ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY); } else if(!strncasecmp(args[i], "lifetime", 4)) { wrq.u.retry.flags &= ~IW_RETRY_LIMIT; wrq.u.retry.flags |= IW_RETRY_LIFETIME; if(++i >= count) ABORT_ARG_NUM("Set Retry Limit", SIOCSIWRETRY); } /* Is there any value to grab ? */ if(sscanf(args[i], "%lg", &(temp)) == 1) { /* Limit is absolute, on the other hand lifetime is seconds */ if(!(wrq.u.retry.flags & IW_RETRY_LIMIT)) { /* Normalise lifetime */ temp *= MEGA; /* default = s */ if(index(args[i], 'u')) temp /= MEGA; if(index(args[i], 'm')) temp /= KILO; } wrq.u.retry.value = (long) temp; ++i; gotone = 1; } if(!gotone) ABORT_ARG_TYPE("Set Retry Limit", SIOCSIWRETRY, args[i]); --i; IW_SET_EXT_ERR(skfd, ifname, SIOCSIWRETRY, &wrq, "Set Retry Limit"); continue; } /* ---------- Other ---------- */ /* Here we have an unrecognised arg... */ fprintf(stderr, "Error : unrecognised wireless request \"%s\"\n", args[i]); return(-1); } /* for(index ... */ return(0);}/******************************* 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"); exit(-1); } /* No argument : show the list of all device + info */ if(argc == 1) iw_enum_devices(skfd, &print_info, NULL, 0); else /* Special case for help... */ if((!strcmp(argv[1], "-h")) || (!strcmp(argv[1], "--help"))) iw_usage(); else /* Special case for version... */ if(!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) goterr = iw_print_version_info("iwconfig"); else { /* '--' escape device name */ if((argc > 2) && !strcmp(argv[1], "--")) { argv++; argc--; } /* The device name must be the first argument */ if(argc == 2) print_info(skfd, argv[1], NULL, 0); else /* The other args on the line specify options to be set... */ goterr = set_info(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 + -