Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/wiconfig - Process all passed option rather than ig...



details:   https://anonhg.NetBSD.org/src/rev/bd2f31fc3bd0
branches:  trunk
changeset: 494408:bd2f31fc3bd0
user:      enami <enami%NetBSD.org@localhost>
date:      Thu Jul 06 03:37:26 2000 +0000

description:
- Process all passed option rather than ignoring silently except the first one.
- Centerize the check whether an interface is specified.
- Print maximum data length.
- Swap wi_type and wi_code in struct wi_table so that wi_type matches with
  wi_type in wi_req.

diffstat:

 usr.sbin/wiconfig/wiconfig.c |  342 ++++++++++++++++++++++--------------------
 1 files changed, 179 insertions(+), 163 deletions(-)

diffs (truncated from 497 to 300 lines):

diff -r ef804f24de09 -r bd2f31fc3bd0 usr.sbin/wiconfig/wiconfig.c
--- a/usr.sbin/wiconfig/wiconfig.c      Thu Jul 06 03:17:19 2000 +0000
+++ b/usr.sbin/wiconfig/wiconfig.c      Thu Jul 06 03:37:26 2000 +0000
@@ -29,7 +29,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
- *     $Id: wiconfig.c,v 1.6 2000/06/24 04:15:49 sommerfeld Exp $
+ *     $Id: wiconfig.c,v 1.7 2000/07/06 03:37:26 enami Exp $
  */
 
 #include <sys/types.h>
@@ -67,9 +67,24 @@
 static const char copyright[] = "@(#) Copyright (c) 1997, 1998, 1999\
        Bill Paul. All rights reserved.";
 static const char rcsid[] =
-       "@(#) $Id: wiconfig.c,v 1.6 2000/06/24 04:15:49 sommerfeld Exp $";
+       "@(#) $Id: wiconfig.c,v 1.7 2000/07/06 03:37:26 enami Exp $";
 #endif
 
+struct wi_table {
+       int wi_type;
+       int wi_code;
+#define        WI_NONE                 0x00
+#define        WI_STRING               0x01
+#define        WI_BOOL                 0x02
+#define        WI_WORDS                0x03
+#define        WI_HEXBYTES             0x04
+#define        WI_KEYSTRUCT            0x05
+       char *wi_label;                 /* label used to print info */
+       int wi_opt;                     /* option character to set this */
+       char *wi_desc;
+       char *wi_optval;
+};
+
 static void wi_getval          __P((char *, struct wi_req *));
 static void wi_setval          __P((char *, struct wi_req *));
 static void wi_printstr                __P((struct wi_req *));
@@ -84,7 +99,9 @@
 static void wi_setkeys         __P((char *, char *, int));
 static void wi_printkeys       __P((struct wi_req *));
 static void wi_dumpstats       __P((char *));
-static void usage              __P((char *));
+static void usage              __P((void));
+static struct wi_table *
+       wi_optlookup __P((struct wi_table *, int));
 static int  wi_hex2int(char c);
 static void wi_str2key         __P((char *, struct wi_key *));
 int main __P((int argc, char **argv));
@@ -96,9 +113,6 @@
        struct ifreq            ifr;
        int                     s;
 
-       if (iface == NULL)
-               errx(1, "must specify interface name");
-
        bzero((char *)&ifr, sizeof(ifr));
 
        strcpy(ifr.ifr_name, iface);
