2 * Send Network SysRq Packet
4 * (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
11 #include <netinet/in.h>
19 int main(int argc, char **argv)
25 struct sockaddr_in sa;
27 bzero(&sp, sizeof(sp));
29 if (argc != 3 && argc != 4) {
30 fprintf(stderr, "Usage: netrq <machine> <cmd> [<passwd>]\n");
34 if (! (h = gethostbyname(argv[1]))) {
35 fprintf(stderr, "Unable to resolve machine name: %m\n");
38 if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
39 fprintf(stderr, "socket: %m\n");
42 sa.sin_family = AF_INET;
43 memcpy(&sa.sin_addr.s_addr, h->h_addr, sizeof(struct in_addr));
44 sa.sin_port = htons(555);
45 if (connect(s, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
46 fprintf(stderr, "connect: %m\n");
53 p = getpass("Enter password: ");
55 fprintf(stderr, "Password is too long!\n");
58 strcpy(sp.password, p);
59 sp.command = argv[2][0];
61 if (write(s, &sp, sizeof(sp)) != sizeof(sp)) {
62 fprintf(stderr, "write: %m\n");