diff options
author | 2004-10-24 11:50:47 +0000 | |
---|---|---|
committer | 2004-10-24 11:50:47 +0000 | |
commit | 793925f4949bfbd53c2810b86451da6af9bc8842 (patch) | |
tree | 4a69a0a0e24d2ca545d0ed8571d16d17fabbf698 | |
parent | regen (diff) | |
download | wireguard-openbsd-793925f4949bfbd53c2810b86451da6af9bc8842.tar.xz wireguard-openbsd-793925f4949bfbd53c2810b86451da6af9bc8842.zip |
unify device selection
-rw-r--r-- | sbin/ancontrol/ancontrol.c | 36 | ||||
-rw-r--r-- | sbin/ipwcontrol/ipwcontrol.c | 22 | ||||
-rw-r--r-- | sbin/iwicontrol/iwicontrol.c | 23 | ||||
-rw-r--r-- | sbin/lmccontrol/lmccontrol.c | 35 | ||||
-rw-r--r-- | sbin/wicontrol/wicontrol.c | 25 |
5 files changed, 68 insertions, 73 deletions
diff --git a/sbin/ancontrol/ancontrol.c b/sbin/ancontrol/ancontrol.c index 5b408ff3a3f..70c744c309f 100644 --- a/sbin/ancontrol/ancontrol.c +++ b/sbin/ancontrol/ancontrol.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ancontrol.c,v 1.27 2004/08/19 18:26:52 jmc Exp $ */ +/* $OpenBSD: ancontrol.c,v 1.28 2004/10/24 11:50:47 deraadt Exp $ */ /* * Copyright (c) 2001 Eric Jackson <ericj@monkey.org> * @@ -129,9 +129,9 @@ int main(int, char **); #ifdef ANCACHE #define ACT_DUMPCACHE 31 #define ACT_ZEROCACHE 32 -#define OPTIONS "a:b:c:d:e:f:j:k:l:m:n:o:p:r:s:t:v:w:ACIK:NQSTW:Z" +#define OPTIONS "a:b:c:d:e:f:hi:j:k:l:m:n:o:p:r:s:t:v:w:ACIK:NQSTW:Z" #else -#define OPTIONS "a:b:c:d:e:f:j:k:l:m:n:o:p:r:s:t:v:w:ACIK:NSTW:" +#define OPTIONS "a:b:c:d:e:f:hi:j:k:l:m:n:o:p:r:s:t:v:w:ACIK:NSTW:" #endif /* ANCACHE */ int s; /* Global socket for ioctl's */ @@ -1250,31 +1250,25 @@ an_enable_tx_key(char *arg) int main(int argc, char *argv[]) { + int modifier = 0, print_stat = 0, ifspecified = 0; int ch; - int modifier = 0; - int print_stat = 0; - - /* Grab device name, if one is given. Default to "an0" */ - opterr = 0; - ch = getopt(argc, argv, "i:"); - if (ch == 'i') { - strlcpy(ifr.ifr_name, optarg, sizeof(ifr.ifr_name)); - } else { - if (argc > 1 && argv[1][0] != '-') { - strlcpy(ifr.ifr_name, argv[1], sizeof(ifr.ifr_name)); - optind = 2; - } else { - strlcpy(ifr.ifr_name, "an0", sizeof(ifr.ifr_name)); - optind = 1; - } + + strlcpy(ifr.ifr_name, "an0", sizeof(ifr.ifr_name)); + if (argc > 1 && argv[1][0] != '-') { + strlcpy(ifr.ifr_name, argv[1], sizeof(ifr.ifr_name)); + ifspecified = 1; + optind = 2; } - opterr = optreset = 1; /* Grab a socket to do our ioctl's */ getsock(); while ((ch = getopt(argc, argv, OPTIONS)) != -1) { - switch(ch) { + switch (ch) { + case 'i': + if (!ifspecified) + strlcpy(ifr.ifr_name, optarg, sizeof(ifr.ifr_name)); + break; case 'A': print_stat |= STAT_DUMPAP; break; diff --git a/sbin/ipwcontrol/ipwcontrol.c b/sbin/ipwcontrol/ipwcontrol.c index 98ee21372c8..3789d380230 100644 --- a/sbin/ipwcontrol/ipwcontrol.c +++ b/sbin/ipwcontrol/ipwcontrol.c @@ -1,4 +1,4 @@ -/* $Id: ipwcontrol.c,v 1.3 2004/10/20 21:26:43 deraadt Exp $ */ +/* $Id: ipwcontrol.c,v 1.4 2004/10/24 11:50:47 deraadt Exp $ */ /*- * Copyright (c) 2004 @@ -28,7 +28,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: ipwcontrol.c,v 1.3 2004/10/20 21:26:43 deraadt Exp $"; +static char rcsid[] = "$Id: ipwcontrol.c,v 1.4 2004/10/24 11:50:47 deraadt Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -69,19 +69,22 @@ static void get_statistics(char *); int main(int argc, char **argv) { - int ch; + int ch, ifspecified = 0; char *iface; - if (argc == 1) - iface = "ipw0"; - else if (argc > 1 && argv[1][0] != '-') { + iface = "ipw0"; + if (argc > 1 && argv[1][0] != '-') { iface = argv[1]; - memcpy(&argv[1], &argv[2], argc * sizeof(char *)); - argc--; + ifspecified = 1; + optind = 2; } - while ((ch = getopt(argc, argv, "f:kr")) != -1) { + while ((ch = getopt(argc, argv, "hf:i:kr")) != -1) { switch (ch) { + case 'i': + if (!ifspecified) + iface = optarg; + break; case 'f': load_firmware(iface, optarg); return EX_OK; @@ -94,6 +97,7 @@ main(int argc, char **argv) get_radio_state(iface); return EX_OK; + case 'h': default: usage(); } diff --git a/sbin/iwicontrol/iwicontrol.c b/sbin/iwicontrol/iwicontrol.c index 73536ebf62a..966145da0f9 100644 --- a/sbin/iwicontrol/iwicontrol.c +++ b/sbin/iwicontrol/iwicontrol.c @@ -1,4 +1,4 @@ -/* $Id: iwicontrol.c,v 1.3 2004/10/20 21:26:43 deraadt Exp $ */ +/* $Id: iwicontrol.c,v 1.4 2004/10/24 11:50:47 deraadt Exp $ */ /*- * Copyright (c) 2004 @@ -77,22 +77,24 @@ static void get_statistics(char *); int main(int argc, char **argv) { - int ch; char *iface = NULL, *mode = NULL, *path = NULL; - int noflag = 1, kflag = 0, rflag = 0; + int noflag = 1, kflag = 0, rflag = 0, ifspecified = 0; + int ch; - if (argc == 1) - iface = "iwi0"; - else if (argc > 1 && argv[1][0] != '-') { + iface = "iwi0"; + if (argc > 1 && argv[1][0] != '-') { iface = argv[1]; - memcpy(&argv[1], &argv[2], argc * sizeof(char *)); - argc--; + ifspecified = 1; + optind = 2; } - while ((ch = getopt(argc, argv, "d:i:km:r")) != -1) { + while ((ch = getopt(argc, argv, "hd:i:km:r")) != -1) { noflag = 0; - switch (ch) { + case 'i': + if (!ifspecified) + iface = optarg; + break; case 'd': path = optarg; break; @@ -109,6 +111,7 @@ main(int argc, char **argv) rflag = 1; break; + case 'h': default: usage(); } diff --git a/sbin/lmccontrol/lmccontrol.c b/sbin/lmccontrol/lmccontrol.c index a0ad78b5875..1bb1b1d963c 100644 --- a/sbin/lmccontrol/lmccontrol.c +++ b/sbin/lmccontrol/lmccontrol.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lmccontrol.c,v 1.4 2002/06/09 08:13:07 todd Exp $ */ +/* $OpenBSD: lmccontrol.c,v 1.5 2004/10/24 11:50:47 deraadt Exp $ */ /*- * Copyright (c) 1997-1999 LAN Media Corporation (LMC) @@ -72,29 +72,26 @@ usage(char *s) int main(int argc, char **argv) { - lmc_ctl_t ctl; - int fd; + lmc_ctl_t ctl, wanted; + int fd, ch; struct ifreq ifr; - int ch; - char *ifname = DEFAULT_INTERFACE; - lmc_ctl_t wanted; - int flag_c = 0; /* clock source external, internal */ - int flag_l = 0; /* line speed */ - int flag_s = 0; /* Scrambler on, off */ - int flag_o = 0; /* cable length < 100, > 100 */ - int flag_e = 0; /* crc 16, 32 */ - int flag_k = 0; /* HDLC keepalive */ - int just_print = 1; - int ifspecified = 0; - + int flag_c = 0; /* clock source external, internal */ + int flag_l = 0; /* line speed */ + int flag_s = 0; /* Scrambler on, off */ + int flag_o = 0; /* cable length < 100, > 100 */ + int flag_e = 0; /* crc 16, 32 */ + int flag_k = 0; /* HDLC keepalive */ + int just_print = 1, ifspecified = 0; + char *ifname; + + ifname = DEFAULT_INTERFACE; if (argc > 1 && argv[1][0] != '-') { ifname = argv[1]; - memcpy(&argv[1], &argv[2], argc * sizeof(char *)); - argc--; ifspecified = 1; + optind = 2; } - while ((ch = getopt(argc, argv, "i:l:cCsSoOeEkKpP")) != -1) { + while ((ch = getopt(argc, argv, "hi:l:cCsSoOeEkKpP")) != -1) { switch (ch) { case 'i': if (!ifspecified) @@ -196,7 +193,7 @@ main(int argc, char **argv) #endif break; case 'h': - case '?': + default: usage(argv[0]); return (0); } diff --git a/sbin/wicontrol/wicontrol.c b/sbin/wicontrol/wicontrol.c index b0b3201bb8d..9c3301de3d8 100644 --- a/sbin/wicontrol/wicontrol.c +++ b/sbin/wicontrol/wicontrol.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wicontrol.c,v 1.54 2004/08/25 17:16:44 mickey Exp $ */ +/* $OpenBSD: wicontrol.c,v 1.55 2004/10/24 11:50:47 deraadt Exp $ */ /* * Copyright (c) 1997, 1998, 1999 @@ -68,7 +68,7 @@ static const char copyright[] = "@(#) Copyright (c) 1997, 1998, 1999\ Bill Paul. All rights reserved."; static const char rcsid[] = - "@(#) $OpenBSD: wicontrol.c,v 1.54 2004/08/25 17:16:44 mickey Exp $"; + "@(#) $OpenBSD: wicontrol.c,v 1.55 2004/10/24 11:50:47 deraadt Exp $"; #endif int wi_getval(char *, struct wi_req *); @@ -872,16 +872,15 @@ struct wi_func wi_opt[] = { int main(int argc, char *argv[]) { - char *iface = "wi0"; - int ch, p, dumpstats, dumpinfo = 1, ifspecified; - int listaps, dumpstations; + int ch, p, dumpstats = 0, dumpinfo = 1, ifspecified = 0; + int listaps = 0, dumpstations = 0; + char *iface; - dumpstats = ifspecified = listaps = dumpstations = 0; + iface = "wi0"; if (argc > 1 && argv[1][0] != '-') { iface = argv[1]; - memcpy(&argv[1], &argv[2], argc * sizeof(char *)); - argc--; ifspecified = 1; + optind = 2; } while ((ch = getopt(argc, argv, @@ -897,20 +896,18 @@ main(int argc, char *argv[]) dumpinfo = ch = 0; } switch (ch) { - case 0: - break; case 'i': if (!ifspecified) iface = optarg; break; - case 'o': - dumpstats++; + case 'l': + dumpstations++; break; case 'L': listaps++; break; - case 'l': - dumpstations++; + case 'o': + dumpstats++; break; case 'v': for (p = 0; wi_opt[p].key; p++) |