1 // Copyright (C) Jann Horn (2013)
2 // You can redistribute this code under the terms of the GPLv2 or GPLv3.
3 // THIS PROGRAM IS FOR EDUCATIONAL PURPOSES ONLY!
4 // I AM NOT RESPONSIBLE FOR WHAT YOU DO WITH THIS PROGRAM OR THE IMPACT THIS
5 // PROGRAM MIGHT HAVE ON YOUR SYSTEMS! YOU HAVE BEEN WARNED!
12 #include <sys/types.h>
20 if (pipe(pipefds)) perror("can't create pipe"), exit(1);
21 int parent_fd = pipefds[0];
22 int child_fd = pipefds[1];
25 if (pid < 0) perror("can't fork"), exit(1);
28 int nullfd = open("/dev/null", O_RDWR);
35 execlp("hping3", "hping3", "-c", "20", "-p", "80", "-i", "u100000", "--syn", target, NULL);
36 perror("can't exec"), exit(1);
41 int indata_written = 0;
43 while ((rres=read(parent_fd, indata+indata_written, 4095-indata_written)) > 0) {
44 indata_written += rres;
45 if (indata_written >= 4095) fputs("too much information", stderr), exit(1);
47 if (rres < 0) perror("failure reading from child"), exit(1);
48 indata[indata_written] = '\0';
54 while ((s=strstr(s, " id=")) != NULL) {
58 int diff = id - last_id;
59 if (diff < 0) diff += (256*256);
65 printf("%i %i\n", (int)time(NULL), sum);
68 int main(int argc, char **argv) {
69 if (argc != 2) fputs("bad invocation\n", stderr), exit(1);