summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2018-07-23 15:48:44 +0200
committerTom Smeding <tom.smeding@gmail.com>2018-07-23 15:48:44 +0200
commit5722c47aa3402f1458da9eec332153a454a540b7 (patch)
treef1bfaa8c89dc39c6b9ae0bf7ff54eb524b1468eb /util.c
Initial version
Working ping back and forth with specified data, and data arrives at the other party. Currently, the server uses nflog to get the pings, which: 1. requires iptables settings to work; 2. buffers and collects messages for a second. Both are suboptimal, and I believe raw sockets can improve on this.
Diffstat (limited to 'util.c')
-rw-r--r--util.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..be7083c
--- /dev/null
+++ b/util.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <ctype.h>
+#include "util.h"
+
+
+void xxd(const void *buf_, size_t length) {
+ unsigned char *buf = (unsigned char*)buf_;
+
+ for (size_t cursor = 0; cursor < length;) {
+ printf("%08zx:", cursor);
+
+ for (int i = 0; i < 16; i++) {
+ if (i % 2 == 0) printf(" ");
+ if (i % 8 == 0) printf(" ");
+ if (cursor + i < length) printf("%02x", (unsigned)buf[cursor + i]);
+ else printf(" ");
+ }
+
+ printf(" |");
+
+ for (int i = 0; i < 16 && cursor + i < length; i++) {
+ if (isprint(buf[cursor + i])) printf("%c", buf[cursor + i]);
+ else printf(".");
+ }
+
+ printf("|\n");
+
+ cursor += 16;
+ }
+}