diff options
author | Marc <foxtrot@malloc.me> | 2021-11-30 22:39:26 +0000 |
---|---|---|
committer | Marc <foxtrot@malloc.me> | 2021-12-01 16:54:44 +0000 |
commit | ae6c98a48da409d040604aeffb84a38155fb5bac (patch) | |
tree | c27a8e28972209581ce3fba2130bf0c2b4f9c9c0 /test/src/helpers.c | |
download | libwifi-ae6c98a48da409d040604aeffb84a38155fb5bac.tar.gz libwifi-ae6c98a48da409d040604aeffb84a38155fb5bac.tar.bz2 libwifi-ae6c98a48da409d040604aeffb84a38155fb5bac.zip |
Initial Commit
Signed-off-by: Marc <foxtrot@malloc.me>
Diffstat (limited to 'test/src/helpers.c')
-rw-r--r-- | test/src/helpers.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/src/helpers.c b/test/src/helpers.c new file mode 100644 index 0000000..9fc9d0b --- /dev/null +++ b/test/src/helpers.c | |||
@@ -0,0 +1,31 @@ | |||
1 | #include "helpers.h" | ||
2 | #include <stdio.h> | ||
3 | |||
4 | void hexdump(void *data, size_t size) { | ||
5 | char ascii[17]; | ||
6 | size_t i, j; | ||
7 | ascii[16] = '\0'; | ||
8 | for (i = 0; i < size; ++i) { | ||
9 | printf("%02X ", ((unsigned char *) data)[i]); | ||
10 | if (((unsigned char *) data)[i] >= ' ' && ((unsigned char *) data)[i] <= '~') { | ||
11 | ascii[i % 16] = ((unsigned char *) data)[i]; | ||
12 | } else { | ||
13 | ascii[i % 16] = '.'; | ||
14 | } | ||
15 | if ((i + 1) % 8 == 0 || i + 1 == size) { | ||
16 | printf(" "); | ||
17 | if ((i + 1) % 16 == 0) { | ||
18 | printf("| %s \n", ascii); | ||
19 | } else if (i + 1 == size) { | ||
20 | ascii[(i + 1) % 16] = '\0'; | ||
21 | if ((i + 1) % 16 <= 8) { | ||
22 | printf(" "); | ||
23 | } | ||
24 | for (j = (i + 1) % 16; j < 16; ++j) { | ||
25 | printf(" "); | ||
26 | } | ||
27 | printf("| %s \n", ascii); | ||
28 | } | ||
29 | } | ||
30 | } | ||
31 | } | ||