summaryrefslogtreecommitdiffstats
path: root/contrib/ipfilter/lib/hexdump.c
blob: f6cc156910c8db2c6c61c4c1078ccb3e6791be00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*	$FreeBSD$	*/

#include <ctype.h>

#include "ipf.h"

void hexdump(out, addr, len, ascii)
FILE *out;
void *addr;
int len, ascii;
{
	FILE *fpout;
	u_char *s, *t;
	int i;

	fpout = out ? out : stdout;
	for (i = 0, s = addr; i < len; i++, s++) {
		fprintf(fpout, "%02x", *s);
		if (i % 16 == 15) {
			if (ascii != 0) {
				fputc('\t', fpout);
				for (t = s - 15; t<= s; t++)
					fputc(ISPRINT(*t) ? *t : '.', fpout);
			}
			fputc('\n', fpout);
		} else if (i % 4 == 3) {
			fputc(' ', fpout);
		}
	}
}
OpenPOWER on IntegriCloud