CVS commit: src/usr.sbin/arp

2020-09-15 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Sep 15 11:14:16 UTC 2020

Modified Files:
src/usr.sbin/arp: arp.c

Log Message:
arp: Permanence is from the llentry, not the route


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/usr.sbin/arp/arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.67 src/usr.sbin/arp/arp.c:1.68
--- src/usr.sbin/arp/arp.c:1.67	Tue Sep 15 10:11:15 2020
+++ src/usr.sbin/arp/arp.c	Tue Sep 15 11:14:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.67 2020/09/15 10:11:15 roy Exp $ */
+/*	$NetBSD: arp.c,v 1.68 2020/09/15 11:14:16 roy Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.67 2020/09/15 10:11:15 roy Exp $");
+__RCSID("$NetBSD: arp.c,v 1.68 2020/09/15 11:14:16 roy Exp $");
 #endif
 #endif /* not lint */
 
@@ -491,8 +491,6 @@ dump(uint32_t addr)
 (void)printf(" on %s", ifname);
 		}
 
-		if (rtm->rtm_rmx.rmx_expire == 0)
-			(void)printf(" permanent");
 		if (sina->sin_other & SIN_PROXY)
 			(void)printf(" published (proxy only)");
 		if (rtm->rtm_addrs & RTA_NETMASK) {



CVS commit: src/usr.sbin/arp

2020-09-15 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Tue Sep 15 10:11:15 UTC 2020

Modified Files:
src/usr.sbin/arp: arp.8 arp.c

Log Message:
arp: Show U for Unreachable


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.sbin/arp/arp.8
cvs rdiff -u -r1.66 -r1.67 src/usr.sbin/arp/arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.8
diff -u src/usr.sbin/arp/arp.8:1.25 src/usr.sbin/arp/arp.8:1.26
--- src/usr.sbin/arp/arp.8:1.25	Fri Sep 11 15:28:29 2020
+++ src/usr.sbin/arp/arp.8	Tue Sep 15 10:11:15 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: arp.8,v 1.25 2020/09/11 15:28:29 roy Exp $
+.\"	$NetBSD: arp.8,v 1.26 2020/09/15 10:11:15 roy Exp $
 .\"
 .\" Copyright (c) 1985, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	from: @(#)arp.8	8.2 (Berkeley) 4/27/95
 .\"
-.Dd September 11, 2020
+.Dd September 15, 2020
 .Dt ARP 8
 .Os
 .Sh NAME
@@ -84,6 +84,8 @@ Probe
 Reachable
 .It S
 Stale
+.It U
+Unreachable
 .It W
 Waitdelete
 .It ?

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.66 src/usr.sbin/arp/arp.c:1.67
--- src/usr.sbin/arp/arp.c:1.66	Fri Sep 11 15:28:29 2020
+++ src/usr.sbin/arp/arp.c	Tue Sep 15 10:11:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.66 2020/09/11 15:28:29 roy Exp $ */
+/*	$NetBSD: arp.c,v 1.67 2020/09/15 10:11:15 roy Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.66 2020/09/11 15:28:29 roy Exp $");
+__RCSID("$NetBSD: arp.c,v 1.67 2020/09/15 10:11:15 roy Exp $");
 #endif
 #endif /* not lint */
 
@@ -539,6 +539,9 @@ dump(uint32_t addr)
 			case ND_LLINFO_PROBE:
 (void)printf(" P");
 break;
+			case ND_LLINFO_UNREACHABLE:
+(void)printf(" U");
+break;
 			default:
 (void)printf(" ?");
 break;



CVS commit: src/usr.sbin/arp

2020-09-11 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Fri Sep 11 15:28:29 UTC 2020

Modified Files:
src/usr.sbin/arp: arp.8 arp.c arp_hostops.c arp_rumpops.c prog_ops.h

Log Message:
arp: Use SIOCGNBRINFO to display neighbor state information


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/usr.sbin/arp/arp.8
cvs rdiff -u -r1.65 -r1.66 src/usr.sbin/arp/arp.c
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/arp/arp_hostops.c \
src/usr.sbin/arp/arp_rumpops.c src/usr.sbin/arp/prog_ops.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.8
diff -u src/usr.sbin/arp/arp.8:1.24 src/usr.sbin/arp/arp.8:1.25
--- src/usr.sbin/arp/arp.8:1.24	Fri Jul  6 00:50:05 2018
+++ src/usr.sbin/arp/arp.8	Fri Sep 11 15:28:29 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: arp.8,v 1.24 2018/07/06 00:50:05 christos Exp $
+.\"	$NetBSD: arp.8,v 1.25 2020/09/11 15:28:29 roy Exp $
 .\"
 .\" Copyright (c) 1985, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	from: @(#)arp.8	8.2 (Berkeley) 4/27/95
 .\"
-.Dd July 5, 2018
+.Dd September 11, 2020
 .Dt ARP 8
 .Os
 .Sh NAME
@@ -69,6 +69,27 @@ entry for
 The host may be specified by name or by number,
 using Internet dot notation.
 .Pp
+The state of the arp entry is shown as a single letter preceeded by the
+time the state is applicable for:
+.Bl -tag -width indent -compact
+.It D
+Delay
+.It I
+Incomplete
+.It N
+Nostate
+.It P
+Probe
+.It R
+Reachable
+.It S
+Stale
+.It W
+Waitdelete
+.It ?
+Unknown state (should never happen).
+.El
+.Pp
 Available options:
 .Bl -tag -width Ds
 .It Fl a

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.65 src/usr.sbin/arp/arp.c:1.66
--- src/usr.sbin/arp/arp.c:1.65	Thu Feb 28 01:20:25 2019
+++ src/usr.sbin/arp/arp.c	Fri Sep 11 15:28:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.65 2019/02/28 01:20:25 nonaka Exp $ */
+/*	$NetBSD: arp.c,v 1.66 2020/09/11 15:28:29 roy Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.65 2019/02/28 01:20:25 nonaka Exp $");
+__RCSID("$NetBSD: arp.c,v 1.66 2020/09/11 15:28:29 roy Exp $");
 #endif
 #endif /* not lint */
 
@@ -60,8 +60,10 @@ __RCSID("$NetBSD: arp.c,v 1.65 2019/02/2
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -92,6 +94,8 @@ static int getsocket(void);
 static int getetheraddr(struct in_addr, struct sockaddr_dl *);
 static struct rt_msghdr * rtmsg(const int, const int,  struct rt_msghdr *,
 	const struct sockaddr_inarp *, const struct sockaddr_dl *);
+static struct in_nbrinfo * getnbrinfo(const char *, struct in_addr *);
+static const char * sec2str(time_t);
 static int set(int, char **);
 static void usage(void) __dead;
 
@@ -439,6 +443,8 @@ dump(uint32_t addr)
 	struct sockaddr_inarp *sina;
 	struct sockaddr_dl *sdl;
 	struct hostent *hp;
+	struct timeval tim;
+	struct in_nbrinfo *nbi;
 
 	mib[0] = CTL_NET;
 	mib[1] = PF_ROUTE;
@@ -497,6 +503,49 @@ dump(uint32_t addr)
 			if (sina->sin_len != 8)
 (void)printf("(weird)");
 		}
+
+		if (sdl->sdl_index == 0)
+			goto done;
+		(void)gettimeofday(&tim, 0);
+		nbi = getnbrinfo(ifname, &sina->sin_addr);
+		if (nbi != NULL) {
+			if (nbi->expire > tim.tv_sec) {
+(void)printf(" %s",
+sec2str(nbi->expire - tim.tv_sec));
+			} else if (nbi->expire == 0)
+(void)printf(" %s", "permanent");
+			else
+(void)printf(" %s", "expired");
+
+			switch (nbi->state) {
+			case ND_LLINFO_NOSTATE:
+(void)printf(" N");
+break;
+			case ND_LLINFO_WAITDELETE:
+(void)printf(" W");
+break;
+			case ND_LLINFO_INCOMPLETE:
+(void)printf(" I");
+break;
+			case ND_LLINFO_REACHABLE:
+(void)printf(" R");
+break;
+			case ND_LLINFO_STALE:
+(void)printf(" S");
+break;
+			case ND_LLINFO_DELAY:
+(void)printf(" D");
+break;
+			case ND_LLINFO_PROBE:
+(void)printf(" P");
+break;
+			default:
+(void)printf(" ?");
+break;
+			}
+		}
+
+done:
 		(void)printf("\n");
 	}
 	free(buf);
