diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2005-03-29 22:00:00 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2005-03-29 22:00:00 +0000 |
commit | 08bf902901162316c7fd37d186a61b1dc06761ea (patch) | |
tree | 0daafbb390d8f1e38510ee1cf1ef7dc485b7784b | |
parent | 8313ab3c4474dfa460edf89ef91a92ff8348c79e (diff) |
add -F to force replacement of entries with -s and -f
inspired by a diff from Mike Belopuhov <mkb@cvs.hnet.spb.ru>,
these semantics with theo, manpage jaredy jmc and bob, ok bob
-rw-r--r-- | usr.sbin/arp/arp.8 | 34 | ||||
-rw-r--r-- | usr.sbin/arp/arp.c | 20 |
2 files changed, 41 insertions, 13 deletions
diff --git a/usr.sbin/arp/arp.8 b/usr.sbin/arp/arp.8 index 128b2be5084..d3b05762689 100644 --- a/usr.sbin/arp/arp.8 +++ b/usr.sbin/arp/arp.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: arp.8,v 1.14 2004/07/09 19:54:41 jaredy Exp $ +.\" $OpenBSD: arp.8,v 1.15 2005/03/29 21:59:59 henning Exp $ .\" $NetBSD: arp.8,v 1.7 1995/03/01 11:50:59 chopps Exp $ .\" .\" Copyright (c) 1985, 1991, 1993 @@ -48,10 +48,12 @@ .Nm arp .Fl d a .Nm arp +.Op Fl F .Fl s Ar hostname ether_addr .Op Cm temp | permanent .Op Cm pub .Nm arp +.Op Fl F .Fl f Ar filename .Sh DESCRIPTION The @@ -85,15 +87,25 @@ 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 +Force existing entries for the given host to be overwritten +(only relevant to the +.Fl f +and +.Fl s +options). +.It Fl f 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 not be overwritten unless +.Fl F +is given. Entries in the file should be of the form: -.Pp -.Bd -filled -offset indent -compact +.Bd -filled -offset indent .Ar hostname ether_addr .Op Cm temp | permanent .Op Cm pub @@ -124,7 +136,11 @@ This behavior has traditionally been called Show network addresses as numbers (normally .Nm attempts to display addresses symbolically). -.It Fl s Ar hostname ether_addr +.It Xo +.Fl s Ar hostname ether_addr +.Op Cm temp | permanent +.Op Cm pub +.Xc Create an .Tn ARP entry for the host called @@ -139,6 +155,11 @@ The or .Cm temp modifiers may be specified with meanings as given above. +.Pp +If the entry already exists for the given host, it will not +be replaced unless +.Fl F +is given. .El .Sh EXAMPLES To view the current @@ -157,8 +178,7 @@ To create .Em proxy ARP entries on an interface, fxp0, for the IP addresses 204.1.2.3 and 204.1.2.4: -.Pp -.Bd -unfilled -offset indent -compact +.Bd -literal -offset indent # arp -s 204.1.2.3 00:90:27:bb:cc:dd pub # arp -s 204.1.2.4 00:90:27:bb:cc:dd pub .Ed diff --git a/usr.sbin/arp/arp.c b/usr.sbin/arp/arp.c index b9218195a85..6686268395e 100644 --- a/usr.sbin/arp/arp.c +++ b/usr.sbin/arp/arp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: arp.c,v 1.31 2005/01/04 10:57:23 pascoe Exp $ */ +/* $OpenBSD: arp.c,v 1.32 2005/03/29 21:59:59 henning Exp $ */ /* $NetBSD: arp.c,v 1.12 1995/04/24 13:25:18 cgd Exp $ */ /* @@ -41,7 +41,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)arp.c 8.2 (Berkeley) 1/2/94";*/ -static char *rcsid = "$OpenBSD: arp.c,v 1.31 2005/01/04 10:57:23 pascoe Exp $"; +static char *rcsid = "$OpenBSD: arp.c,v 1.32 2005/03/29 21:59:59 henning Exp $"; #endif /* not lint */ /* @@ -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; @@ -131,6 +132,9 @@ main(int argc, char *argv[]) usage(); func = F_SET; break; + case 'F': + replace = 1; + break; case 'f': if (func) usage(); @@ -160,6 +164,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 +211,8 @@ file(char *name) retval = 1; continue; } + if (replace) + (void)delete(arg[0], NULL); if (set(i, args)) retval = 1; } @@ -459,7 +467,7 @@ print_entry(struct sockaddr_dl *sdl, struct sockaddr_inarp *sin, { char *host; struct hostent *hp; - char ifname[IF_NAMESIZE]; + char ifname[IFNAMSIZ]; if (nflag == 0) hp = gethostbyaddr((caddr_t)&(sin->sin_addr), @@ -527,8 +535,8 @@ 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 -f filename\n"); + "usage: arp [-F] -s hostname ether_addr [temp | permanent] [pub]\n"); + (void)fprintf(stderr, "usage: arp [-F] -f filename\n"); exit(1); } |