29 lines
No EOL
565 B
C
29 lines
No EOL
565 B
C
#include "util.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
// hex_dumb display network packets in a good way
|
|
void hex_dump(unsigned n, const unsigned char* buf)
|
|
{
|
|
int on_this_line = 0;
|
|
while (n-- > 0)
|
|
{
|
|
fprintf(stderr, "%02X ", *buf++);
|
|
on_this_line += 1;
|
|
if (on_this_line == 16 || n == 0)
|
|
{
|
|
int i;
|
|
|
|
fputs(" ", stderr);
|
|
|
|
for (i = on_this_line; i < 16; i++)
|
|
fputs(" ", stderr);
|
|
|
|
for (i = on_this_line; i > 0; i--)
|
|
fputc(isprint(buf[-i]) ? buf[-i] : '.', stderr);
|
|
|
|
fputs("\n", stderr);
|
|
on_this_line = 0;
|
|
}
|
|
}
|
|
} |