@@ -800,3 +849,66 @@ getetheraddr(struct in_addr ipaddr, stru
 	freeifaddrs(ifaddrs);
 	return -1;
 }
+
+static struct in_nbrinfo *
+getnbrinfo(const char *ifname, struct in_addr *addr)
+{
+	static struct in_nbrinfo nbi, *nbip;
+	int s;
+
+	if ((s = prog_socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+		err(1, "socket");
+
+	(void)memset(&nbi, 0, sizeof(nbi));
+	(void)strlcpy(nbi.ifname, ifname, sizeof(nbi.ifname));
+	nbi.addr = *addr;
+	if (prog_ioctl(s, SIOCGNBRINFO, &nbi) == -1) {
+		warn("ioctl(SIOCGNBRINFO)");
+		nbip = NULL;
+	} else
+		nbip = &nbi;
+	(void)prog_close(s);
+
+	return nbip;
+}
+
+static const char *
+sec2str(time_t total)
+{
+	static char result[256];
+	int days, hours, mins, secs;
+	int first = 1;
+	char *p = result;
+	char *ep = &

CVS commit: src/usr.sbin/arp

2019-02-27 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Thu Feb 28 01:20:25 UTC 2019

Modified Files:
src/usr.sbin/arp: arp.c

Log Message:
arp(8): one more to close socket.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/usr.sbin/arp/arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.64 src/usr.sbin/arp/arp.c:1.65
--- src/usr.sbin/arp/arp.c:1.64	Wed Feb 27 23:29:50 2019
+++ src/usr.sbin/arp/arp.c	Thu Feb 28 01:20:25 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.64 2019/02/27 23:29:50 dholland Exp $ */
+/*	$NetBSD: arp.c,v 1.65 2019/02/28 01:20:25 nonaka Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.64 2019/02/27 23:29:50 dholland Exp $");
+__RCSID("$NetBSD: arp.c,v 1.65 2019/02/28 01:20:25 nonaka Exp $");
 #endif
 #endif /* not lint */
 
@@ -413,8 +413,10 @@ delete_one(struct rt_msghdr *rtm)
 	sina = (struct sockaddr_inarp *)(void *)(rtm + 1);
 	sdl = (struct sockaddr_dl *)(void *)(RT_ROUNDUP(sina->sin_len) +
 	(char *)(void *)sina);
-	if (sdl->sdl_family != AF_LINK)
+	if (sdl->sdl_family != AF_LINK) {
+		prog_close(s);
 		return (1);
+	}
 	rtm = rtmsg(s, RTM_DELETE, rtm, sina, sdl);
 	prog_close(s);
 	if (rtm == NULL)



CVS commit: src/usr.sbin/arp

2019-02-27 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed Feb 27 23:29:50 UTC 2019

Modified Files:
src/usr.sbin/arp: arp.c arp_hostops.c arp_rumpops.c prog_ops.h

Log Message:
Teach arp that it's okay to close sockets after using them.
(this requires adding a close op to the rump turds)

Fixes PR 53974 reporting too many open files.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/usr.sbin/arp/arp.c
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/arp/arp_hostops.c \
src/usr.sbin/arp/arp_rumpops.c src/usr.sbin/arp/prog_ops.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.63 src/usr.sbin/arp/arp.c:1.64
--- src/usr.sbin/arp/arp.c:1.63	Tue Jul 31 09:45:52 2018
+++ src/usr.sbin/arp/arp.c	Wed Feb 27 23:29:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.63 2018/07/31 09:45:52 nonaka Exp $ */
+/*	$NetBSD: arp.c,v 1.64 2019/02/27 23:29:50 dholland Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.63 2018/07/31 09:45:52 nonaka Exp $");
+__RCSID("$NetBSD: arp.c,v 1.64 2019/02/27 23:29:50 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -276,8 +276,10 @@ set(int argc, char **argv)
 	argc -= 2;
 	argv += 2;
 
-	if (getinetaddr(host, &sin_m.sin_addr) == -1)
+	if (getinetaddr(host, &sin_m.sin_addr) == -1) {
+		prog_close(s);
 		return (1);
+	}
 	if (strcmp(eaddr, "auto") != 0 && atosdl(eaddr, &sdl_m))
 		warnx("invalid link-level address '%s'", eaddr);
 	doing_proxy = flags = export_only = expire_time = 0;
@@ -310,13 +312,16 @@ set(int argc, char **argv)
 
 	}
 	if (doing_proxy && strcmp(eaddr, "auto") == 0) {
-		if (getetheraddr(sin_m.sin_addr, &sdl_m) == -1)
+		if (getetheraddr(sin_m.sin_addr, &sdl_m) == -1) {
+			prog_close(s);
 			return 1;
+		}
 	}
 tryagain:
 	rtm = rtmsg(s, RTM_GET, NULL, &sin_m, &sdl_m);
 	if (rtm == NULL) {
 		warn("%s", host);
+		prog_close(s);
 		return (1);
 	}
 	sina = (struct sockaddr_inarp *)(void *)(rtm + 1);
@@ -327,10 +332,12 @@ tryagain:
 			goto overwrite;
 		if (doing_proxy == 0) {
 			warnx("set: can only proxy for %s", host);
+			prog_close(s);
 			return (1);
 		}
 		if (sin_m.sin_other & SIN_PROXY) {
 			warnx("set: proxy entry exists for non 802 device");
+			prog_close(s);
 			return (1);
 		}
 		sin_m.sin_other = SIN_PROXY;
@@ -341,6 +348,7 @@ overwrite:
 	if (sdl->sdl_family != AF_LINK) {
 		warnx("cannot intuit interface index and type for %s",
 		host);
+		prog_close(s);
 		return (1);
 	}
 	sdl_m.sdl_type = sdl->sdl_type;
@@ -351,6 +359,7 @@ overwrite:
 	rtm = rtmsg(s, RTM_ADD, NULL, &sin_m, &sdl_m);
 	if (vflag)
 		(void)printf("%s (%s) added\n", host, eaddr);
+	prog_close(s);
 	return (rtm == NULL) ? 1 : 0;
 }
 
@@ -407,6 +416,7 @@ delete_one(struct rt_msghdr *rtm)
 	if (sdl->sdl_family != AF_LINK)
 		return (1);
 	rtm = rtmsg(s, RTM_DELETE, rtm, sina, sdl);
+	prog_close(s);
 	if (rtm == NULL)
 		return (1);
 	return (0);

Index: src/usr.sbin/arp/arp_hostops.c
diff -u src/usr.sbin/arp/arp_hostops.c:1.1 src/usr.sbin/arp/arp_hostops.c:1.2
--- src/usr.sbin/arp/arp_hostops.c:1.1	Wed Jul 29 06:07:35 2015
+++ src/usr.sbin/arp/arp_hostops.c	Wed Feb 27 23:29:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp_hostops.c,v 1.1 2015/07/29 06:07:35 ozaki-r Exp $	*/
+/*	$NetBSD: arp_hostops.c,v 1.2 2019/02/27 23:29:50 dholland Exp $	*/
 
 /*
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: arp_hostops.c,v 1.1 2015/07/29 06:07:35 ozaki-r Exp $");
+__RCSID("$NetBSD: arp_hostops.c,v 1.2 2019/02/27 23:29:50 dholland Exp $");
 #endif /* !lint */
 
 #include 
@@ -47,6 +47,7 @@ const struct prog_ops prog_ops = {
 
 	.op_read = read,
 	.op_write = write,
+	.op_close = close,
 
 	.op_sysctl = sysctl,
 };
Index: src/usr.sbin/arp/arp_rumpops.c
diff -u src/usr.sbin/arp/arp_rumpops.c:1.1 src/usr.sbin/arp/arp_rumpops.c:1.2
--- src/usr.sbin/arp/arp_rumpops.c:1.1	Wed Jul 29 06:07:35 2015
+++ src/usr.sbin/arp/arp_rumpops.c	Wed Feb 27 23:29:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp_rumpops.c,v 1.1 2015/07/29 06:07:35 ozaki-r Exp $	*/
+/*	$NetBSD: arp_rumpops.c,v 1.2 2019/02/27 23:29:50 dholland Exp $	*/
 
 /*
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: arp_rumpops.c,v 1.1 2015/07/29 06:07:35 ozaki-r Exp $");
+__RCSID("$NetBSD: arp_rumpops.c,v 1.2 2019/02/27 23:29:50 dholland Exp $");
 #endif /* !lint */
 
 #include 
@@ -51,6 +51,7 @@ const struct prog_ops prog_ops = {
 
 	.op_read =	rump_sys_read,
 	.op_write =	rump_sys_write,
+	.op_close =	rump_sys_close,
 
 	.op_sysctl =	rump_sys___sysctl,
 };
Index: src/usr.sbin/arp/prog_ops.h
diff -u src/usr.sbin/arp/prog_ops.h:1.1 src/usr.sbin/arp/prog_ops.h:1.2
--- src/usr.sbin/arp/prog_ops.h:1.1	Wed Jul 29

CVS commit: src/usr.sbin/arp

2018-07-31 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Tue Jul 31 09:45:52 UTC 2018

Modified Files:
src/usr.sbin/arp: arp.c

Log Message:
arp(8): Fix the host output when arp -dav.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/usr.sbin/arp/arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.62 src/usr.sbin/arp/arp.c:1.63
--- src/usr.sbin/arp/arp.c:1.62	Wed Jul 11 03:10:48 2018
+++ src/usr.sbin/arp/arp.c	Tue Jul 31 09:45:52 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.62 2018/07/11 03:10:48 ozaki-r Exp $ */
+/*	$NetBSD: arp.c,v 1.63 2018/07/31 09:45:52 nonaka Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.62 2018/07/11 03:10:48 ozaki-r Exp $");
+__RCSID("$NetBSD: arp.c,v 1.63 2018/07/31 09:45:52 nonaka Exp $");
 #endif
 #endif /* not lint */
 
@@ -497,6 +497,7 @@ void
 delete(const char *host, const char *info)
 {
 	int mib[6];
+	char addr[sizeof("000.000.000.000\0")];
 	size_t needed;
 	char *lim, *buf, *next;
 	struct rt_msghdr *rtm;
@@ -543,8 +544,10 @@ retry:
 		found = true;
 		ret = delete_one(rtm);
 		if (vflag && ret == 0) {
-			(void)printf("%s (%s) deleted\n", host,
+			snprintf(addr, sizeof(addr), "%s",
 			inet_ntoa(sina->sin_addr));
+			(void)printf("%s (%s) deleted\n",
+			host != NULL ? host : addr, addr);
 		}
 	}
 	if (host != NULL && !found)



CVS commit: src/usr.sbin/arp

2018-07-10 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 11 03:10:48 UTC 2018

Modified Files:
src/usr.sbin/arp: arp.c

Log Message:
arp: warn if failed to delete a specified arp entry

This restores the original behavior of arp in NetBSD 7.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/usr.sbin/arp/arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.61 src/usr.sbin/arp/arp.c:1.62
--- src/usr.sbin/arp/arp.c:1.61	Sat Jul  7 15:44:27 2018
+++ src/usr.sbin/arp/arp.c	Wed Jul 11 03:10:48 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.61 2018/07/07 15:44:27 christos Exp $ */
+/*	$NetBSD: arp.c,v 1.62 2018/07/11 03:10:48 ozaki-r Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.61 2018/07/07 15:44:27 christos Exp $");
+__RCSID("$NetBSD: arp.c,v 1.62 2018/07/11 03:10:48 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -502,6 +502,7 @@ delete(const char *host, const char *inf
 	struct rt_msghdr *rtm;
 	struct sockaddr_inarp *sina;
 	struct sockaddr_inarp sin_m = blank_sin; /* struct copy */
+	bool found = false;
 
 	if (host != NULL) {
 		int ret = getinetaddr(host, &sin_m.sin_addr);
@@ -539,12 +540,15 @@ retry:
 		if (host != NULL &&
 		sina->sin_addr.s_addr != sin_m.sin_addr.s_addr)
 			continue;
+		found = true;
 		ret = delete_one(rtm);
 		if (vflag && ret == 0) {
 			(void)printf("%s (%s) deleted\n", host,
 			inet_ntoa(sina->sin_addr));
 		}
 	}
+	if (host != NULL && !found)
+		warnx("delete: can't locate %s", host);
 	free(buf);
 }
 



CVS commit: src/usr.sbin/arp

2018-07-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jul  7 15:44:27 UTC 2018

Modified Files:
src/usr.sbin/arp: arp.c

Log Message:
Fix the logic for the non auto case


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/usr.sbin/arp/arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.60 src/usr.sbin/arp/arp.c:1.61
--- src/usr.sbin/arp/arp.c:1.60	Thu Jul  5 20:50:05 2018
+++ src/usr.sbin/arp/arp.c	Sat Jul  7 11:44:27 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.60 2018/07/06 00:50:05 christos Exp $ */
+/*	$NetBSD: arp.c,v 1.61 2018/07/07 15:44:27 christos Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.60 2018/07/06 00:50:05 christos Exp $");
+__RCSID("$NetBSD: arp.c,v 1.61 2018/07/07 15:44:27 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -278,7 +278,7 @@ set(int argc, char **argv)
 
 	if (getinetaddr(host, &sin_m.sin_addr) == -1)
 		return (1);
-	if (!strcmp(eaddr, "auto") && atosdl(eaddr, &sdl_m))
+	if (strcmp(eaddr, "auto") != 0 && atosdl(eaddr, &sdl_m))
 		warnx("invalid link-level address '%s'", eaddr);
 	doing_proxy = flags = export_only = expire_time = 0;
 	for (; argc-- > 0; argv++) {
@@ -309,7 +309,7 @@ set(int argc, char **argv)
 		}
 
 	}
-	if (doing_proxy && !strcmp(eaddr, "auto")) {
+	if (doing_proxy && strcmp(eaddr, "auto") == 0) {
 		if (getetheraddr(sin_m.sin_addr, &sdl_m) == -1)
 			return 1;
 	}



CVS commit: src/usr.sbin/arp

2018-07-05 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jul  6 00:50:05 UTC 2018

Modified Files:
src/usr.sbin/arp: arp.8 arp.c

Log Message:
Add an "auto" keyword to auto-determine the link address from the inet addr.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.sbin/arp/arp.8
cvs rdiff -u -r1.59 -r1.60 src/usr.sbin/arp/arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.8
diff -u src/usr.sbin/arp/arp.8:1.23 src/usr.sbin/arp/arp.8:1.24
--- src/usr.sbin/arp/arp.8:1.23	Mon Jul  8 00:31:12 2013
+++ src/usr.sbin/arp/arp.8	Thu Jul  5 20:50:05 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: arp.8,v 1.23 2013/07/08 04:31:12 apb Exp $
+.\"	$NetBSD: arp.8,v 1.24 2018/07/06 00:50:05 christos Exp $
 .\"
 .\" Copyright (c) 1985, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	from: @(#)arp.8	8.2 (Berkeley) 4/27/95
 .\"
-.Dd July 8, 2013
+.Dd July 5, 2018
 .Dt ARP 8
 .Os
 .Sh NAME
@@ -132,11 +132,19 @@ server,
 responding to requests for
 .Ar hostname
 even though the host address is not its own.
+.Pp
 If the word
 .Cm proxy
 is also given, the published entry will be a
 .Dq proxy only
 entry.
+In this case the
+.Ar ether_addr
+can be given as
+.Cm auto
+in which case the interfaces on this host will be examined,
+and if one of them is found to occupy the same subnet, its
+Ethernet address will be used.
 .It Fl v
 Display verbose information when adding or deleting
 .Tn ARP

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.59 src/usr.sbin/arp/arp.c:1.60
--- src/usr.sbin/arp/arp.c:1.59	Fri Jun  8 00:24:12 2018
+++ src/usr.sbin/arp/arp.c	Thu Jul  5 20:50:05 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.59 2018/06/08 04:24:12 nonaka Exp $ */
+/*	$NetBSD: arp.c,v 1.60 2018/07/06 00:50:05 christos Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.59 2018/06/08 04:24:12 nonaka Exp $");
+__RCSID("$NetBSD: arp.c,v 1.60 2018/07/06 00:50:05 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -84,14 +84,14 @@ static void dump(uint32_t);
 static void delete(const char *, const char *);
 static void sdl_print(const struct sockaddr_dl *);
 static int getifname(u_int16_t, char *, size_t);
-static int atosdl(const char *s, struct sockaddr_dl *sdl);
+static int atosdl(const char *, struct sockaddr_dl *);
 static int file(const char *);
 static void get(const char *);
 static int getinetaddr(const char *, struct in_addr *);
 static int getsocket(void);
-static struct rt_msghdr *
-	rtmsg(const int, const int,  struct rt_msghdr *,
-	const struct sockaddr_inarp *, const struct sockaddr_dl *);
+static int getetheraddr(struct in_addr, struct sockaddr_dl *);
+static struct rt_msghdr * rtmsg(const int, const int,  struct rt_msghdr *,
+	const struct sockaddr_inarp *, const struct sockaddr_dl *);
 static int set(int, char **);
 static void usage(void) __dead;
 
@@ -278,7 +278,7 @@ set(int argc, char **argv)
 
 	if (getinetaddr(host, &sin_m.sin_addr) == -1)
 		return (1);
-	if (atosdl(eaddr, &sdl_m))
+	if (!strcmp(eaddr, "auto") && atosdl(eaddr, &sdl_m))
 		warnx("invalid link-level address '%s'", eaddr);
 	doing_proxy = flags = export_only = expire_time = 0;
 	for (; argc-- > 0; argv++) {
@@ -309,6 +309,10 @@ set(int argc, char **argv)
 		}
 
 	}
+	if (doing_proxy && !strcmp(eaddr, "auto")) {
+		if (getetheraddr(sin_m.sin_addr, &sdl_m) == -1)
+			return 1;
+	}
 tryagain:
 	rtm = rtmsg(s, RTM_GET, NULL, &sin_m, &sdl_m);
 	if (rtm == NULL) {
@@ -706,7 +710,7 @@ getifname(u_int16_t ifindex, char *ifnam
 {
 	int i;
 	struct ifaddrs *addr;
-	const struct sockaddr_dl *sdl = NULL;
+	const struct sockaddr_dl *sdl;
 	static struct ifaddrs* ifaddrs = NULL;
 
 	if (ifaddrs == NULL) {
@@ -729,3 +733,51 @@ getifname(u_int16_t ifindex, char *ifnam
 
 	return -1;
 }
+
+static int
+getetheraddr(struct in_addr ipaddr, struct sockaddr_dl *sdl)
+{
+	struct ifaddrs *ifaddrs, *addr;
+	in_addr_t ina, mask;
+	char ifname[IFNAMSIZ];
+
+	if (getifaddrs(&ifaddrs) != 0) {
+		warn("getifaddrs");
+		return -1;
+	}
+
+	for (addr = ifaddrs; addr; addr = addr->ifa_next) {
+		if (addr->ifa_addr == NULL ||
+		addr->ifa_addr->sa_family != AF_INET)
+			continue;
+		if ((addr->ifa_flags & (IFF_UP|IFF_BROADCAST|IFF_POINTOPOINT|
+		IFF_LOOPBACK|IFF_NOARP)) != (IFF_UP|IFF_BROADCAST))
+			continue;
+
+		mask = ((struct sockaddr_in *)(void *)addr->ifa_netmask)->sin_addr.s_addr;
+		ina = ((struct sockaddr_in *)(void *)addr->ifa_addr)->sin_addr.s_addr;
+		if ((ipaddr.s_addr & mask) != (ina & mask))
+			continue;
+		strlcpy(ifname, addr->ifa_name, sizeof(ifname));
+		break;
+	}
+	if (addr == NULL) {
+		warnx("No interface matched %s", inet_ntoa(ipaddr));
+		freeifaddrs(ifaddrs);
+		return -1;
+	}
+
+	for (ad

CVS commit: src/usr.sbin/arp

2018-06-07 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Fri Jun  8 04:24:12 UTC 2018

Modified Files:
src/usr.sbin/arp: arp.c

Log Message:
fix usage of `arp -d'.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/usr.sbin/arp/arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.58 src/usr.sbin/arp/arp.c:1.59
--- src/usr.sbin/arp/arp.c:1.58	Wed Jun 28 08:17:50 2017
+++ src/usr.sbin/arp/arp.c	Fri Jun  8 04:24:12 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.58 2017/06/28 08:17:50 ozaki-r Exp $ */
+/*	$NetBSD: arp.c,v 1.59 2018/06/08 04:24:12 nonaka Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.58 2017/06/28 08:17:50 ozaki-r Exp $");
+__RCSID("$NetBSD: arp.c,v 1.59 2018/06/08 04:24:12 nonaka Exp $");
 #endif
 #endif /* not lint */
 
@@ -597,7 +597,7 @@ usage(void)
 	progname = getprogname();
 	(void)fprintf(stderr, "Usage: %s [-n] hostname\n", progname);
 	(void)fprintf(stderr, "   %s [-nv] -a\n", progname);
-	(void)fprintf(stderr, "   %s [-v] -d [-a|hostname [pub [proxy]]]\n",
+	(void)fprintf(stderr, "   %s [-v] -d [-a|hostname [proxy]]\n",
 	progname);
 	(void)fprintf(stderr, "   %s -s hostname ether_addr [temp] [pub [proxy]]\n",
 	progname);



CVS commit: src/usr.sbin/arp

2017-06-06 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Tue Jun  6 19:59:10 UTC 2017

Modified Files:
src/usr.sbin/arp: arp.c

Log Message:
whitespace police


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/usr.sbin/arp/arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.55 src/usr.sbin/arp/arp.c:1.56
--- src/usr.sbin/arp/arp.c:1.55	Mon Apr  4 07:37:08 2016
+++ src/usr.sbin/arp/arp.c	Tue Jun  6 19:59:10 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.55 2016/04/04 07:37:08 ozaki-r Exp $ */
+/*	$NetBSD: arp.c,v 1.56 2017/06/06 19:59:10 ryo Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.55 2016/04/04 07:37:08 ozaki-r Exp $");
+__RCSID("$NetBSD: arp.c,v 1.56 2017/06/06 19:59:10 ryo Exp $");
 #endif
 #endif /* not lint */
 
@@ -96,7 +96,7 @@ static int set(int, char **);
 static void usage(void) __dead;
 
 static int aflag, nflag, vflag;
-static struct sockaddr_in so_mask = { 
+static struct sockaddr_in so_mask = {
 	.sin_len = 8,
 	.sin_addr = {
 		.s_addr = 0x
@@ -206,7 +206,7 @@ file(const char *name)
 		inputstring = line;
 		for (ap = argv; ap < &argv[sizeof(argv) / sizeof(argv[0])] &&
 		(*ap = stresep(&inputstring, " \t", '\\')) != NULL;) {
-		   if (**ap != '\0')
+			if (**ap != '\0')
 ap++;
 		}
 		i = ap - argv;
@@ -257,7 +257,7 @@ getlink(const char *name, struct sockadd
 }
 
 /*
- * Set an individual arp entry 
+ * Set an individual arp entry
  */
 static int
 set(int argc, char **argv)
@@ -291,8 +291,8 @@ set(int argc, char **argv)
 			flags |= RTF_ANNOUNCE;
 			doing_proxy = 1;
 			if (argc && strncmp(argv[1], "pro", 3) == 0) {
-			export_only = 1;
-			argc--; argv++;
+export_only = 1;
+argc--; argv++;
 			}
 		} else if (strncmp(argv[0], "trail", 5) == 0) {
 			warnx("%s: Sending trailers is no longer supported",
@@ -387,7 +387,7 @@ is_llinfo(const struct sockaddr_dl *sdl,
 }
 
 /*
- * Delete an arp entry 
+ * Delete an arp entry
  */
 int
 delete(const char *host, const char *info)
@@ -401,7 +401,7 @@ delete(const char *host, const char *inf
 
 	s = getsocket();
 	if (info && strncmp(info, "pro", 3) == 0)
-		 sin_m.sin_other = SIN_PROXY;
+		sin_m.sin_other = SIN_PROXY;
 	if (getinetaddr(host, &sin_m.sin_addr) == -1)
 		return (1);
 tryagain:
@@ -572,13 +572,13 @@ atosdl(const char *ss, struct sockaddr_d
 	int i;
 	unsigned long b;
 	char *endp;
-	char *p; 
+	char *p;
 	char *t, *r;
 
 	p = LLADDR(sdl);
 	endp = ((char *)(void *)sdl) + sdl->sdl_len;
 	i = 0;
-	
+
 	b = strtoul(ss, &t, 16);
 	if (b > 255 || t == ss)
 		return 1;
@@ -605,8 +605,8 @@ usage(void)
 
 	progname = getprogname();
 	(void)fprintf(stderr, "Usage: %s [-n] hostname\n", progname);
-	(void)fprintf(stderr, "	  %s [-nv] -a\n", progname);
-	(void)fprintf(stderr, "	  %s [-v] -d [-a|hostname [pub [proxy]]]\n",
+	(void)fprintf(stderr, "   %s [-nv] -a\n", progname);
+	(void)fprintf(stderr, "   %s [-v] -d [-a|hostname [pub [proxy]]]\n",
 	progname);
 	(void)fprintf(stderr, "   %s -s hostname ether_addr [temp] [pub [proxy]]\n",
 	progname);
@@ -725,7 +725,7 @@ getifname(u_int16_t ifindex, char *ifnam
 	}
 
 	for (addr = ifaddrs; addr; addr = addr->ifa_next) {
-		if (addr->ifa_addr == NULL || 
+		if (addr->ifa_addr == NULL ||
 		addr->ifa_addr->sa_family != AF_LINK)
 			continue;
 



CVS commit: src/usr.sbin/arp

2016-10-15 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Sun Oct 16 05:32:30 UTC 2016

Modified Files:
src/usr.sbin/arp: arp.4

Log Message:
Add missing verb. New sentence, new line.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/arp/arp.4

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.4
diff -u src/usr.sbin/arp/arp.4:1.13 src/usr.sbin/arp/arp.4:1.14
--- src/usr.sbin/arp/arp.4:1.13	Wed Oct 12 08:43:17 2016
+++ src/usr.sbin/arp/arp.4	Sun Oct 16 05:32:30 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: arp.4,v 1.13 2016/10/12 08:43:17 roy Exp $
+.\"	$NetBSD: arp.4,v 1.14 2016/10/16 05:32:30 wiz Exp $
 .\"
 .\" Copyright (c) 1985, 1986, 1988, 1994
 .\"	The Regents of the University of California.  All rights reserved.
@@ -83,10 +83,11 @@ This is no longer supported.
 .Sh DIAGNOSTICS
 .Bl -diag
 ARP implements Address Conflict Detection.
-When an address is first added to the host, it marked tentative and
+When an address is first added to the host, it is marked tentative and
 ARP probes the network to discover if another host has the address.
 If another host replies with the same address, then the local address is
-marked duplicate and the host will not use it. Otherwise the tentative
+marked duplicate and the host will not use it.
+Otherwise the tentative
 mark is removed and the host can start using the address.
 .Pp
 ARP will defend the host's active address when a conflicting message is



CVS commit: src/usr.sbin/arp

2016-10-12 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Wed Oct 12 08:43:18 UTC 2016

Modified Files:
src/usr.sbin/arp: arp.4

Log Message:
Document our RFC 5227 implementation.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/arp/arp.4

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.4
diff -u src/usr.sbin/arp/arp.4:1.12 src/usr.sbin/arp/arp.4:1.13
--- src/usr.sbin/arp/arp.4:1.12	Mon Apr  4 13:32:37 2016
+++ src/usr.sbin/arp/arp.4	Wed Oct 12 08:43:17 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: arp.4,v 1.12 2016/04/04 13:32:37 wiz Exp $
+.\"	$NetBSD: arp.4,v 1.13 2016/10/12 08:43:17 roy Exp $
 .\"
 .\" Copyright (c) 1985, 1986, 1988, 1994
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	from: @(#)arp4.4	6.5 (Berkeley) 4/18/94
 .\"
-.Dd March 30, 2016
+.Dd October 12, 2016
 .Dt ARP 4
 .Os
 .Sh NAME
@@ -80,16 +80,31 @@ as if it were the target of the request.
 In the past,
 ARP was used to negotiate the use of a trailer encapsulation.
 This is no longer supported.
-.Pp
-ARP watches passively for hosts impersonating the local host (i.e. a host
-which responds to an ARP mapping request for the local host's address).
 .Sh DIAGNOSTICS
 .Bl -diag
-.It "duplicate IP address %x sent from ethernet address %x:%x:%x:%x:%x:%x."
-ARP has discovered another host on the local network which responds to
-mapping requests for its own Internet address with a different Ethernet
-address, generally indicating that two hosts are attempting to use the
-same Internet address.
+ARP implements Address Conflict Detection.
+When an address is first added to the host, it marked tentative and
+ARP probes the network to discover if another host has the address.
+If another host replies with the same address, then the local address is
+marked duplicate and the host will not use it. Otherwise the tentative
+mark is removed and the host can start using the address.
+.Pp
+ARP will defend the host's active address when a conflicting message is
+received.
+However, if another conflicting message for the address is found within
+a 10 second period, then the address is marked duplicate and the host will
+stop using it.
+.Pp
+For some systems such as a router or a server,
+it is desirable never to give up an assigned address.
+This can be achieved by setting the
+.Xr sysctl 7
+variable
+.Dv net.inet.ip_dad_count
+to 0.
+.Pp
+In all of the above cases, ARP will log diagnostic messages which include
+the hardware address of the conflicting host.
 .El
 .Sh SEE ALSO
 .Xr inet 4 ,
@@ -109,7 +124,15 @@ same Internet address.
 .%B "Trailer Encapsulations"
 .%T RFC 893
 .Re
+.Rs
+.%A Cheshire, S.
+.%B "IPv4 Address Conflict Detection"
+.%T RFC 5227
+.Re
 .Sh HISTORY
 Since
 .Nx 8.0 ,
 the ARP cache was not stored in the routing table.
+.Pp
+Address Conflict Detection was added in
+.Nx 8.0 .



CVS commit: src/usr.sbin/arp

2016-04-04 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Apr  4 13:32:37 UTC 2016

Modified Files:
src/usr.sbin/arp: arp.4

Log Message:
Sort sections.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/arp/arp.4

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.4
diff -u src/usr.sbin/arp/arp.4:1.11 src/usr.sbin/arp/arp.4:1.12
--- src/usr.sbin/arp/arp.4:1.11	Mon Apr  4 07:37:08 2016
+++ src/usr.sbin/arp/arp.4	Mon Apr  4 13:32:37 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: arp.4,v 1.11 2016/04/04 07:37:08 ozaki-r Exp $
+.\"	$NetBSD: arp.4,v 1.12 2016/04/04 13:32:37 wiz Exp $
 .\"
 .\" Copyright (c) 1985, 1986, 1988, 1994
 .\"	The Regents of the University of California.  All rights reserved.
@@ -91,10 +91,6 @@ mapping requests for its own Internet ad
 address, generally indicating that two hosts are attempting to use the
 same Internet address.
 .El
-.Sh HISTORY
-Since
-.Nx 8.0 ,
-the ARP cache was not stored in the routing table.
 .Sh SEE ALSO
 .Xr inet 4 ,
 .Xr route 4 ,
@@ -113,3 +109,7 @@ the ARP cache was not stored in the rout
 .%B "Trailer Encapsulations"
 .%T RFC 893
 .Re
+.Sh HISTORY
+Since
+.Nx 8.0 ,
+the ARP cache was not stored in the routing table.



CVS commit: src/usr.sbin/arp

2016-02-24 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Feb 24 08:01:09 UTC 2016

Modified Files:
src/usr.sbin/arp: arp.c

Log Message:
Kill confusable use of SIN_PROXY


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/usr.sbin/arp/arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.53 src/usr.sbin/arp/arp.c:1.54
--- src/usr.sbin/arp/arp.c:1.53	Fri Jul 31 04:02:40 2015
+++ src/usr.sbin/arp/arp.c	Wed Feb 24 08:01:09 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.53 2015/07/31 04:02:40 ozaki-r Exp $ */
+/*	$NetBSD: arp.c,v 1.54 2016/02/24 08:01:09 ozaki-r Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.53 2015/07/31 04:02:40 ozaki-r Exp $");
+__RCSID("$NetBSD: arp.c,v 1.54 2016/02/24 08:01:09 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -289,7 +289,7 @@ set(int argc, char **argv)
 		}
 		else if (strncmp(argv[0], "pub", 3) == 0) {
 			flags |= RTF_ANNOUNCE;
-			doing_proxy = SIN_PROXY;
+			doing_proxy = 1;
 			if (argc && strncmp(argv[1], "pro", 3) == 0) {
 			export_only = 1;
 			argc--; argv++;



CVS commit: src/usr.sbin/arp

2015-07-30 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Jul 31 04:02:40 UTC 2015

Modified Files:
src/usr.sbin/arp: arp.c

Log Message:
Reduce abuse of global variables


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/usr.sbin/arp/arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.52 src/usr.sbin/arp/arp.c:1.53
--- src/usr.sbin/arp/arp.c:1.52	Wed Jul 29 06:07:35 2015
+++ src/usr.sbin/arp/arp.c	Fri Jul 31 04:02:40 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.52 2015/07/29 06:07:35 ozaki-r Exp $ */
+/*	$NetBSD: arp.c,v 1.53 2015/07/31 04:02:40 ozaki-r Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.52 2015/07/29 06:07:35 ozaki-r Exp $");
+__RCSID("$NetBSD: arp.c,v 1.53 2015/07/31 04:02:40 ozaki-r Exp $");
 #endif
 #endif /* not lint */
 
@@ -88,15 +88,14 @@ static int atosdl(const char *s, struct 
 static int file(const char *);
 static void get(const char *);
 static int getinetaddr(const char *, struct in_addr *);
-static void getsocket(void);
-static int rtmsg(int);
+static int getsocket(void);
+static struct rt_msghdr *
+	rtmsg(const int, const int, const struct sockaddr_inarp *,
+	const struct sockaddr_dl *);
 static int set(int, char **);
 static void usage(void) __dead;
 
-static pid_t pid;
 static int aflag, nflag, vflag;
-static int s = -1;
-static struct ifaddrs* ifaddrs = NULL;
 static struct sockaddr_in so_mask = { 
 	.sin_len = 8,
 	.sin_addr = {
@@ -107,18 +106,12 @@ static struct sockaddr_inarp blank_sin =
 	.sin_len = sizeof(blank_sin),
 	.sin_family = AF_INET
 };
-static struct sockaddr_inarp sin_m;
 static struct sockaddr_dl blank_sdl = {
 	.sdl_len = sizeof(blank_sdl),
 	.sdl_family = AF_LINK
 };
-static struct sockaddr_dl sdl_m;
 
 static int expire_time, flags, export_only, doing_proxy, found_entry;
-static struct {
-	struct	rt_msghdr m_rtm;
-	char	m_space[512];
-} m_rtmsg;
 
 int
 main(int argc, char **argv)
@@ -158,8 +151,6 @@ main(int argc, char **argv)
 	if (prog_init && prog_init() == -1)
 		err(1, "init failed");
 
-	pid = prog_getpid();
-
 	switch((char)op) {
 	case 'a':
 		dump(0);
@@ -232,14 +223,14 @@ file(const char *name)
 	return retval;
 }
 
-static void
+static int
 getsocket(void)
 {
-	if (s >= 0)
-		return;
+	int s;
 	s = prog_socket(PF_ROUTE, SOCK_RAW, 0);
 	if (s < 0)
 		err(1, "socket");
+	return s;
 }
 
 static int
@@ -275,18 +266,17 @@ set(int argc, char **argv)
 	struct sockaddr_dl *sdl;
 	struct rt_msghdr *rtm;
 	char *host = argv[0], *eaddr;
-	int rval;
+	struct sockaddr_inarp sin_m = blank_sin; /* struct copy */
+	struct sockaddr_dl sdl_m = blank_sdl; /* struct copy */
+	int s;
 
-	sina = &sin_m;
-	rtm = &(m_rtmsg.m_rtm);
 	eaddr = argv[1];
 
-	getsocket();
+	s = getsocket();
 	argc -= 2;
 	argv += 2;
-	sdl_m = blank_sdl;		/* struct copy */
-	sin_m = blank_sin;		/* struct copy */
-	if (getinetaddr(host, &sina->sin_addr) == -1)
+
+	if (getinetaddr(host, &sin_m.sin_addr) == -1)
 		return (1);
 	if (atosdl(eaddr, &sdl_m))
 		warnx("invalid link-level address '%s'", eaddr);
@@ -322,7 +312,8 @@ set(int argc, char **argv)
 	if (memcmp(&sdl_m, &blank_sdl, sizeof(blank_sdl)))
 		goto out;
 tryagain:
-	if (rtmsg(RTM_GET) < 0) {
+	rtm = rtmsg(s, RTM_GET, &sin_m, &sdl_m);
+	if (rtm == NULL) {
 		warn("%s", host);
 		return (1);
 	}
@@ -353,10 +344,13 @@ overwrite:
 	sdl_m.sdl_type = sdl->sdl_type;
 	sdl_m.sdl_index = sdl->sdl_index;
 out:
-	rval = rtmsg(RTM_ADD);
+	sin_m.sin_other = 0;
+	if (doing_proxy && export_only)
+		sin_m.sin_other = SIN_PROXY;
+	rtm = rtmsg(s, RTM_ADD, &sin_m, &sdl_m);
 	if (vflag)
 		(void)printf("%s (%s) added\n", host, eaddr);
-	return (rval);
+	return (rtm == NULL) ? 1 : 0;
 }
 
 /*
@@ -365,15 +359,13 @@ out:
 static void
 get(const char *host)
 {
-	struct sockaddr_inarp *sina;
+	struct sockaddr_inarp sin = blank_sin; /* struct copy */
 
-	sina = &sin_m;
-	sin_m = blank_sin;		/* struct copy */
-	if (getinetaddr(host, &sina->sin_addr) == -1)
+	if (getinetaddr(host, &sin.sin_addr) == -1)
 		exit(1);
-	dump(sina->sin_addr.s_addr);
+	dump(sin.sin_addr.s_addr);
 	if (found_entry == 0)
-		errx(1, "%s (%s) -- no entry", host, inet_ntoa(sina->sin_addr));
+		errx(1, "%s (%s) -- no entry", host, inet_ntoa(sin.sin_addr));
 }
 
 
@@ -404,20 +396,20 @@ int
 delete(const char *host, const char *info)
 {
 	struct sockaddr_inarp *sina;
-	struct rt_msghdr *rtm;
 	struct sockaddr_dl *sdl;
+	struct rt_msghdr *rtm;
+	struct sockaddr_inarp sin_m = blank_sin; /* struct copy */
+	struct sockaddr_dl sdl_m = blank_sdl; /* struct copy */
+	int s;
 
-	sina = &sin_m;
-	rtm = &m_rtmsg.m_rtm;
-
-	getsocket();
-	sin_m = blank_sin;		/* struct copy */
+	s = getsocket();
 	if (info && strncmp(info, "pro", 3) == 0)
-		 sina->sin_other = SIN_P

CVS commit: src/usr.sbin/arp

2013-07-07 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Mon Jul  8 04:31:12 UTC 2013

Modified Files:
src/usr.sbin/arp: arp.8

Log Message:
Use .Cm markup for the keywords "temp", "pub", and "proxy" (suggested
by wiz).  Also bump date.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.sbin/arp/arp.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.8
diff -u src/usr.sbin/arp/arp.8:1.22 src/usr.sbin/arp/arp.8:1.23
--- src/usr.sbin/arp/arp.8:1.22	Fri Jun  7 18:33:53 2013
+++ src/usr.sbin/arp/arp.8	Mon Jul  8 04:31:12 2013
@@ -1,4 +1,4 @@
-.\"	$NetBSD: arp.8,v 1.22 2013/06/07 18:33:53 apb Exp $
+.\"	$NetBSD: arp.8,v 1.23 2013/07/08 04:31:12 apb Exp $
 .\"
 .\" Copyright (c) 1985, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"	from: @(#)arp.8	8.2 (Berkeley) 4/27/95
 .\"
-.Dd January 31, 2006
+.Dd July 8, 2013
 .Dt ARP 8
 .Os
 .Sh NAME
@@ -49,11 +49,11 @@
 .Nm
 .Op Fl v
 .Fl d Ar hostname
-.Op proxy
+.Op Cm proxy
 .Nm
 .Fl s Ar hostname ether_addr
-.Op temp
-.Op pub Op proxy
+.Op Cm temp
+.Op Cm pub Op Cm proxy
 .Nm
 .Fl f Ar filename
 .Sh DESCRIPTION
@@ -82,7 +82,7 @@ with the
 .Fl d
 flag.
 If the
-.Dq proxy
+.Cm proxy
 keyword is specified, only the published
 .Dq proxy only
 .Tn ARP
@@ -103,8 +103,8 @@ Entries in the file should be of the for
 .Pp
 .Bd -filled -offset indent -compact
 .Ar hostname ether_addr
-.Op temp
-.Op pub
+.Op Cm temp
+.Op Cm pub
 .Ed
 .Pp
 with argument meanings as described below.
@@ -121,10 +121,10 @@ with the Ethernet address
 .Ar ether_addr .
 The Ethernet address is given as six hex bytes separated by colons.
 The entry will be permanent unless the word
-.Dq temp
+.Cm temp
 is given in the command.
 If the word
-.Dq pub
+.Cm pub
 is given, the entry will be "published"; i.e., this system will
 act as an
 .Tn ARP
@@ -133,7 +133,7 @@ responding to requests for
 .Ar hostname
 even though the host address is not its own.
 If the word
-.Dq proxy
+.Cm proxy
 is also given, the published entry will be a
 .Dq proxy only
 entry.



CVS commit: src/usr.sbin/arp

2013-06-07 Thread Alan Barrett
Module Name:src
Committed By:   apb
Date:   Fri Jun  7 18:33:53 UTC 2013

Modified Files:
src/usr.sbin/arp: arp.8

Log Message:
"temp", "pub", and "proxy" are keywords, not replaceable
parameters, so do not use ".Ar" markup.  Use either no markup,
or ".Dq" markup, depending on context.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.sbin/arp/arp.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.8
diff -u src/usr.sbin/arp/arp.8:1.21 src/usr.sbin/arp/arp.8:1.22
--- src/usr.sbin/arp/arp.8:1.21	Mon Apr 25 22:20:29 2011
+++ src/usr.sbin/arp/arp.8	Fri Jun  7 18:33:53 2013
@@ -1,4 +1,4 @@
-.\"	$NetBSD: arp.8,v 1.21 2011/04/25 22:20:29 wiz Exp $
+.\"	$NetBSD: arp.8,v 1.22 2013/06/07 18:33:53 apb Exp $
 .\"
 .\" Copyright (c) 1985, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -49,11 +49,11 @@
 .Nm
 .Op Fl v
 .Fl d Ar hostname
-.Op Ar proxy
+.Op proxy
 .Nm
 .Fl s Ar hostname ether_addr
-.Op Ar temp
-.Op Ar pub Op Ar proxy
+.Op temp
+.Op pub Op proxy
 .Nm
 .Fl f Ar filename
 .Sh DESCRIPTION
@@ -82,7 +82,7 @@ with the
 .Fl d
 flag.
 If the
-.Cm proxy
+.Dq proxy
 keyword is specified, only the published
 .Dq proxy only
 .Tn ARP
@@ -103,8 +103,8 @@ Entries in the file should be of the for
 .Pp
 .Bd -filled -offset indent -compact
 .Ar hostname ether_addr
-.Op Ar temp
-.Op Ar pub
+.Op temp
+.Op pub
 .Ed
 .Pp
 with argument meanings as described below.
@@ -121,10 +121,10 @@ with the Ethernet address
 .Ar ether_addr .
 The Ethernet address is given as six hex bytes separated by colons.
 The entry will be permanent unless the word
-.Ar temp
+.Dq temp
 is given in the command.
 If the word
-.Ar pub
+.Dq pub
 is given, the entry will be "published"; i.e., this system will
 act as an
 .Tn ARP
@@ -133,7 +133,7 @@ responding to requests for
 .Ar hostname
 even though the host address is not its own.
 If the word
-.Ar proxy
+.Dq proxy
 is also given, the published entry will be a
 .Dq proxy only
 entry.



CVS commit: src/usr.sbin/arp

2013-06-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jun  7 17:18:33 UTC 2013

Modified Files:
src/usr.sbin/arp: arp.c

Log Message:
allow ifscope with pub and proxy


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/usr.sbin/arp/arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.50 src/usr.sbin/arp/arp.c:1.51
--- src/usr.sbin/arp/arp.c:1.50	Thu Jun  6 21:09:10 2013
+++ src/usr.sbin/arp/arp.c	Fri Jun  7 13:18:33 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.50 2013/06/07 01:09:10 christos Exp $ */
+/*	$NetBSD: arp.c,v 1.51 2013/06/07 17:18:33 christos Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.50 2013/06/07 01:09:10 christos Exp $");
+__RCSID("$NetBSD: arp.c,v 1.51 2013/06/07 17:18:33 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -169,7 +169,7 @@ main(int argc, char **argv)
 		}
 		break;
 	case 's':
-		if (argc < 2 || argc > 5)
+		if (argc < 2 || argc > 7)
 			usage();
 		return (set(argc, argv) ? 1 : 0);
 	case 'f':



CVS commit: src/usr.sbin/arp

2013-06-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jun  7 01:09:10 UTC 2013

Modified Files:
src/usr.sbin/arp: arp.c

Log Message:
Add an ifscope  argument to arp in the spirit of the MacOS/X one,
that sets the arp entry on the interface specified. Undocumented for now,
until people decide it is useful.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/usr.sbin/arp/arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.49 src/usr.sbin/arp/arp.c:1.50
--- src/usr.sbin/arp/arp.c:1.49	Thu Jun 10 02:03:20 2010
+++ src/usr.sbin/arp/arp.c	Thu Jun  6 21:09:10 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.49 2010/06/10 06:03:20 dholland Exp $ */
+/*	$NetBSD: arp.c,v 1.50 2013/06/07 01:09:10 christos Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1984, 19
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.49 2010/06/10 06:03:20 dholland Exp $");
+__RCSID("$NetBSD: arp.c,v 1.50 2013/06/07 01:09:10 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -237,6 +237,29 @@ getsocket(void)
 		err(1, "socket");
 }
 
+static int
+getlink(const char *name, struct sockaddr_dl *sdl)
+{
+	struct ifaddrs *ifap, *ifa;
+
+	if (getifaddrs(&ifap) != 0) {
+		warn("getifaddrs");
+		return 0;
+	}
+
+	for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+		if (ifa->ifa_addr->sa_family != AF_LINK)
+			continue;
+		if (strcmp(ifa->ifa_name, name) != 0)
+			continue;
+		memcpy(sdl, ifa->ifa_addr, sizeof(*sdl));
+		freeifaddrs(ifap);
+		return 1;
+	}
+	freeifaddrs(ifap);
+	return 0;
+}
+
 /*
  * Set an individual arp entry 
  */
@@ -263,7 +286,7 @@ set(int argc, char **argv)
 	if (atosdl(eaddr, &sdl_m))
 		warnx("invalid link-level address '%s'", eaddr);
 	doing_proxy = flags = export_only = expire_time = 0;
-	while (argc-- > 0) {
+	for (; argc-- > 0; argv++) {
 		if (strncmp(argv[0], "temp", 4) == 0) {
 			struct timeval timev;
 			(void)gettimeofday(&timev, 0);
@@ -279,9 +302,20 @@ set(int argc, char **argv)
 		} else if (strncmp(argv[0], "trail", 5) == 0) {
 			warnx("%s: Sending trailers is no longer supported",
 			host);
+		} else if (strcmp(argv[0], "ifscope") == 0) {
+			if (argc == 0) {
+warnx("missing interface for ifscope");
+continue;
+			}
+			argc--;
+			argv++;
+			if (!getlink(argv[0], &sdl_m))
+warnx("cannot get link address for %s", argv[0]);
 		}
-		argv++;
+
 	}
+	if (memcmp(&sdl_m, &blank_sdl, sizeof(blank_sdl)))
+		goto out;
 tryagain:
 	if (rtmsg(RTM_GET) < 0) {
 		warn("%s", host);
@@ -313,6 +347,7 @@ overwrite:
 	}
 	sdl_m.sdl_type = sdl->sdl_type;
 	sdl_m.sdl_index = sdl->sdl_index;
+out:
 	rval = rtmsg(RTM_ADD);
 	if (vflag)
 		(void)printf("%s (%s) added\n", host, eaddr);



CVS commit: src/usr.sbin/arp

2011-04-25 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Mon Apr 25 22:20:30 UTC 2011

Modified Files:
src/usr.sbin/arp: arp.8

Log Message:
New sentence, new line. Remove trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/arp/arp.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.8
diff -u src/usr.sbin/arp/arp.8:1.20 src/usr.sbin/arp/arp.8:1.21
--- src/usr.sbin/arp/arp.8:1.20	Thu Jan 10 14:16:26 2008
+++ src/usr.sbin/arp/arp.8	Mon Apr 25 22:20:29 2011
@@ -1,4 +1,4 @@
-.\"	$NetBSD: arp.8,v 1.20 2008/01/10 14:16:26 seanb Exp $
+.\"	$NetBSD: arp.8,v 1.21 2011/04/25 22:20:29 wiz Exp $
 .\"
 .\" Copyright (c) 1985, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -80,7 +80,7 @@
 .Ar hostname
 with the
 .Fl d
-flag. 
+flag.
 If the
 .Cm proxy
 keyword is specified, only the published
@@ -131,7 +131,8 @@
 server,
 responding to requests for
 .Ar hostname
-even though the host address is not its own.  If the word
+even though the host address is not its own.
+If the word
 .Ar proxy
 is also given, the published entry will be a
 .Dq proxy only



CVS commit: src/usr.sbin/arp

2010-06-09 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Thu Jun 10 06:03:20 UTC 2010

Modified Files:
src/usr.sbin/arp: arp.c

Log Message:
Allow -f -, as per PR 10898.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/usr.sbin/arp/arp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/arp/arp.c
diff -u src/usr.sbin/arp/arp.c:1.48 src/usr.sbin/arp/arp.c:1.49
--- src/usr.sbin/arp/arp.c:1.48	Thu Apr  2 21:02:06 2009
+++ src/usr.sbin/arp/arp.c	Thu Jun 10 06:03:20 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: arp.c,v 1.48 2009/04/02 21:02:06 christos Exp $ */
+/*	$NetBSD: arp.c,v 1.49 2010/06/10 06:03:20 dholland Exp $ */
 
 /*
  * Copyright (c) 1984, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)arp.c	8.3 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: arp.c,v 1.48 2009/04/02 21:02:06 christos Exp $");
+__RCSID("$NetBSD: arp.c,v 1.49 2010/06/10 06:03:20 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -195,8 +195,14 @@
 	int i, retval;
 	FILE *fp;
 
-	if ((fp = fopen(name, "r")) == NULL)
-		err(1, "cannot open %s", name);
+	if (!strcmp(name, "-")) {
+		fp = stdin;
+	} else {
+		fp = fopen(name, "r");
+		if (fp == NULL) {
+			err(1, "Cannot open %s", name);
+		}
+	}
 	retval = 0;
 	for (; (line = fparseln(fp, NULL, NULL, NULL, 0)) != NULL; free(line)) {
 		char **ap, *inputstring;
@@ -216,7 +222,8 @@
 		if (set(i, argv))
 			retval = 1;
 	}
-	(void)fclose(fp);
+	if (fp != stdin)
+		(void)fclose(fp);
 	return retval;
 }