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

arp: replacing existing entries



I suppose, it is not a new topic for a discussion, anyway,
here is the diff.

--- arp.c.orig	Sun Mar 13 15:54:38 2005
+++ arp.c	Fri Mar 25 02:23:44 2005
@@ -103,6 +103,7 @@ extern int h_errno;
 #define F_SET		2
 #define F_FILESET	3
 #define F_DELETE	4
+#define F_REPLACE	5
 
 int
 main(int argc, char *argv[])
@@ -113,7 +114,7 @@ main(int argc, char *argv[])
 	opterr = 0;
 	func = 0;
 
-	while ((ch = getopt(argc, argv, "andsf")) != -1) {
+	while ((ch = getopt(argc, argv, "andSsf")) != -1) {
 		switch ((char)ch) {
 		case 'a':
 			aflag = 1;
@@ -126,6 +127,11 @@ main(int argc, char *argv[])
 				usage();
 			func = F_DELETE;
 			break;
+		case 'S':
+			if (func)
+				usage();
+			func = F_REPLACE;
+			break;
 		case 's':
 			if (func)
 				usage();
@@ -158,8 +164,12 @@ main(int argc, char *argv[])
 			usage();
 		break;
 	case F_SET:
+		/* FALLTHROUGH */
+	case F_REPLACE:
 		if (argc < 2 || argc > 5)
 			usage();
+		if (func == F_REPLACE)
+			(void)delete(argv[0], NULL);
 		rtn = set(argc, argv) ? 1 : 0;
 		break;
 	case F_DELETE:
@@ -205,6 +215,7 @@ file(char *name)
 			retval = 1;
 			continue;
 		}
+		(void)delete(arg[0], NULL);
 		if (set(i, args))
 			retval = 1;
 	}
@@ -528,6 +539,8 @@ usage(void)
 	(void)fprintf(stderr, "usage: arp -d -a\n");
 	(void)fprintf(stderr,
 	    "usage: arp -s hostname ether_addr [temp | permanent] [pub]\n");
+	(void)fprintf(stderr,
+	    "usage: arp -S hostname ether_addr [temp | permanent] [pub]\n");
 	(void)fprintf(stderr, "usage: arp -f filename\n");
 	exit(1);
 }
--- arp.8.orig	Sat Jul 10 21:30:31 2004
+++ arp.8	Fri Mar 25 02:30:04 2005
@@ -52,6 +52,10 @@
 .Op Cm temp | permanent
 .Op Cm pub
 .Nm arp
+.Fl S Ar hostname ether_addr
+.Op Cm temp | permanent
+.Op Cm pub
+.Nm arp
 .Fl f Ar filename
 .Sh DESCRIPTION
 The
@@ -133,6 +137,13 @@
 .Ar ether_addr .
 The Ethernet address is given as six hexadecimal bytes separated by
 colons.
+.It Fl S Ar hostname ether_addr
+Create or replace an
+.Tn ARP
+entry for the host called
+.Ar hostname
+with the Ethernet address
+.Ar ether_addr .
 .Pp
 The
 .Cm permanent , pub ,