Blame SOURCES/ether-wake-interfaces.patch

612949
--- a/ether-wake.c	2013-09-03 18:15:13.000000000 +0200
612949
+++ b/ether-wake.c	2013-09-03 17:39:02.000000000 +0200
612949
@@ -22,7 +22,7 @@
612949
 "	Options:\n"
612949
 "		-b	Send wake-up packet to the broadcast address.\n"
612949
 "		-D	Increase the debug level.\n"
612949
-"		-i ifname	Use interface IFNAME instead of the default 'eth0'.\n"
612949
+"		-i ifname	Use interface ifname instead of sending a wake packet to all interfaces.\n"
612949
 "		-p <pw>		Append the four or six byte password PW to the packet.\n"
612949
 "					A password is only required for a few adapter types.\n"
612949
 "					The password may be specified in ethernet hex format\n"
612949
@@ -89,6 +89,9 @@
612949
 #include <netdb.h>
612949
 #include <netinet/ether.h>
612949
 
612949
+#include "interface.h"
612949
+#include "sockets.h"
612949
+
612949
 /* Grrr, no consistency between include versions.
612949
    Enable this if setsockopt() isn't declared with your library. */
612949
 #if 0
612949
@@ -110,20 +113,29 @@
612949
 static int get_fill(unsigned char *pkt, struct ether_addr *eaddr);
612949
 static int get_wol_pw(const char *optarg);
612949
 
612949
+typedef struct {
612949
+	int s;
612949
+	int verbose;
612949
+	int pktsize;
612949
+} if_info;
612949
+
612949
+static int send_wol_packet(char *ifname, int s, int verbose, int pktsize);
612949
+
612949
+static int do_wake(struct interface *ife, void *cookie) {
612949
+	if_info *info = (if_info *)cookie;
612949
+	send_wol_packet(ife->name, info->s, info->verbose, info->pktsize);
612949
+	return 0;
612949
+}
612949
+
612949
 int main(int argc, char *argv[])
612949
 {
612949
-	char *ifname = "eth0";
612949
-	int one = 1;				/* True, for socket options. */
612949
+	char *ifname = NULL;
612949
 	int s;						/* Raw socket */
612949
 	int errflag = 0, verbose = 0, do_version = 0;
612949
 	int perm_failure = 0;
612949
-	int i, c, pktsize;
612949
-#if defined(PF_PACKET)
612949
-	struct sockaddr_ll whereto;
612949
-#else
612949
-	struct sockaddr whereto;	/* who to wake up */
612949
-#endif
612949
+	int c, pktsize;
612949
 	struct ether_addr eaddr;
612949
+	if_info info;
612949
 
612949
 	while ((c = getopt(argc, argv, "bDi:p:uvV")) != -1)
612949
 		switch (c) {
612949
@@ -177,13 +189,45 @@
612949
 
612949
 	pktsize = get_fill(outpack, &eaddr);
612949
 
612949
+	if (ifname == NULL) {
612949
+		info.s = s;
612949
+		info.verbose = verbose;
612949
+		info.pktsize = pktsize;
612949
+
612949
+		/* Create a channel to the NET kernel. */
612949
+		if ((sockets_open(0)) < 0) {
612949
+			perror("socket");
612949
+			exit(1);
612949
+		}
612949
+
612949
+		return for_all_interfaces(do_wake, &info;;
612949
+	}
612949
+
612949
+	return send_wol_packet(ifname, s, verbose, pktsize);
612949
+}
612949
+
612949
+/* Send a Wake-On-LAN (WOL) "Magic Packet" to Interface IFNAME using
612949
+   Socket S with a packet size PKTSIZE.  VERBOSE implies
612949
+   verbosity.  */
612949
+
612949
+static int send_wol_packet(char *ifname, int s, int verbose, int pktsize)
612949
+{
612949
+	int i;
612949
+	int one = 1;				/* True, for socket options. */
612949
+#if defined(PF_PACKET)
612949
+	struct sockaddr_ll whereto;
612949
+#else
612949
+	struct sockaddr whereto;	/* who to wake up */
612949
+#endif
612949
+
612949
 	/* Fill in the source address, if possible.
612949
 	   The code to retrieve the local station address is Linux specific. */
612949
 	if (! opt_no_src_addr) {
612949
 		struct ifreq if_hwaddr;
612949
-		unsigned char *hwaddr = if_hwaddr.ifr_hwaddr.sa_data;
612949
+		char *hwaddr = if_hwaddr.ifr_hwaddr.sa_data;
612949
 
612949
-		strcpy(if_hwaddr.ifr_name, ifname);
612949
+		strncpy(if_hwaddr.ifr_name, ifname, IFNAMSIZ);
612949
+		if_hwaddr.ifr_name[IFNAMSIZ-1] = '\0';
612949
 		if (ioctl(s, SIOCGIFHWADDR, &if_hwaddr) < 0) {
612949
 			fprintf(stderr, "SIOCGIFHWADDR on %s failed: %s\n", ifname,
612949
 					strerror(errno));
612949
@@ -220,7 +264,8 @@
612949
 #if defined(PF_PACKET)
612949
 	{
612949
 		struct ifreq ifr;
612949
-		strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
612949
+		strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
612949
+		ifr.ifr_name[IFNAMSIZ-1] = '\0';
612949
 		if (ioctl(s, SIOCGIFINDEX, &ifr) == -1) {
612949
 			fprintf(stderr, "SIOCGIFINDEX on %s failed: %s\n", ifname,
612949
 					strerror(errno));
612949
--- a/Makefile	2013-09-03 13:15:22.531951613 +0100
612949
+++ b/Makefile	2013-09-03 13:24:29.659823455 +0100
612949
@@ -188,6 +188,8 @@ 
612949
 mii-tool:	$(NET_LIB) mii-tool.o
612949
 		$(CC) $(CFLAGS) $(LDFLAGS) -o $@ mii-tool.o $(NLIB) $(RESLIB)
612949
 
612949
+ether-wake:	$(NET_LIB) ether-wake.o
612949
+		$(CC) $(LDFLAGS) -o ether-wake ether-wake.o $(NLIB)
612949
 installbin:
612949
 	@echo
612949
 	@echo "######################################################"
612949
--- a/man/en_US/ether-wake.8	2013-09-03 13:15:22.576952098 +0100
612949
+++ b/man/en_US/ether-wake.8	2013-09-03 13:14:55.270657575 +0100
612949
@@ -49,7 +49,7 @@ 
612949
 Increase the Debug Level.
612949
 .TP
612949
 .B \-i ifname
612949
-Use interface ifname instead of the default "eth0".
612949
+Use interface ifname instead of sending a wake packet to all interfaces.
612949
 .TP
612949
 .B \-p passwd
612949
 Append a four or six byte password to the packet. Only a few adapters