Bernhard Reutner-Fischer | dac7ff1 | 2006-04-12 17:55:51 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 2 | /* |
| 3 | * ether-wake.c - Send a magic packet to wake up sleeping machines. |
| 4 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 5 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 6 | * |
| 7 | * Author: Donald Becker, http://www.scyld.com/"; http://www.scyld.com/wakeonlan.html |
| 8 | * Busybox port: Christian Volkmann <haveaniceday@online.de> |
| 9 | * Used version of ether-wake.c: v1.09 11/12/2003 Donald Becker, http://www.scyld.com/"; |
| 10 | */ |
| 11 | |
| 12 | /* full usage according Donald Becker |
| 13 | * usage: ether-wake [-i <ifname>] [-p aa:bb:cc:dd[:ee:ff]] 00:11:22:33:44:55\n" |
| 14 | * |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 15 | * This program generates and transmits a Wake-On-LAN (WOL)\n" |
| 16 | * \"Magic Packet\", used for restarting machines that have been\n" |
| 17 | * soft-powered-down (ACPI D3-warm state).\n" |
| 18 | * It currently generates the standard AMD Magic Packet format, with\n" |
| 19 | * an optional password appended.\n" |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 20 | * |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 21 | * The single required parameter is the Ethernet MAC (station) address\n" |
| 22 | * of the machine to wake or a host ID with known NSS 'ethers' entry.\n" |
| 23 | * The MAC address may be found with the 'arp' program while the target\n" |
| 24 | * machine is awake.\n" |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 25 | * |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 26 | * Options:\n" |
| 27 | * -b Send wake-up packet to the broadcast address.\n" |
| 28 | * -D Increase the debug level.\n" |
| 29 | * -i ifname Use interface IFNAME instead of the default 'eth0'.\n" |
| 30 | * -p <pw> Append the four or six byte password PW to the packet.\n" |
| 31 | * A password is only required for a few adapter types.\n" |
| 32 | * The password may be specified in ethernet hex format\n" |
| 33 | * or dotted decimal (Internet address)\n" |
| 34 | * -p 00:22:44:66:88:aa\n" |
| 35 | * -p 192.168.1.1\n"; |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 36 | * |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 37 | * |
| 38 | * This program generates and transmits a Wake-On-LAN (WOL) "Magic Packet", |
| 39 | * used for restarting machines that have been soft-powered-down |
| 40 | * (ACPI D3-warm state). It currently generates the standard AMD Magic Packet |
| 41 | * format, with an optional password appended. |
| 42 | * |
| 43 | * This software may be used and distributed according to the terms |
| 44 | * of the GNU Public License, incorporated herein by reference. |
| 45 | * Contact the author for use under other terms. |
| 46 | * |
| 47 | * This source file was originally part of the network tricks package, and |
| 48 | * is now distributed to support the Scyld Beowulf system. |
| 49 | * Copyright 1999-2003 Donald Becker and Scyld Computing Corporation. |
| 50 | * |
| 51 | * The author may be reached as becker@scyld, or C/O |
Denys Vlasenko | 60cb48c | 2013-01-14 15:57:44 +0100 | [diff] [blame] | 52 | * Scyld Computing Corporation |
| 53 | * 914 Bay Ridge Road, Suite 220 |
| 54 | * Annapolis MD 21403 |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 55 | * |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 56 | * Notes: |
| 57 | * On some systems dropping root capability allows the process to be |
| 58 | * dumped, traced or debugged. |
| 59 | * If someone traces this program, they get control of a raw socket. |
| 60 | * Linux handles this safely, but beware when porting this program. |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 61 | * |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 62 | * An alternative to needing 'root' is using a UDP broadcast socket, however |
| 63 | * doing so only works with adapters configured for unicast+broadcast Rx |
| 64 | * filter. That configuration consumes more power. |
Denys Vlasenko | eba5fae | 2013-10-14 19:04:20 +0200 | [diff] [blame] | 65 | */ |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 66 | //config:config ETHER_WAKE |
Denys Vlasenko | b097a84 | 2018-12-28 03:20:17 +0100 | [diff] [blame] | 67 | //config: bool "ether-wake (4.9 kb)" |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 68 | //config: default y |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 69 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 70 | //config: Send a magic packet to wake up sleeping machines. |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 71 | |
| 72 | //applet:IF_ETHER_WAKE(APPLET_ODDNAME(ether-wake, ether_wake, BB_DIR_USR_SBIN, BB_SUID_DROP, ether_wake)) |
| 73 | |
| 74 | //kbuild:lib-$(CONFIG_ETHER_WAKE) += ether-wake.o |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 75 | |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 76 | //usage:#define ether_wake_trivial_usage |
Denys Vlasenko | eba5fae | 2013-10-14 19:04:20 +0200 | [diff] [blame] | 77 | //usage: "[-b] [-i IFACE] [-p aa:bb:cc:dd[:ee:ff]/a.b.c.d] MAC" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 78 | //usage:#define ether_wake_full_usage "\n\n" |
| 79 | //usage: "Send a magic packet to wake up sleeping machines.\n" |
| 80 | //usage: "MAC must be a station address (00:11:22:33:44:55) or\n" |
| 81 | //usage: "a hostname with a known 'ethers' entry.\n" |
Denys Vlasenko | eba5fae | 2013-10-14 19:04:20 +0200 | [diff] [blame] | 82 | //usage: "\n -b Broadcast the packet" |
| 83 | //usage: "\n -i IFACE Interface to use (default eth0)" |
| 84 | //usage: "\n -p PASSWORD Append four or six byte PASSWORD to the packet" |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 85 | |
Dan Fandrich | f533ec8 | 2011-06-10 05:17:59 +0200 | [diff] [blame] | 86 | #include "libbb.h" |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 87 | #include <netpacket/packet.h> |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 88 | #include <netinet/ether.h> |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 89 | #include <linux/if.h> |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 90 | |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 91 | /* Note: PF_INET, SOCK_DGRAM, IPPROTO_UDP would allow SIOCGIFHWADDR to |
| 92 | * work as non-root, but we need SOCK_PACKET to specify the Ethernet |
| 93 | * destination address. |
| 94 | */ |
| 95 | #ifdef PF_PACKET |
| 96 | # define whereto_t sockaddr_ll |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 97 | # define make_socket() xsocket(PF_PACKET, SOCK_RAW, 0) |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 98 | #else |
| 99 | # define whereto_t sockaddr |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 100 | # define make_socket() xsocket(AF_INET, SOCK_PACKET, SOCK_PACKET) |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 101 | #endif |
| 102 | |
| 103 | #ifdef DEBUG |
| 104 | # define bb_debug_msg(fmt, args...) fprintf(stderr, fmt, ## args) |
| 105 | void bb_debug_dump_packet(unsigned char *outpack, int pktsize) |
| 106 | { |
| 107 | int i; |
| 108 | printf("packet dump:\n"); |
| 109 | for (i = 0; i < pktsize; ++i) { |
| 110 | printf("%2.2x ", outpack[i]); |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 111 | if (i % 20 == 19) bb_putchar('\n'); |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 112 | } |
| 113 | printf("\n\n"); |
| 114 | } |
| 115 | #else |
Denis Vlasenko | 198714c | 2007-04-16 23:16:37 +0000 | [diff] [blame] | 116 | # define bb_debug_msg(fmt, args...) ((void)0) |
| 117 | # define bb_debug_dump_packet(outpack, pktsize) ((void)0) |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 118 | #endif |
| 119 | |
Denis Vlasenko | 198714c | 2007-04-16 23:16:37 +0000 | [diff] [blame] | 120 | /* Convert the host ID string to a MAC address. |
| 121 | * The string may be a: |
| 122 | * Host name |
| 123 | * IP address string |
| 124 | * MAC address string |
Denys Vlasenko | 60cb48c | 2013-01-14 15:57:44 +0100 | [diff] [blame] | 125 | */ |
Denis Vlasenko | 198714c | 2007-04-16 23:16:37 +0000 | [diff] [blame] | 126 | static void get_dest_addr(const char *hostid, struct ether_addr *eaddr) |
| 127 | { |
| 128 | struct ether_addr *eap; |
| 129 | |
Denys Vlasenko | 37a658c | 2010-03-23 15:43:08 +0100 | [diff] [blame] | 130 | eap = ether_aton_r(hostid, eaddr); |
Denis Vlasenko | 198714c | 2007-04-16 23:16:37 +0000 | [diff] [blame] | 131 | if (eap) { |
Denys Vlasenko | 37a658c | 2010-03-23 15:43:08 +0100 | [diff] [blame] | 132 | bb_debug_msg("The target station address is %s\n\n", ether_ntoa(eap)); |
Mike Frysinger | 445e754 | 2013-03-12 11:13:22 -0400 | [diff] [blame] | 133 | #if !defined(__UCLIBC__) || UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30) |
Denis Vlasenko | 198714c | 2007-04-16 23:16:37 +0000 | [diff] [blame] | 134 | } else if (ether_hostton(hostid, eaddr) == 0) { |
| 135 | bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa(eaddr)); |
| 136 | #endif |
Denys Vlasenko | 37a658c | 2010-03-23 15:43:08 +0100 | [diff] [blame] | 137 | } else { |
Denis Vlasenko | 198714c | 2007-04-16 23:16:37 +0000 | [diff] [blame] | 138 | bb_show_usage(); |
Denys Vlasenko | 37a658c | 2010-03-23 15:43:08 +0100 | [diff] [blame] | 139 | } |
Denis Vlasenko | 198714c | 2007-04-16 23:16:37 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Denys Vlasenko | eba5fae | 2013-10-14 19:04:20 +0200 | [diff] [blame] | 142 | #define PKT_HEADER_SIZE (20 + 16*6) |
| 143 | static int fill_pkt_header(unsigned char *pkt, struct ether_addr *eaddr, int broadcast) |
Denis Vlasenko | 198714c | 2007-04-16 23:16:37 +0000 | [diff] [blame] | 144 | { |
| 145 | int i; |
| 146 | unsigned char *station_addr = eaddr->ether_addr_octet; |
| 147 | |
| 148 | memset(pkt, 0xff, 6); |
| 149 | if (!broadcast) |
| 150 | memcpy(pkt, station_addr, 6); |
| 151 | pkt += 6; |
| 152 | |
| 153 | memcpy(pkt, station_addr, 6); /* 6 */ |
| 154 | pkt += 6; |
| 155 | |
| 156 | *pkt++ = 0x08; /* 12 */ /* Or 0x0806 for ARP, 0x8035 for RARP */ |
| 157 | *pkt++ = 0x42; /* 13 */ |
| 158 | |
| 159 | memset(pkt, 0xff, 6); /* 14 */ |
| 160 | |
| 161 | for (i = 0; i < 16; ++i) { |
| 162 | pkt += 6; |
| 163 | memcpy(pkt, station_addr, 6); /* 20,26,32,... */ |
| 164 | } |
| 165 | |
Denys Vlasenko | eba5fae | 2013-10-14 19:04:20 +0200 | [diff] [blame] | 166 | return PKT_HEADER_SIZE; /* length of packet */ |
Denis Vlasenko | 198714c | 2007-04-16 23:16:37 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | static int get_wol_pw(const char *ethoptarg, unsigned char *wol_passwd) |
| 170 | { |
| 171 | unsigned passwd[6]; |
| 172 | int byte_cnt, i; |
| 173 | |
| 174 | /* handle MAC format */ |
| 175 | byte_cnt = sscanf(ethoptarg, "%2x:%2x:%2x:%2x:%2x:%2x", |
| 176 | &passwd[0], &passwd[1], &passwd[2], |
| 177 | &passwd[3], &passwd[4], &passwd[5]); |
| 178 | /* handle IP format */ |
| 179 | // FIXME: why < 4?? should it be < 6? |
| 180 | if (byte_cnt < 4) |
| 181 | byte_cnt = sscanf(ethoptarg, "%u.%u.%u.%u", |
| 182 | &passwd[0], &passwd[1], &passwd[2], &passwd[3]); |
| 183 | if (byte_cnt < 4) { |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 184 | bb_simple_error_msg("can't read Wake-On-LAN pass"); |
Denis Vlasenko | 198714c | 2007-04-16 23:16:37 +0000 | [diff] [blame] | 185 | return 0; |
| 186 | } |
| 187 | // TODO: check invalid numbers >255?? |
| 188 | for (i = 0; i < byte_cnt; ++i) |
| 189 | wol_passwd[i] = passwd[i]; |
| 190 | |
| 191 | bb_debug_msg("password: %2.2x %2.2x %2.2x %2.2x (%d)\n\n", |
| 192 | wol_passwd[0], wol_passwd[1], wol_passwd[2], wol_passwd[3], |
| 193 | byte_cnt); |
| 194 | |
| 195 | return byte_cnt; |
| 196 | } |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 197 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 198 | int ether_wake_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 199 | int ether_wake_main(int argc UNUSED_PARAM, char **argv) |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 200 | { |
Denis Vlasenko | 4c97863 | 2007-02-03 03:31:13 +0000 | [diff] [blame] | 201 | const char *ifname = "eth0"; |
Denis Vlasenko | 517d1aa | 2007-04-16 23:23:33 +0000 | [diff] [blame] | 202 | char *pass; |
Denis Vlasenko | 198714c | 2007-04-16 23:16:37 +0000 | [diff] [blame] | 203 | unsigned flags; |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 204 | unsigned char wol_passwd[6]; |
| 205 | int wol_passwd_sz = 0; |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 206 | int s; /* Raw socket */ |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 207 | int pktsize; |
Denys Vlasenko | eba5fae | 2013-10-14 19:04:20 +0200 | [diff] [blame] | 208 | unsigned char outpack[PKT_HEADER_SIZE + 6 /* max passwd size */ + 16 /* paranoia */]; |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 209 | |
| 210 | struct ether_addr eaddr; |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 211 | struct whereto_t whereto; /* who to wake up */ |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 212 | |
| 213 | /* handle misc user options */ |
Denys Vlasenko | 22542ec | 2017-08-08 21:55:02 +0200 | [diff] [blame] | 214 | flags = getopt32(argv, "^" "bi:p:" "\0" "=1", &ifname, &pass); |
Denis Vlasenko | 517d1aa | 2007-04-16 23:23:33 +0000 | [diff] [blame] | 215 | if (flags & 4) /* -p */ |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 216 | wol_passwd_sz = get_wol_pw(pass, wol_passwd); |
Denis Vlasenko | 517d1aa | 2007-04-16 23:23:33 +0000 | [diff] [blame] | 217 | flags &= 1; /* we further interested only in -b [bcast] flag */ |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 218 | |
| 219 | /* create the raw socket */ |
| 220 | s = make_socket(); |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 221 | |
| 222 | /* now that we have a raw socket we can drop root */ |
Denis Vlasenko | 517d1aa | 2007-04-16 23:23:33 +0000 | [diff] [blame] | 223 | /* xsetuid(getuid()); - but save on code size... */ |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 224 | |
| 225 | /* look up the dest mac address */ |
| 226 | get_dest_addr(argv[optind], &eaddr); |
| 227 | |
| 228 | /* fill out the header of the packet */ |
Denys Vlasenko | eba5fae | 2013-10-14 19:04:20 +0200 | [diff] [blame] | 229 | pktsize = fill_pkt_header(outpack, &eaddr, flags /* & 1 OPT_BROADCAST */); |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 230 | |
| 231 | bb_debug_dump_packet(outpack, pktsize); |
| 232 | |
| 233 | /* Fill in the source address, if possible. */ |
| 234 | #ifdef __linux__ |
| 235 | { |
| 236 | struct ifreq if_hwaddr; |
| 237 | |
Denis Vlasenko | 360d966 | 2008-12-02 18:18:50 +0000 | [diff] [blame] | 238 | strncpy_IFNAMSIZ(if_hwaddr.ifr_name, ifname); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 239 | ioctl_or_perror_and_die(s, SIOCGIFHWADDR, &if_hwaddr, "SIOCGIFHWADDR on %s failed", ifname); |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 240 | |
| 241 | memcpy(outpack+6, if_hwaddr.ifr_hwaddr.sa_data, 6); |
| 242 | |
| 243 | # ifdef DEBUG |
| 244 | { |
| 245 | unsigned char *hwaddr = if_hwaddr.ifr_hwaddr.sa_data; |
| 246 | printf("The hardware address (SIOCGIFHWADDR) of %s is type %d " |
Denys Vlasenko | 6967578 | 2013-01-14 01:34:48 +0100 | [diff] [blame] | 247 | "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n\n", ifname, |
| 248 | if_hwaddr.ifr_hwaddr.sa_family, hwaddr[0], hwaddr[1], |
| 249 | hwaddr[2], hwaddr[3], hwaddr[4], hwaddr[5]); |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 250 | } |
| 251 | # endif |
| 252 | } |
| 253 | #endif /* __linux__ */ |
| 254 | |
| 255 | bb_debug_dump_packet(outpack, pktsize); |
| 256 | |
| 257 | /* append the password if specified */ |
| 258 | if (wol_passwd_sz > 0) { |
| 259 | memcpy(outpack+pktsize, wol_passwd, wol_passwd_sz); |
| 260 | pktsize += wol_passwd_sz; |
| 261 | } |
| 262 | |
| 263 | bb_debug_dump_packet(outpack, pktsize); |
| 264 | |
| 265 | /* This is necessary for broadcasts to work */ |
Denis Vlasenko | 517d1aa | 2007-04-16 23:23:33 +0000 | [diff] [blame] | 266 | if (flags /* & 1 OPT_BROADCAST */) { |
Denis Vlasenko | 198714c | 2007-04-16 23:16:37 +0000 | [diff] [blame] | 267 | if (setsockopt_broadcast(s) != 0) |
James Byrne | 6937487 | 2019-07-02 11:35:03 +0200 | [diff] [blame] | 268 | bb_simple_perror_msg("SO_BROADCAST"); |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | #if defined(PF_PACKET) |
| 272 | { |
| 273 | struct ifreq ifr; |
Denis Vlasenko | 360d966 | 2008-12-02 18:18:50 +0000 | [diff] [blame] | 274 | strncpy_IFNAMSIZ(ifr.ifr_name, ifname); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 275 | xioctl(s, SIOCGIFINDEX, &ifr); |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 276 | memset(&whereto, 0, sizeof(whereto)); |
| 277 | whereto.sll_family = AF_PACKET; |
| 278 | whereto.sll_ifindex = ifr.ifr_ifindex; |
| 279 | /* The manual page incorrectly claims the address must be filled. |
| 280 | We do so because the code may change to match the docs. */ |
| 281 | whereto.sll_halen = ETH_ALEN; |
| 282 | memcpy(whereto.sll_addr, outpack, ETH_ALEN); |
| 283 | } |
| 284 | #else |
| 285 | whereto.sa_family = 0; |
| 286 | strcpy(whereto.sa_data, ifname); |
| 287 | #endif |
Bernhard Reutner-Fischer | b290889 | 2007-04-12 11:34:39 +0000 | [diff] [blame] | 288 | xsendto(s, outpack, pktsize, (struct sockaddr *)&whereto, sizeof(whereto)); |
Denis Vlasenko | 198714c | 2007-04-16 23:16:37 +0000 | [diff] [blame] | 289 | if (ENABLE_FEATURE_CLEAN_UP) |
| 290 | close(s); |
Mike Frysinger | b662f0d | 2005-05-11 03:59:53 +0000 | [diff] [blame] | 291 | return EXIT_SUCCESS; |
| 292 | } |