FreeCalypso > hg > freecalypso-tools
comparison rvinterf/libprint/hexdump.c @ 928:65953c172f24
rvinterf/lowlevel: new hex dump format
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 23 May 2023 05:23:19 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
927:4e243402f453 | 928:65953c172f24 |
---|---|
1 /* | |
2 * The function contained in this module implements hex dump functionality: | |
3 * an arbitrary binary packet is dumped in hex, line by line, calling an output | |
4 * function for each line. | |
5 */ | |
6 | |
7 #include <sys/types.h> | |
8 #include <stdio.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 | |
12 void | |
13 packet_hex_dump(src, srclen, outfunc) | |
14 u_char *src; | |
15 unsigned srclen; | |
16 void (*outfunc)(); | |
17 { | |
18 u_char *sp = src; | |
19 unsigned remain = srclen; | |
20 unsigned offset = 0; | |
21 unsigned chunk; | |
22 char line[80], *dp; | |
23 int i, c; | |
24 | |
25 while (remain) { | |
26 sprintf(line, "%04X: ", offset); | |
27 dp = line + 7; | |
28 chunk = remain; | |
29 if (chunk > 16) | |
30 chunk = 16; | |
31 for (i = 0; i < 16; i++) { | |
32 if (i < chunk) | |
33 sprintf(dp, "%02X ", sp[i]); | |
34 else | |
35 strcpy(dp, " "); | |
36 dp += 3; | |
37 if (i == 7 || i == 15) | |
38 *dp++ = ' '; | |
39 } | |
40 for (i = 0; i < chunk; i++) { | |
41 c = sp[i]; | |
42 if (c < ' ' || c > '~') | |
43 c = '.'; | |
44 *dp++ = c; | |
45 } | |
46 *dp = '\0'; | |
47 outfunc(line); | |
48 sp += chunk; | |
49 remain -= chunk; | |
50 offset += chunk; | |
51 } | |
52 } |