Blame SOURCES/ether-wake-interfaces.patch

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