Blame SOURCES/ether-wake-interfaces.patch

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