diff --git a/src/decode.c b/src/decode.c index f27fa62..c352159 100644 --- a/src/decode.c +++ b/src/decode.c @@ -4,8 +4,8 @@ #include #include -#include #include +#include static void usage(int argc, char **argv, const char *message, ...) { if (message) { @@ -22,136 +22,6 @@ static void usage(int argc, char **argv, const char *message, ...) { exit(1); } -static int callsign_fprint(FILE *stream, const patty_ax25_addr *addr) { - char buf[7]; - uint8_t ssid; - - if (patty_ax25_ntop(addr, buf, &ssid, sizeof(buf)) < 0) { - goto error_ntop; - } - - fprintf(stream, "%s", buf); - - if (ssid) { - fprintf(stream, "/%d", ssid); - } - - return 0; - -error_ntop: - return -1; -} - -#define printable(c) \ - (c >= 0x20 && c < 0x7f) - -static int hexdump_fprint(FILE *stream, void *data, size_t len) { - size_t i; - - for (i=0; isrc); - - fprintf(stream, " > "); - - for (i=0; ihops; i++) { - callsign_fprint(stream, &frame->repeaters[i]); - fprintf(stream, " > "); - } - - callsign_fprint(stream, &frame->dest); - - return 0; -} - -static int frame_fprint(FILE *stream, - const patty_ax25_frame *frame, - void *data, - size_t len) { - if (address_fprint(stream, frame) < 0) { - goto error_io; - } - - if (PATTY_AX25_CONTROL_INFO(frame->control)) { - if (fprintf(stream, " type I poll %d ns %d nr %d info %zu", - PATTY_AX25_CONTROL_POLL(frame->control), - PATTY_AX25_CONTROL_SEQ_SEND(frame->control), - PATTY_AX25_CONTROL_SEQ_RECV(frame->control), - frame->infolen) < 0) { - goto error_io; - } - } else if (PATTY_AX25_CONTROL_UNNUMBERED(frame->control)) { - if (fprintf(stream, " type U info %zu", - frame->infolen) < 0) { - goto error_io; - } - } - - if (fprintf(stream, " total %zu bytes\n", len) < 0) { - goto error_io; - } - - if (frame->info) { - if (hexdump_fprint(stream, frame->info, frame->infolen) < 0) { - goto error_io; - } - } - - return 0; - -error_io: - return -1; -} - int main(int argc, char **argv) { patty_kiss_tnc *tnc; void *buf; @@ -195,10 +65,10 @@ int main(int argc, char **argv) { goto error_ax25_frame_decode; } - if (frame_fprint(stdout, &frame, buf, len) < 0) { + if (patty_print_frame(stdout, &frame, buf, len) < 0) { perror("Unable to print frame"); - goto error_frame_fprint; + goto error_print_frame; } } @@ -208,7 +78,7 @@ int main(int argc, char **argv) { return 0; -error_frame_fprint: +error_print_frame: error_ax25_frame_decode: error_kiss_tnc_recv: free(buf);