Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/arp Add an ifscope <interface> argument to arp in t...
details: https://anonhg.NetBSD.org/src/rev/07c9f62ff4de
branches: trunk
changeset: 787224:07c9f62ff4de
user: christos <christos%NetBSD.org@localhost>
date: Fri Jun 07 01:09:10 2013 +0000
description:
Add an ifscope <interface> 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.
diffstat:
usr.sbin/arp/arp.c | 43 +++++++++++++++++++++++++++++++++++++++----
1 files changed, 39 insertions(+), 4 deletions(-)
diffs (87 lines):
diff -r a6530d7b6203 -r 07c9f62ff4de usr.sbin/arp/arp.c
--- a/usr.sbin/arp/arp.c Thu Jun 06 21:42:36 2013 +0000
+++ b/usr.sbin/arp/arp.c Fri Jun 07 01:09:10 2013 +0000
@@ -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 @@
#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 @@
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 @@
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 @@
} 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 @@
}
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);
Home |
Main Index |
Thread Index |
Old Index