📄 mapi.c
字号:
// iw_usage(); if(sscanf(Args[i], "%d", &(wrq.u.sens.value)) != 1); // iw_usage(); if(ioctl(SocketFileDescriptor, SIOCSIWSENS, &wrq) < 0) { fprintf(stderr, "SIOCSIWSENS: %s\n", strerror(errno)); return(-1); } continue; } /* ---------- Set encryption stuff ---------- */ if((!strncmp(Args[i], "enc", 3)) || (!strcmp(Args[i], "key"))) { unsigned char key[IW_ENCODING_TOKEN_MAX]; if(++i >= Count) ; //iw_usage(); if(!strcasecmp(Args[i], "on")) { /* Get old encryption information */ wrq.u.data.pointer = (caddr_t) key; wrq.u.data.length = 0; wrq.u.data.flags = 0; if(ioctl(SocketFileDescriptor, SIOCGIWENCODE, &wrq) < 0) { fprintf(stderr, "SIOCGIWENCODE: %s\n", strerror(errno)); return(-1); } strcpy(wrq.ifr_name, InterfaceName); wrq.u.data.flags &= ~IW_ENCODE_DISABLED; /* Enable */ } else { char * buff; char * p; int temp; int k = 0; int gotone = 1; wrq.u.data.pointer = (caddr_t) NULL; wrq.u.data.flags = 0; wrq.u.data.length = 0; /* -- Check for the key -- */ if(!strncmp(Args[i], "s:", 2)) { /* First case : as an ASCII string */ wrq.u.data.length = strlen(Args[i] + 2); if(wrq.u.data.length > IW_ENCODING_TOKEN_MAX) wrq.u.data.length = IW_ENCODING_TOKEN_MAX; strncpy(key, Args[i] + 2, wrq.u.data.length); wrq.u.data.pointer = (caddr_t) key; ++i; gotone = 1; } else { /* Second case : has hexadecimal digits */ p = buff = malloc(strlen(Args[i]) + 1); strcpy(buff, Args[i]); p = strtok(buff, "-:;.,"); while(p != (char *) NULL) { if(sscanf(p, "%2X", &temp) != 1) { gotone = 0; break; } key[k++] = (unsigned char) (temp & 0xFF); if(strlen(p) > 2) /* Token not finished yet */ p += 2; else p = strtok((char *) NULL, "-:;.,"); } free(buff); if(gotone) { ++i; wrq.u.data.length = k; wrq.u.data.pointer = (caddr_t) key; } } /* -- Check for token index -- */ if((i < Count) && (sscanf(Args[i], "[%d]", &temp) == 1) && (temp > 0) && (temp < IW_ENCODE_INDEX)) { wrq.u.encoding.flags |= temp; ++i; gotone = 1; } /* -- Check the various flags -- */ if(i < Count) { if(!strcasecmp(Args[i], "off")) wrq.u.data.flags |= IW_ENCODE_DISABLED; if(!strcasecmp(Args[i], "open")) wrq.u.data.flags |= IW_ENCODE_OPEN; if(!strncasecmp(Args[i], "restricted", 5)) wrq.u.data.flags |= IW_ENCODE_RESTRICTED; if(wrq.u.data.flags & IW_ENCODE_FLAGS) { ++i; gotone = 1; } } if(!gotone) ; //iw_usage(); --i; } if(ioctl(SocketFileDescriptor, SIOCSIWENCODE, &wrq) < 0) { fprintf(stderr, "SIOCSIWENCODE(%d): %s\n", errno, strerror(errno)); return(-1); } continue; } /* ---------- Set ESSID ---------- */ if(!strcasecmp(Args[i], "essid")) { char essid[IW_ESSID_MAX_SIZE + 1]; i++; if(i >= Count) ; // iw_usage(); 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 */ wrq.u.essid.pointer = (caddr_t) essid; wrq.u.essid.length = 0; wrq.u.essid.flags = 0; if(ioctl(SocketFileDescriptor, SIOCGIWESSID, &wrq) < 0) { fprintf(stderr, "SIOCGIWESSID: %s\n", strerror(errno)); return(-1); } strcpy(wrq.ifr_name, InterfaceName); wrq.u.essid.flags = 1; } else if(strlen(Args[i]) > IW_ESSID_MAX_SIZE) { fprintf(stderr, "ESSID too long (max %d): ``%s''\n", IW_ESSID_MAX_SIZE, Args[i]); //iw_usage(); } else { wrq.u.essid.flags = 1; strcpy(essid, Args[i]); } wrq.u.essid.pointer = (caddr_t) essid; wrq.u.essid.length = strlen(essid) + 1; if(ioctl(SocketFileDescriptor, SIOCSIWESSID, &wrq) < 0) { fprintf(stderr, "SIOCSIWESSID: %s\n", strerror(errno)); return(-1); } continue; } /* ---------- Set AP address ---------- */ if(!strcasecmp(Args[i], "ap")) { if(++i >= Count); //iw_usage(); /* Check if we have valid address types */ if(check_addr_type(SocketFileDescriptor, InterfaceName) < 0) { fprintf(stderr, "%-8.8s Interface doesn't support MAC & IP addresses\n", InterfaceName); return(-1); } /* Get the address */ if(in_addr(SocketFileDescriptor, InterfaceName, Args[i++], &(wrq.u.ap_addr)) < 0) ;//iw_usage(); if(ioctl(SocketFileDescriptor, SIOCSIWAP, &wrq) < 0) { fprintf(stderr, "SIOCSIWAP: %s\n", strerror(errno)); return(-1); } continue; } /* ---------- Set NickName ---------- */ if(!strncmp(Args[i], "nick", 4)) { i++; if(i >= Count) ;//iw_usage(); if(strlen(Args[i]) > IW_ESSID_MAX_SIZE) { fprintf(stderr, "Name too long (max %d) : ``%s''\n", IW_ESSID_MAX_SIZE, Args[i]); //iw_usage(); } wrq.u.essid.pointer = (caddr_t) Args[i]; wrq.u.essid.length = strlen(Args[i]) + 1; if(ioctl(SocketFileDescriptor, SIOCSIWNICKN, &wrq) < 0) { fprintf(stderr, "SIOCSIWNICKN: %s\n", strerror(errno)); return(-1); } continue; } /* ---------- Set Bit-Rate ---------- */ if((!strncmp(Args[i], "bit", 3)) || (!strcmp(Args[i], "rate"))) { if(++i >= Count) ;//iw_usage(); if(!strcasecmp(Args[i], "auto")) { wrq.u.bitrate.value = -1; wrq.u.bitrate.fixed = 0; } else { if(!strcasecmp(Args[i], "fixed")) { /* Get old bitrate */ if(ioctl(SocketFileDescriptor, SIOCGIWRATE, &wrq) < 0) { fprintf(stderr, "SIOCGIWRATE: %s\n", strerror(errno)); return(-1); } strcpy(wrq.ifr_name, InterfaceName); wrq.u.bitrate.fixed = 1; } else /* Should be a numeric value */ { double brate; if(sscanf(Args[i], "%lg", &(brate)) != 1) ;//iw_usage(); 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(ioctl(SocketFileDescriptor, SIOCSIWRATE, &wrq) < 0) { fprintf(stderr, "SIOCSIWRATE: %s\n", strerror(errno)); return(-1); } continue; } /* ---------- Set RTS threshold ---------- */ if(!strncasecmp(Args[i], "rts", 3)) { i++; if(i >= Count) ;//iw_usage(); 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 */ if(ioctl(SocketFileDescriptor, SIOCGIWRTS, &wrq) < 0) { fprintf(stderr, "SIOCGIWRTS: %s\n", strerror(errno)); return(-1); } strcpy(wrq.ifr_name, InterfaceName); wrq.u.rts.fixed = 1; } else /* Should be a numeric value */ if(sscanf(Args[i], "%ld", (unsigned long *) &(wrq.u.rts.value)) != 1) ;//iw_usage(); } if(ioctl(SocketFileDescriptor, SIOCSIWRTS, &wrq) < 0) { fprintf(stderr, "SIOCSIWRTS: %s\n", strerror(errno)); return(-1); } continue; } /* ---------- Set fragmentation threshold ---------- */ if(!strncmp(Args[i], "frag", 4)) { i++; if(i >= Count) ;//iw_usage(); 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 */ if(ioctl(SocketFileDescriptor, SIOCGIWFRAG, &wrq) < 0) { fprintf(stderr, "SIOCGIWFRAG: %s\n", strerror(errno)); return(-1); } strcpy(wrq.ifr_name, InterfaceName); wrq.u.frag.fixed = 1; } else /* Should be a numeric value */ if(sscanf(Args[i], "%ld", (unsigned long *) &(wrq.u.frag.value)) != 1) ;//iw_usage(); } if(ioctl(SocketFileDescriptor, SIOCSIWFRAG, &wrq) < 0) { fprintf(stderr, "SIOCSIWFRAG: %s\n", strerror(errno)); return(-1); } continue; } /* ---------- Set operation mode ---------- */ if(!strcmp(Args[i], "mode")) { int k; i++; if(i >= Count) ;//iw_usage(); if(sscanf(Args[i], "%d", &k) != 1) { k = 0; while(k < 6 && strncasecmp(Args[i], OperationMode[k], 3)) k++; } if((k > 5) || (k < 0)) ;//iw_usage(); wrq.u.mode = k; if(ioctl(SocketFileDescriptor, SIOCSIWMODE, &wrq) < 0) { fprintf(stderr, "SIOCSIWMODE: %s\n", strerror(errno)); return(-1); } continue; } /* ---------- Set Power Management ---------- */ if(!strncmp(Args[i], "power", 3)) { if(++i >= Count) ;//iw_usage(); if(!strcasecmp(Args[i], "off")) wrq.u.power.disabled = 1; /* i.e. max size */ else if(!strcasecmp(Args[i], "on")) { /* Get old Power Info */ if(ioctl(SocketFileDescriptor, SIOCGIWPOWER, &wrq) < 0) { fprintf(stderr, "SIOCGIWFRAG: %s\n", strerror(errno)); return(-1); } strcpy(wrq.ifr_name, InterfaceName); 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], "period")) { wrq.u.power.flags = IW_POWER_PERIOD; if(++i >= Count) ;//iw_usage(); } else if(!strcasecmp(Args[i], "timeout")) { wrq.u.power.flags = IW_POWER_TIMEOUT; if(++i >= Count) ;//iw_usage(); } /* 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_ON) 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) ;//iw_usage(); --i; } if(ioctl(SocketFileDescriptor, SIOCSIWPOWER, &wrq) < 0) { fprintf(stderr, "SIOCSIWPOWER(%d): %s\n", errno, strerror(errno)); return(-1); } continue; } /* ---------- Other ---------- */ /* Here we have an unrecognised arg... */ fprintf(stderr, "Invalid argument : %s\n", Args[i]); ;//iw_usage(); return(-1); } /* for(index ... */ return(0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -