diff options
author | June McEnroe <programble@gmail.com> | 2017-09-06 14:01:48 -0400 |
---|---|---|
committer | June McEnroe <programble@gmail.com> | 2017-09-06 14:01:48 -0400 |
commit | f77fae1335c562b720c4a6d4aa710f8627eaaff6 (patch) | |
tree | d027fc65a47a79db548ef797d95539952b17ba42 /bin/wake.c | |
parent | Rename curtis -> home (diff) | |
download | src-f77fae1335c562b720c4a6d4aa710f8627eaaff6.tar.gz src-f77fae1335c562b720c4a6d4aa710f8627eaaff6.zip |
Move C code to bin, Makefile, AGPL
Diffstat (limited to 'bin/wake.c')
-rw-r--r-- | bin/wake.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/bin/wake.c b/bin/wake.c new file mode 100644 index 00000000..42b3022f --- /dev/null +++ b/bin/wake.c @@ -0,0 +1,55 @@ +/* Wake-on-LAN. + * + * Copyright (c) 2017, Curtis McEnroe <programble@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <err.h> +#include <netinet/in.h> +#include <stdint.h> +#include <stdlib.h> +#include <sys/socket.h> +#include <sysexits.h> + +#define MAC 0x04, 0x7D, 0x7B, 0xD5, 0x6A, 0x53 + +const uint8_t payload[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC, + MAC, MAC, MAC, MAC, MAC, MAC, MAC, MAC, +}; + +int main() { + int sock = socket(PF_INET, SOCK_DGRAM, 0); + if (sock < 0) err(EX_OSERR, "socket"); + + int on = 1; + int error = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)); + if (error) err(EX_OSERR, "setsockopt"); + + struct sockaddr_in addr = { + .sin_family = AF_INET, + .sin_port = 9, + .sin_addr.s_addr = INADDR_BROADCAST, + }; + + ssize_t len = sendto( + sock, payload, sizeof(payload), 0, + (struct sockaddr *)&addr, sizeof(addr) + ); + if (len < 0) err(EX_IOERR, "sendto"); + + return EX_OK; +} |