From 0373077aae7770258b030ae2e4a20a68c5334d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jarom=C3=ADr=20Kon=C4=8Dick=C3=BD?= Date: Wed, 4 Sep 2013 11:51:24 +0200 Subject: [PATCH] use all interfaces instead of default (#1003875) --- ether-wake-interfaces.patch | 152 ++++++++++++++++++++++++++++++++++++ ether-wake.c | 19 ++--- net-tools.spec | 15 +++- 3 files changed, 171 insertions(+), 15 deletions(-) create mode 100644 ether-wake-interfaces.patch diff --git a/ether-wake-interfaces.patch b/ether-wake-interfaces.patch new file mode 100644 index 0000000..9c5a1d9 --- /dev/null +++ b/ether-wake-interfaces.patch @@ -0,0 +1,152 @@ +--- a/ether-wake.c 2013-09-03 18:15:13.000000000 +0200 ++++ b/ether-wake.c 2013-09-03 17:39:02.000000000 +0200 +@@ -3,10 +3,10 @@ + static char version_msg[] = + "ether-wake.c: v1.09 11/12/2003 Donald Becker, http://www.scyld.com/"; + static char brief_usage_msg[] = +-"usage: ether-wake [-i ] [-p aa:bb:cc:dd[:ee:ff]] 00:11:22:33:44:55\n" ++"usage: ether-wake -i [-p aa:bb:cc:dd[:ee:ff]] 00:11:22:33:44:55\n" + " Use '-u' to see the complete set of options.\n"; + static char usage_msg[] = +-"usage: ether-wake [-i ] [-p aa:bb:cc:dd[:ee:ff]] 00:11:22:33:44:55\n" ++"usage: ether-wake -i [-p aa:bb:cc:dd[:ee:ff]] 00:11:22:33:44:55\n" + "\n" + " This program generates and transmits a Wake-On-LAN (WOL)\n" + " \"Magic Packet\", used for restarting machines that have been\n" +@@ -22,7 +22,7 @@ + " Options:\n" + " -b Send wake-up packet to the broadcast address.\n" + " -D Increase the debug level.\n" +-" -i ifname Use interface IFNAME instead of the default 'eth0'.\n" ++" -i ifname Use interface IFNAME.\n" + " -p Append the four or six byte password PW to the packet.\n" + " A password is only required for a few adapter types.\n" + " The password may be specified in ethernet hex format\n" +@@ -89,6 +89,9 @@ + #include + #include + ++#include "interface.h" ++#include "sockets.h" ++ + /* Grrr, no consistency between include versions. + Enable this if setsockopt() isn't declared with your library. */ + #if 0 +@@ -110,20 +113,29 @@ + static int get_fill(unsigned char *pkt, struct ether_addr *eaddr); + static int get_wol_pw(const char *optarg); + ++typedef struct { ++ int s; ++ int verbose; ++ int pktsize; ++} if_info; ++ ++static int send_wol_packet(char *ifname, int s, int verbose, int pktsize); ++ ++static int do_wake(struct interface *ife, void *cookie) { ++ if_info *info = (if_info *)cookie; ++ send_wol_packet(ife->name, info->s, info->verbose, info->pktsize); ++ return 0; ++} ++ + int main(int argc, char *argv[]) + { +- char *ifname = "eth0"; +- int one = 1; /* True, for socket options. */ ++ char *ifname = NULL; + int s; /* Raw socket */ + int errflag = 0, verbose = 0, do_version = 0; + int perm_failure = 0; +- int i, c, pktsize; +-#if defined(PF_PACKET) +- struct sockaddr_ll whereto; +-#else +- struct sockaddr whereto; /* who to wake up */ +-#endif ++ int c, pktsize; + struct ether_addr eaddr; ++ if_info info; + + while ((c = getopt(argc, argv, "bDi:p:uvV")) != -1) + switch (c) { +@@ -177,13 +189,45 @@ + + pktsize = get_fill(outpack, &eaddr); + ++ if (ifname == NULL) { ++ info.s = s; ++ info.verbose = verbose; ++ info.pktsize = pktsize; ++ ++ /* Create a channel to the NET kernel. */ ++ if ((sockets_open(0)) < 0) { ++ perror("socket"); ++ exit(1); ++ } ++ ++ return for_all_interfaces(do_wake, &info); ++ } ++ ++ return send_wol_packet(ifname, s, verbose, pktsize); ++} ++ ++/* Send a Wake-On-LAN (WOL) "Magic Packet" to Interface IFNAME using ++ Socket S with a packet size PKTSIZE. VERBOSE implies ++ verbosity. */ ++ ++static int send_wol_packet(char *ifname, int s, int verbose, int pktsize) ++{ ++ int i; ++ int one = 1; /* True, for socket options. */ ++#if defined(PF_PACKET) ++ struct sockaddr_ll whereto; ++#else ++ struct sockaddr whereto; /* who to wake up */ ++#endif ++ + /* Fill in the source address, if possible. + The code to retrieve the local station address is Linux specific. */ + if (! opt_no_src_addr) { + struct ifreq if_hwaddr; +- unsigned char *hwaddr = if_hwaddr.ifr_hwaddr.sa_data; ++ char *hwaddr = if_hwaddr.ifr_hwaddr.sa_data; + +- strcpy(if_hwaddr.ifr_name, ifname); ++ strncpy(if_hwaddr.ifr_name, ifname, IFNAMSIZ); ++ if_hwaddr.ifr_name[IFNAMSIZ-1] = '\0'; + if (ioctl(s, SIOCGIFHWADDR, &if_hwaddr) < 0) { + fprintf(stderr, "SIOCGIFHWADDR on %s failed: %s\n", ifname, + strerror(errno)); +@@ -220,7 +264,8 @@ + #if defined(PF_PACKET) + { + struct ifreq ifr; +- strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); ++ strncpy(ifr.ifr_name, ifname, IFNAMSIZ); ++ ifr.ifr_name[IFNAMSIZ-1] = '\0'; + if (ioctl(s, SIOCGIFINDEX, &ifr) == -1) { + fprintf(stderr, "SIOCGIFINDEX on %s failed: %s\n", ifname, + strerror(errno)); +--- a/Makefile 2013-09-03 13:15:22.531951613 +0100 ++++ b/Makefile 2013-09-03 13:24:29.659823455 +0100 +@@ -188,6 +188,8 @@ + mii-tool: $(NET_LIB) mii-tool.o + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ mii-tool.o $(NLIB) $(RESLIB) + ++ether-wake: $(NET_LIB) ether-wake.o ++ $(CC) $(LDFLAGS) -o ether-wake ether-wake.o $(NLIB) + installbin: + @echo + @echo "######################################################" +--- a/man/en_US/ether-wake.8 2013-09-03 13:15:22.576952098 +0100 ++++ b/man/en_US/ether-wake.8 2013-09-03 13:14:55.270657575 +0100 +@@ -49,7 +49,7 @@ + Increase the Debug Level. + .TP + .B \-i ifname +-Use interface ifname instead of the default "eth0". ++Use interface ifname instead of sending a wake packet to all interfaces. + .TP + .B \-p passwd + Append a four or six byte password to the packet. Only a few adapters diff --git a/ether-wake.c b/ether-wake.c index 82ede31..eef22a7 100644 --- a/ether-wake.c +++ b/ether-wake.c @@ -3,10 +3,10 @@ static char version_msg[] = "ether-wake.c: v1.09 11/12/2003 Donald Becker, http://www.scyld.com/"; static char brief_usage_msg[] = -"usage: ether-wake -i [-p aa:bb:cc:dd[:ee:ff]] 00:11:22:33:44:55\n" +"usage: ether-wake [-i ] [-p aa:bb:cc:dd[:ee:ff]] 00:11:22:33:44:55\n" " Use '-u' to see the complete set of options.\n"; static char usage_msg[] = -"usage: ether-wake -i [-p aa:bb:cc:dd[:ee:ff]] 00:11:22:33:44:55\n" +"usage: ether-wake [-i ] [-p aa:bb:cc:dd[:ee:ff]] 00:11:22:33:44:55\n" "\n" " This program generates and transmits a Wake-On-LAN (WOL)\n" " \"Magic Packet\", used for restarting machines that have been\n" @@ -22,7 +22,7 @@ static char usage_msg[] = " Options:\n" " -b Send wake-up packet to the broadcast address.\n" " -D Increase the debug level.\n" -" -i ifname Use interface IFNAME.\n" +" -i ifname Use interface IFNAME instead of the default 'eth0'.\n" " -p Append the four or six byte password PW to the packet.\n" " A password is only required for a few adapter types.\n" " The password may be specified in ethernet hex format\n" @@ -112,7 +112,7 @@ static int get_wol_pw(const char *optarg); int main(int argc, char *argv[]) { - char *ifname = NULL; + char *ifname = "eth0"; int one = 1; /* True, for socket options. */ int s; /* Raw socket */ int errflag = 0, verbose = 0, do_version = 0; @@ -144,11 +144,6 @@ int main(int argc, char *argv[]) return 3; } - if (ifname == NULL) { - fprintf(stderr, "Specify -i .\n"); - return 3; - } - if (optind == argc) { fprintf(stderr, "Specify the Ethernet address as 00:11:22:33:44:55.\n"); return 3; @@ -188,8 +183,7 @@ int main(int argc, char *argv[]) struct ifreq if_hwaddr; unsigned char *hwaddr = if_hwaddr.ifr_hwaddr.sa_data; - strncpy(if_hwaddr.ifr_name, ifname, IFNAMSIZ); - if_hwaddr.ifr_name[IFNAMSIZ-1] = '\0'; + strcpy(if_hwaddr.ifr_name, ifname); if (ioctl(s, SIOCGIFHWADDR, &if_hwaddr) < 0) { fprintf(stderr, "SIOCGIFHWADDR on %s failed: %s\n", ifname, strerror(errno)); @@ -226,8 +220,7 @@ int main(int argc, char *argv[]) #if defined(PF_PACKET) { struct ifreq ifr; - strncpy(ifr.ifr_name, ifname, IFNAMSIZ); - ifr.ifr_name[IFNAMSIZ-1] = '\0'; + strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCGIFINDEX, &ifr) == -1) { fprintf(stderr, "SIOCGIFINDEX on %s failed: %s\n", ifname, strerror(errno)); diff --git a/net-tools.spec b/net-tools.spec index b05116c..32c9efa 100644 --- a/net-tools.spec +++ b/net-tools.spec @@ -3,7 +3,7 @@ Summary: Basic networking tools Name: net-tools Version: 2.0 -Release: 0.9.%{checkout}%{?dist} +Release: 0.10.%{checkout}%{?dist} License: GPLv2+ Group: System Environment/Base URL: http://sourceforge.net/projects/net-tools/ @@ -53,6 +53,9 @@ Patch10: net-tools-ifconfig-long-iface-crasher.patch # fixed tcp timers info in netstat (#466845) Patch11: net-tools-netstat-probe.patch +# use all interfaces instead of default (#1003875) +Patch20: ether-wake-interfaces.patch + BuildRequires: gettext, libselinux BuildRequires: libselinux-devel BuildRequires: systemd-units @@ -86,10 +89,14 @@ cp %SOURCE6 ./man/en_US cp %SOURCE7 ./man/en_US cp %SOURCE8 ./man/en_US +%patch20 -p1 -b .interfaces + %ifarch alpha perl -pi -e "s|-O2||" Makefile %endif +touch ./config.h + %build # Sparc and s390 arches need to use -fPIE %ifarch sparcv9 sparc64 s390 s390x @@ -101,7 +108,7 @@ export CFLAGS="$RPM_OPT_FLAGS $CFLAGS -fpie" export LDFLAGS="$LDFLAGS -pie -Wl,-z,relro -Wl,-z,now" make -gcc $RPM_OPT_FLAGS -o ether-wake ether-wake.c +make ether-wake gcc $RPM_OPT_FLAGS -o mii-diag mii-diag.c %install @@ -163,6 +170,10 @@ install -m 644 %{SOURCE9} %{buildroot}%{_unitdir} %attr(0644,root,root) %{_unitdir}/arp-ethers.service %changelog +* Wed Sep 04 2013 Jaromír Končický - 2.0-0.10.20130607git +- use all interfaces instead of default (#1003875) +- reverted all changes on ether-wake.c and put original file + * Sat Aug 03 2013 Fedora Release Engineering - 2.0-0.9.20130607git - Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild