Perform hex dump of packet contents in src/decode.c
This commit is contained in:
parent
cc57d49c0e
commit
478d22936b
1 changed files with 41 additions and 0 deletions
41
src/decode.c
41
src/decode.c
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue