add spamnet (for spamming a network server with garbage)
authorJann Horn <jann@thejh.net>
Thu, 27 Mar 2014 18:45:28 +0000 (19:45 +0100)
committerJann Horn <jann@thejh.net>
Thu, 27 Mar 2014 18:45:28 +0000 (19:45 +0100)
tools/spamnet.c [new file with mode: 0644]

diff --git a/tools/spamnet.c b/tools/spamnet.c
new file mode 100644 (file)
index 0000000..29de7e5
--- /dev/null
@@ -0,0 +1,27 @@
+#include <jh.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+  if (argc != 4) xperror("invocation: <host> <port> <spamstr>", 0);
+  int s = netopen(argv[1], argv[2], JH_TCP_HINTS);
+  if (s < 0) {
+    fprintf(stderr, "unable to connect: %s\n", gai_strerror(s));
+    exit(1);
+  }
+  char *buf = argv[3];
+  ssize_t len = strlen(buf);
+  ssize_t total = 0;
+  while (1) {
+    ssize_t wcount = fail_on_neg(write(s, buf, len), "write failed", 1);
+    if (wcount == 0) {
+      fprintf(stderr, "zero write! ending.\n");
+      return 1;
+    }
+    if (wcount != len) {
+      fprintf(stderr, "wrong write size! ending.\n");
+      return 1;
+    }
+    total += wcount;
+    fprintf(stderr, "%zd\n", total);
+  }
+}