The repository formerly known as dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wake.c 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Copyright (c) 2017, Curtis McEnroe <programble@gmail.com>
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU Affero General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <sys/types.h>
  17. #include <err.h>
  18. #include <netinet/in.h>
  19. #include <stdlib.h>
  20. #include <sys/socket.h>
  21. #include <sysexits.h>
  22. typedef unsigned char byte;
  23. #define MAC 0x04, 0x7D, 0x7B, 0xD5, 0x6A, 0x53
  24. static const byte Payload[102] = {
  25. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  26. MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC,
  27. MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC,
  28. };
  29. int main() {
  30. int sock = socket(PF_INET, SOCK_DGRAM, 0);
  31. if (sock < 0) err(EX_OSERR, "socket");
  32. int on = 1;
  33. int error = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));
  34. if (error) err(EX_OSERR, "setsockopt");
  35. struct sockaddr_in addr = {
  36. .sin_family = AF_INET,
  37. .sin_port = 9,
  38. .sin_addr.s_addr = INADDR_BROADCAST,
  39. };
  40. ssize_t size = sendto(
  41. sock, Payload, sizeof(Payload), 0,
  42. (struct sockaddr *)&addr, sizeof(addr)
  43. );
  44. if (size < 0) err(EX_IOERR, "sendto");
  45. return EX_OK;
  46. }