summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkn <kn@cvs.openbsd.org>2019-09-16 19:39:48 +0000
committerkn <kn@cvs.openbsd.org>2019-09-16 19:39:48 +0000
commit7d1f85fb6e0298b29b159b3bd6cf65e7c5cc4f81 (patch)
tree24d2a8867e16757df8c50bfa53b96f3dc7a9dad8
parent7a7cc6a8324fe6a08a059447246cd2ed5d39db9a (diff)
Simplify function detection
To determine which "function" (get, set, ...) is requested, use getopt(3)'s result directly as ndp(8) does instead of translating everyting into internal F_* defines and back again. Avoids one level of indirection, chops 22 lines of code and brings both tools closer together. OK bluhm
-rw-r--r--usr.sbin/arp/arp.c40
1 files changed, 9 insertions, 31 deletions
diff --git a/usr.sbin/arp/arp.c b/usr.sbin/arp/arp.c
index 6bdee91552a..aa8516698d0 100644
--- a/usr.sbin/arp/arp.c
+++ b/usr.sbin/arp/arp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arp.c,v 1.86 2019/08/31 13:46:14 bluhm Exp $ */
+/* $OpenBSD: arp.c,v 1.87 2019/09/16 19:39:47 kn Exp $ */
/* $NetBSD: arp.c,v 1.12 1995/04/24 13:25:18 cgd Exp $ */
/*
@@ -95,13 +95,6 @@ extern int h_errno;
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
-/* which function we're supposed to do */
-#define F_GET 1
-#define F_SET 2
-#define F_FILESET 3
-#define F_DELETE 4
-#define F_WAKE 5
-
int
main(int argc, char *argv[])
{
@@ -120,23 +113,16 @@ main(int argc, char *argv[])
nflag = 1;
break;
case 'd':
- if (func)
- usage();
- func = F_DELETE;
- break;
case 's':
+ case 'f':
+ case 'W':
if (func)
usage();
- func = F_SET;
+ func = ch;
break;
case 'F':
replace = 1;
break;
- case 'f':
- if (func)
- usage();
- func = F_FILESET;
- break;
case 'V':
rdomain = strtonum(optarg, 0, RT_TABLEID_MAX, &errstr);
if (errstr != NULL) {
@@ -144,11 +130,6 @@ main(int argc, char *argv[])
usage();
}
break;
- case 'W':
- if (func)
- usage();
- func = F_WAKE;
- break;
default:
usage();
break;
@@ -157,11 +138,8 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
- if (!func)
- func = F_GET;
-
switch (func) {
- case F_GET:
+ case 0:
if (aflag && argc == 0)
dump();
else if (!aflag && argc == 1)
@@ -169,14 +147,14 @@ main(int argc, char *argv[])
else
usage();
break;
- case F_SET:
+ case 's':
if (argc < 2 || argc > 5)
usage();
if (replace)
delete(argv[0]);
error = set(argc, argv) ? 1 : 0;
break;
- case F_DELETE:
+ case 'd':
if (aflag && argc == 0)
search(0, nuke_entry);
else if (!aflag && argc == 1)
@@ -184,12 +162,12 @@ main(int argc, char *argv[])
else
usage();
break;
- case F_FILESET:
+ case 'f':
if (argc != 1)
usage();
error = file(argv[0]);
break;
- case F_WAKE:
+ case 'W':
if (aflag || nflag || replace || rdomain > 0)
usage();
if (argc == 1)