NetBSD/dist/ipf/lib/hexdump.c

31 lines
547 B
C
Raw Normal View History

/* $NetBSD: hexdump.c,v 1.2 2004/11/13 19:16:10 he Exp $ */
2004-03-28 12:55:20 +04:00
#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);
2004-03-28 12:55:20 +04:00
}
fputc('\n', fpout);
} else if (i % 4 == 3) {
fputc(' ', fpout);
}
}
}