diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2018-07-23 15:48:44 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2018-07-23 15:48:44 +0200 |
commit | 5722c47aa3402f1458da9eec332153a454a540b7 (patch) | |
tree | f1bfaa8c89dc39c6b9ae0bf7ff54eb524b1468eb /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.c | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -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; + } +} |