comparison uptools/libcoding/hexdump.c @ 336:ead4ee22ef62

uptools/libcoding: hex dump function implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 04 Feb 2018 01:03:20 +0000
parents
children
comparison
equal deleted inserted replaced
335:097ce8431d11 336:ead4ee22ef62
1 /*
2 * This library module implements a simple hex dump facility.
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7
8 msg_bits_hexdump(dumpbuf, dumplen)
9 u_char *dumpbuf;
10 unsigned dumplen;
11 {
12 u_char *buf = dumpbuf;
13 unsigned lineoff, linelen, i, c;
14
15 for (lineoff = 0; lineoff < dumplen; ) {
16 linelen = dumplen - lineoff;
17 if (linelen > 16)
18 linelen = 16;
19 printf("%02X: ", lineoff);
20 for (i = 0; i < 16; i++) {
21 if (i < linelen)
22 printf("%02X ", buf[i]);
23 else
24 fputs(" ", stdout);
25 if (i == 7 || i == 15)
26 putchar(' ');
27 }
28 for (i = 0; i < linelen; i++) {
29 c = buf[i];
30 if (c < ' ' || c > '~')
31 c = '.';
32 putchar(c);
33 }
34 putchar('\n');
35 buf += linelen;
36 lineoff += linelen;
37 }
38 }