Perform hex dump of packet contents in src/decode.c

This commit is contained in:
XANTRONIX Development 2020-05-22 21:14:22 -04:00 committed by XANTRONIX Industrial
parent cc57d49c0e
commit 478d22936b

View file

@ -32,6 +32,45 @@ static int callsign_fprint(FILE *stream, const patty_ax25_address *address) {
return 0;
}
static int hexdump_fprint(FILE *stream, void *data, size_t len) {
size_t i;
for (i=0; i<len; i++) {
if (i % 16 == 0) {
if (i) {
if (fprintf(stderr, "\n") < 0) {
goto error_fprintf;
}
}
if (fprintf(stderr, "%08lx: ", i) < 0) {
goto error_fprintf;
}
}
if (fprintf(stderr, "%02x", ((uint8_t *)data)[i]) < 0) {
goto error_fprintf;
}
if (i % 2) {
if (fprintf(stderr, " ") < 0) {
goto error_fprintf;
}
}
}
if (i) {
if (fprintf(stderr, "\n") < 0) {
goto error_fprintf;
}
}
return 0;
error_fprintf:
return -1;
}
static int address_fprint(FILE *stream, const patty_ax25_frame *frame) {
int i;
@ -87,6 +126,8 @@ int main(int argc, char **argv) {
}
fprintf(stderr, " %ld bytes\n", len);
hexdump_fprint(stderr, data, len);
}
patty_kiss_tnc_close(tnc);