diff --git a/usr.sbin/wake/wake.8 b/usr.sbin/wake/wake.8 index a837ca644afb..dcce06439f67 100644 --- a/usr.sbin/wake/wake.8 +++ b/usr.sbin/wake/wake.8 @@ -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 .\" @@ -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 @@ WoL functionality is generally enabled in a machine's BIOS 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 diff --git a/usr.sbin/wake/wake.c b/usr.sbin/wake/wake.c index 4cc1b109d135..49f0f741e923 100644 --- a/usr.sbin/wake/wake.c +++ b/usr.sbin/wake/wake.c @@ -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 @@ -117,6 +117,7 @@ find_ether(char *dst, size_t len) { struct ifaddrs *ifap, *ifa; struct sockaddr_dl *sdl = NULL; + int nifs; if (dst == NULL || len == 0) return 0; @@ -125,18 +126,18 @@ find_ether(char *dst, size_t len) 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