rawnet - fix logging, add hexdump.

This commit is contained in:
Kelvin Sherlock 2018-12-14 20:35:23 -05:00
parent 1b1983b64a
commit a8c23a4c2a
2 changed files with 32 additions and 1 deletions

View File

@ -149,3 +149,32 @@ unsigned long crc32_buf(const char *buffer, unsigned int len) {
return ~crc; return ~crc;
} }
void rawnet_hexdump(unsigned char *what, int count ) {
static const char hex[] = "0123456789abcdef";
char buffer1[16 * 3 + 1];
char buffer2[16 + 1];
unsigned offset;
offset = 0;
while (count) {
unsigned char x = *what++;
buffer1[offset * 3] = hex[x >> 4];
buffer1[offset * 3 + 1] = hex[x & 0x0f];
buffer1[offset * 3 + 2] = ' ';
buffer2[offset] = isprint(x) ? x : '.';
--count;
++offset;
if (offset == 16 || count == 0) {
buffer1[offset * 3] = 0;
buffer2[offset] = 0;
fprintf(stderr, "%-50s %s\n", buffer1, buffer2);
offset = 0;
}
}
}

View File

@ -52,5 +52,7 @@ extern int util_string_set(char **str, const char *new_value);
extern unsigned long crc32_buf(const char *buffer, unsigned int len); extern unsigned long crc32_buf(const char *buffer, unsigned int len);
#define log_message(level,...) fprintf(stderr,__VA_ARGS__) void rawnet_hexdump(unsigned char *what, int count );
#define log_message(level,...) do { fprintf(stderr,__VA_ARGS__); fputs("\n", stderr); } while (0)
#endif #endif