@@ -175,12 +189,6 @@
 {
        struct wi_req           wreq;
 
-       if (iface == NULL)
-               errx(1, "must specify interface name");
-
-       if (str == NULL)
-               errx(1, "must specify string");
-
        bzero((char *)&wreq, sizeof(wreq));
 
        if (strlen(str) > 30)
@@ -204,9 +212,6 @@
 {
        struct wi_req           wreq;
 
-       if (iface == NULL)
-               errx(1, "must specify interface name");
-
        bzero((char *)&wreq, sizeof(wreq));
 
        wreq.wi_type = code;
@@ -225,9 +230,6 @@
 {
        struct wi_req           wreq;
 
-       if (iface == NULL)
-               errx(1, "must specify interface name");
-
        bzero((char *)&wreq, sizeof(wreq));
 
        wreq.wi_type = code;
@@ -246,13 +248,7 @@
 {
        struct ether_addr       *addr;
 
-       if (iface == NULL)
-               errx(1, "must specify interface name");
-       if (str == NULL)
-               errx(1, "must specify address");
-
        addr = ether_aton(str);
-
        if (addr == NULL)
                errx(1, "badly formatted address");
 
@@ -309,9 +305,6 @@
         struct wi_ltv_keys      *keys;
         struct wi_key           *k;
 
-       if (iface == NULL)
-               errx(1, "must specify interface name");
-
         bzero((char *)&wreq, sizeof(wreq));
         wreq.wi_len = WI_MAX_DATALEN;
         wreq.wi_type = WI_RID_WEP_AVAIL;
@@ -427,49 +420,71 @@
        return;
 }
 
-#define WI_STRING              0x01
-#define WI_BOOL                        0x02
-#define WI_WORDS               0x03
-#define WI_HEXBYTES            0x04
-#define WI_KEYSTRUCT            0x05
-
-struct wi_table {
-       int                     wi_code;
-       int                     wi_type;
-       char                    *wi_str;
-};
-
 static struct wi_table wi_table[] = {
        { WI_RID_SERIALNO, WI_STRING, "NIC serial number:\t\t\t" },
-       { WI_RID_NODENAME, WI_STRING, "Station name:\t\t\t\t" },
-       { WI_RID_OWN_SSID, WI_STRING, "SSID for IBSS creation:\t\t\t" },
+       { WI_RID_NODENAME, WI_STRING, "Station name:\t\t\t\t",
+           's', "station name" },
+       { WI_RID_OWN_SSID, WI_STRING, "SSID for IBSS creation:\t\t\t",
+           'q', "own SSID" },
        { WI_RID_CURRENT_SSID, WI_STRING, "Current netname (SSID):\t\t\t" },
-       { WI_RID_DESIRED_SSID, WI_STRING, "Desired netname (SSID):\t\t\t" },
+       { WI_RID_DESIRED_SSID, WI_STRING, "Desired netname (SSID):\t\t\t",
+           'n', "network name" },
        { WI_RID_CURRENT_BSSID, WI_HEXBYTES, "Current BSSID:\t\t\t\t" },
        { WI_RID_CHANNEL_LIST, WI_WORDS, "Channel list:\t\t\t\t" },
-       { WI_RID_OWN_CHNL, WI_WORDS, "IBSS channel:\t\t\t\t" },
+       { WI_RID_OWN_CHNL, WI_WORDS, "IBSS channel:\t\t\t\t",
+           'f', "frequency" },
        { WI_RID_CURRENT_CHAN, WI_WORDS, "Current channel:\t\t\t" },
        { WI_RID_COMMS_QUALITY, WI_WORDS, "Comms quality/signal/noise:\t\t" },
        { WI_RID_PROMISC, WI_BOOL, "Promiscuous mode:\t\t\t" },
-       { WI_RID_PORTTYPE, WI_WORDS, "Port type (1=BSS, 3=ad-hoc):\t\t"},
-       { WI_RID_MAC_NODE, WI_HEXBYTES, "MAC address:\t\t\t\t"},
-       { WI_RID_TX_RATE, WI_WORDS, "TX rate (selection):\t\t\t"},
+       { WI_RID_PORTTYPE, WI_WORDS, "Port type (1=BSS, 3=ad-hoc):\t\t",
+           'p', "port type" },
+       { WI_RID_MAC_NODE, WI_HEXBYTES, "MAC address:\t\t\t\t",
+           'm', "MAC address" },
+       { WI_RID_TX_RATE, WI_WORDS, "TX rate (selection):\t\t\t",
+           't', "TX rate" },
        { WI_RID_CUR_TX_RATE, WI_WORDS, "TX rate (actual speed):\t\t\t"},
-       { WI_RID_RTS_THRESH, WI_WORDS, "RTS/CTS handshake threshold:\t\t"},
-       { WI_RID_CREATE_IBSS, WI_BOOL, "Create IBSS:\t\t\t\t" },
-       { WI_RID_SYSTEM_SCALE, WI_WORDS, "Access point density:\t\t\t" },
-       { WI_RID_PM_ENABLED, WI_WORDS, "Power Mgmt (1=on, 0=off):\t\t" },
-       { WI_RID_MAX_SLEEP, WI_WORDS, "Max sleep time:\t\t\t\t" },
-       { 0, NULL }
+       { WI_RID_MAX_DATALEN, WI_WORDS, "Maximum data length:\t\t\t",
+           'd', "maximum data length" },
+       { WI_RID_RTS_THRESH, WI_WORDS, "RTS/CTS handshake threshold:\t\t",
+           'r', "RTS threshold" },
+       { WI_RID_CREATE_IBSS, WI_BOOL, "Create IBSS:\t\t\t\t",
+           'c', "create ibss" },
+       { WI_RID_SYSTEM_SCALE, WI_WORDS, "Access point density:\t\t\t",
+           'a', "system scale" },
+       { WI_RID_PM_ENABLED, WI_WORDS, "Power Mgmt (1=on, 0=off):\t\t",
+           'P', "power management enabled" },
+       { WI_RID_MAX_SLEEP, WI_WORDS, "Max sleep time:\t\t\t\t",
+           'S', "max sleep duration" },
+       { 0, WI_NONE }
 };
 
 static struct wi_table wi_crypt_table[] = {
-        { WI_RID_ENCRYPTION, WI_BOOL, "WEP encryption:\t\t\t\t" },
+       { WI_RID_ENCRYPTION, WI_BOOL, "WEP encryption:\t\t\t\t",
+           'e', "encryption" },
         { WI_RID_TX_CRYPT_KEY, WI_WORDS, "TX encryption key:\t\t\t" },
         { WI_RID_DEFLT_CRYPT_KEYS, WI_KEYSTRUCT, "Encryption keys:\t\t\t" },
-        { 0, NULL }
+       { 0, WI_NONE }
+};
+
+static struct wi_table *wi_tables[] = {
+       wi_table,
+       wi_crypt_table,
+       NULL
 };
 
+static struct wi_table *
+wi_optlookup(table, opt)
+       struct wi_table *table;
+       int opt;
+{
+       struct wi_table *wt;
+
+       for (wt = table; wt->wi_type != 0; wt++)
+               if (wt->wi_opt == opt)
+                       return (wt);
+       return (NULL);
+}
+
 static void wi_dumpinfo(iface)
        char                    *iface;
 {
@@ -487,15 +502,15 @@
 
        w = wi_table;
 
-       for (i = 0; w[i].wi_type; i++) {
+       for (i = 0; w[i].wi_code != WI_NONE; i++) {
                bzero((char *)&wreq, sizeof(wreq));
 
                wreq.wi_len = WI_MAX_DATALEN;
-               wreq.wi_type = w[i].wi_code;
+               wreq.wi_type = w[i].wi_type;
 
                wi_getval(iface, &wreq);
-               printf("%s", w[i].wi_str);
-               switch (w[i].wi_type) {
+               printf("%s", w[i].wi_label);
+               switch (w[i].wi_code) {
                case WI_STRING:
                        wi_printstr(&wreq);
                        break;
@@ -516,15 +531,15 @@
 
        if (has_wep) {
                w = wi_crypt_table;
-               for (i = 0; w[i].wi_type; i++) {
+               for (i = 0; w[i].wi_code != WI_NONE; i++) {
                        bzero((char *)&wreq, sizeof(wreq));
 
                        wreq.wi_len = WI_MAX_DATALEN;
-                       wreq.wi_type = w[i].wi_code;
+                       wreq.wi_type = w[i].wi_type;
 
                        wi_getval(iface, &wreq);
-                       printf("%s", w[i].wi_str);
-                       switch (w[i].wi_type) {
+                       printf("%s", w[i].wi_label);
+                       switch (w[i].wi_code) {
                        case WI_STRING:
                                wi_printstr(&wreq);
                                break;
@@ -558,9 +573,6 @@
        struct wi_req           wreq;
        struct wi_counters      *c;
 
-       if (iface == NULL)
-               errx(1, "must specify interface name");
-
        bzero((char *)&wreq, sizeof(wreq));
        wreq.wi_len = WI_MAX_DATALEN;
        wreq.wi_type = WI_RID_IFACE_STATS;
@@ -613,16 +625,19 @@
        return;
 }
 
-static void usage(p)
-       char                    *p;
+static void
+usage()
 {
+       extern char *__progname;
+
        fprintf(stderr,
-           "usage: wiconfig interface "
+           "usage: %s interface "
            "[-o] [-t tx rate] [-n network name] [-s station name]\n"
            "       [-e 0|1] [-k key [-v 1|2|3|4]] [-T 1|2|3|4]\n"
            "       [-c 0|1] [-q SSID] [-p port type] [-a access point density]\n"
            "       [-m MAC address] [-d max data length] [-r RTS threshold]\n"
-           "       [-f frequency] [-P 0|1] [-S max sleep duration]\n");
+           "       [-f frequency] [-P 0|1] [-S max sleep duration]\n",
+           __progname);
        exit(1);
 }
 
@@ -630,11 +645,22 @@
        int                     argc;
        char                    *argv[];
 {
-       int                     ch;
-       char                    *iface = NULL;
-       char                    *p = argv[0];
-       char                    *key = NULL;
-       int                     modifier = 0;
+       struct wi_table *wt, **table;
+       char *iface, *key, *keyv[4], *tx_crypt_key;



Home | Main Index | Thread Index | Old Index