Module Name: src
Committed By: mbalmer
Date: Mon Jan 4 11:34:40 UTC 2010
Modified Files:
src/usr.sbin/wake: wake.8 wake.c
Log Message:
Only use an auto-determined interface if it is the only one in the system
that is up and running. This change prevents wake(8) from picking an
arbitrary interface (which is possibly the wrong one).
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/wake/wake.8
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/wake/wake.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/wake/wake.8
diff -u src/usr.sbin/wake/wake.8:1.7 src/usr.sbin/wake/wake.8:1.8
--- src/usr.sbin/wake/wake.8:1.7 Sun Jan 3 19:04:26 2010
+++ src/usr.sbin/wake/wake.8 Mon Jan 4 11:34:39 2010
@@ -1,4 +1,4 @@
-.\" $NetBSD: wake.8,v 1.7 2010/01/03 19:04:26 wiz Exp $
+.\" $NetBSD: wake.8,v 1.8 2010/01/04 11:34:39 mbalmer Exp $
.\"
.\" Copyright (c) 2009, 2010 Marc Balmer <[email protected]>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd January 3, 2010
+.Dd January 4, 2010
.Dt WAKE 8
.Os
.Sh NAME
@@ -35,13 +35,12 @@
and can be used to power on machines from a remote system without
having physical access to them.
.Pp
-If
.Ar interface
-is an Ethernet interface of the local machine, it is used to send the
+is an Ethernet interface of the local machine and is used to send the
Wake on LAN frames over it.
-Else
-.Nm
-uses the first Ethernet device found in the system.
+If there is only one Ethernet device available that is up and running, then the
+.Ar interface
+argument can be omitted.
.Ar lladdr
is the link layer address of the remote machine.
This can be specified as the actual hardware address
Index: src/usr.sbin/wake/wake.c
diff -u src/usr.sbin/wake/wake.c:1.10 src/usr.sbin/wake/wake.c:1.11
--- src/usr.sbin/wake/wake.c:1.10 Sun Jan 3 17:58:14 2010
+++ src/usr.sbin/wake/wake.c Mon Jan 4 11:34:39 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: wake.c,v 1.10 2010/01/03 17:58:14 mbalmer Exp $ */
+/* $NetBSD: wake.c,v 1.11 2010/01/04 11:34:39 mbalmer Exp $ */
/*
* Copyright (C) 2006, 2007, 2008, 2009, 2010 Marc Balmer <[email protected]>
@@ -117,6 +117,7 @@
{
struct ifaddrs *ifap, *ifa;
struct sockaddr_dl *sdl = NULL;
+ int nifs;
if (dst == NULL || len == 0)
return 0;
@@ -125,18 +126,18 @@
return -1;
/* XXX also check the link state */
- for (ifa = ifap; ifa; ifa = ifa->ifa_next)
+ for (nifs = 0, ifa = ifap; ifa; ifa = ifa->ifa_next)
if (ifa->ifa_addr->sa_family == AF_LINK &&
ifa->ifa_flags & IFF_UP && ifa->ifa_flags & IFF_RUNNING) {
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
if (sdl->sdl_type == IFT_ETHER) {
strlcpy(dst, ifa->ifa_name, len);
- break;
+ nifs++;
}
}
freeifaddrs(ifap);
- return 0;
+ return nifs == 1 ? 0 : -1;
}
static int