93 lines
2.1 KiB
C
93 lines
2.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include <patty/kiss.h>
|
|
#include <patty/ax25.h>
|
|
|
|
static void usage(int argc, char **argv, const char *message, ...) {
|
|
if (message) {
|
|
va_list args;
|
|
|
|
va_start(args, message);
|
|
vfprintf(stderr, message, args);
|
|
fprintf(stderr, "\n");
|
|
va_end(args);
|
|
}
|
|
|
|
fprintf(stderr, "usage: %s kiss.cap\n", argv[0]);
|
|
|
|
exit(1);
|
|
}
|
|
|
|
static int callsign_fprint(FILE *stream, const patty_ax25_address *address) {
|
|
fprintf(stream, "%s", address->callsign);
|
|
|
|
if (address->ssid) {
|
|
fprintf(stream, "/%d", address->ssid);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int address_fprint(FILE *stream, const patty_ax25_frame *frame) {
|
|
int i;
|
|
|
|
callsign_fprint(stream, &frame->src);
|
|
fprintf(stream, " > ");
|
|
callsign_fprint(stream, &frame->dest);
|
|
|
|
for (i=0; i<frame->hops; i++) {
|
|
fprintf(stream, " < ");
|
|
callsign_fprint(stream, &frame->repeaters[i]);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
patty_kiss_tnc *tnc;
|
|
ssize_t len;
|
|
void *data;
|
|
int port;
|
|
|
|
if (argc != 2) {
|
|
usage(argc, argv, "No TNC device provided");
|
|
}
|
|
|
|
if ((tnc = patty_kiss_tnc_open(argv[1], 330)) == NULL) {
|
|
perror("Unable to open TNC");
|
|
|
|
exit(127);
|
|
}
|
|
|
|
while ((len = patty_kiss_tnc_recv(tnc, &data, &port)) > 0) {
|
|
patty_ax25_frame frame;
|
|
|
|
if (patty_ax25_frame_decode(&frame, data, len) < 0) {
|
|
perror("Unable to decode frame");
|
|
|
|
exit(127);
|
|
}
|
|
|
|
address_fprint(stderr, &frame);
|
|
|
|
if (frame.type == PATTY_AX25_FRAME_INFO) {
|
|
fprintf(stderr, " poll %d", PATTY_AX25_CONTROL_POLL(frame.control));
|
|
fprintf(stderr, " ns %d", PATTY_AX25_CONTROL_SEQ_SEND(frame.control));
|
|
fprintf(stderr, " nr %d", PATTY_AX25_CONTROL_SEQ_RECV(frame.control));
|
|
}
|
|
|
|
if (frame.payload) {
|
|
fprintf(stderr, " proto %02x", frame.proto);
|
|
}
|
|
|
|
fprintf(stderr, " %ld bytes\n", len);
|
|
}
|
|
|
|
patty_kiss_tnc_close(tnc);
|
|
|
|
return 0;
|
|
}
|