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

arp: allow overwrites



this adds -S, which works like -s and allows to overwrite static 
entries, and -F, which is like -f but allows to overwrite as well.
based on a diff by Mike Belopuhov <mkb_(_at_)_cvs_(_dot_)_hnet_(_dot_)_spb_(_dot_)_ru> but without 
modifying existing semantics, manpage help jaredy and jmc

Index: arp.8
===================================================================
RCS file: /cvs/src/usr.sbin/arp/arp.8,v
retrieving revision 1.14
diff -u -p -r1.14 arp.8
--- arp.8	9 Jul 2004 19:54:41 -0000	1.14
+++ arp.8	29 Mar 2005 18:41:09 -0000
@@ -48,10 +48,16 @@
 .Nm arp
 .Fl d a
 .Nm arp
+.Fl S Ar hostname ether_addr
+.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
+.Nm arp
 .Fl f Ar filename
 .Sh DESCRIPTION
 The
@@ -85,12 +91,14 @@ flag may be combined with the
 flag to delete all entries, with hostname lookups automatically
 disabled.
 Only the superuser may delete entries.
-.It Fl f Ar filename
+.It Fl F Ar filename
 Process entries from
 .Ar filename
 to be set in the
 .Tn ARP
 tables.
+Any entries in the file that already exist for a given host will be
+overwritten.
 Entries in the file should be of the form:
 .Pp
 .Bd -filled -offset indent -compact
@@ -120,12 +128,21 @@ responding to requests for
 even though the host address is not its own.
 This behavior has traditionally been called
 .Em proxy ARP .
+.It Fl f Ar filename
+The same as
+.Fl F
+except that any entries in the file that already exist for a given host
+will not be overwritten.
 .It Fl n
 Show network addresses as numbers (normally
 .Nm
 attempts to display addresses symbolically).
-.It Fl s Ar hostname ether_addr
-Create an
+.It Xo
+.Fl S Ar hostname ether_addr
+.Op Cm temp | permanent
+.Op Cm pub
+.Xc
+Create or replace an
 .Tn ARP
 entry for the host called
 .Ar hostname
@@ -139,6 +156,15 @@ The
 or
 .Cm temp
 modifiers may be specified with meanings as given above.
+.It Xo
+.Fl s Ar hostname ether_addr
+.Op Cm temp | permanent
+.Op Cm pub
+.Xc
+The same as
+.Fl S
+except that if the entry already exists for the given host, it will not
+be replaced.
 .El
 .Sh EXAMPLES
 To view the current
Index: arp.c
===================================================================
RCS file: /cvs/src/usr.sbin/arp/arp.c,v
retrieving revision 1.31
diff -u -p -r1.31 arp.c
--- arp.c	4 Jan 2005 10:57:23 -0000	1.31
+++ arp.c	29 Mar 2005 18:41:09 -0000
@@ -88,6 +88,7 @@ int set(int, char **);
 void usage(void);
 
 static pid_t pid;
+static int replace;	/* replace entries when adding */
 static int nflag;	/* no reverse dns lookups */
 static int aflag;	/* do it for all entries */
 static int s = -1;
@@ -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, "andSsFf")) != -1) {
 		switch ((char)ch) {
 		case 'a':
 			aflag = 1;
@@ -126,11 +127,17 @@ main(int argc, char *argv[])
 				usage();
 			func = F_DELETE;
 			break;
+		case 'S':
+			replace = 1;
+			/* FALLTHROUGH */
 		case 's':
 			if (func)
 				usage();
 			func = F_SET;
 			break;
+		case 'F':
+			replace = 1;
+			/* FALLTHROUGH */
 		case 'f':
 			if (func)
 				usage();
@@ -160,6 +167,8 @@ main(int argc, char *argv[])
 	case F_SET:
 		if (argc < 2 || argc > 5)
 			usage();
+		if (replace)
+			(void)delete(argv[0], NULL);
 		rtn = set(argc, argv) ? 1 : 0;
 		break;
 	case F_DELETE:
@@ -205,6 +214,8 @@ file(char *name)
 			retval = 1;
 			continue;
 		}
+		if (replace)
+			(void)delete(arg[0], NULL);
 		if (set(i, args))
 			retval = 1;
 	}
@@ -459,7 +470,7 @@ print_entry(struct sockaddr_dl *sdl, str
 {
 	char *host;
 	struct hostent *hp;
-	char ifname[IF_NAMESIZE];
+	char ifname[IFNAMSIZ];
 
 	if (nflag == 0)
 		hp = gethostbyaddr((caddr_t)&(sin->sin_addr),
@@ -527,7 +538,10 @@ usage(void)
 	(void)fprintf(stderr, "usage: arp -d hostname\n");
 	(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");
 	(void)fprintf(stderr, "usage: arp -f filename\n");
 	exit(1);
 }



Visit your host, monkey.org