I'm writting a proxy programme to pass-through raw binary data between AX.25 socket and a TCP socket.
In fact, to not to reinvent the wheel, I took a simple TCP proxy source and converted the server TCP socket to AX.25 socket on one side and a client TCP socket to AX.25 socket on another side of AX.25 link.
/* Forward data between sockets */
void forward_data(int source_sock, int destination_sock, const char *name) {
ssize_t n;
fd_set read_fd;
int s = source_sock;
#define BUF_SIZE 16384
char buffer[BUF_SIZE];
if (fcntl(s, F_SETFL, O_NONBLOCK) < 0) {
perror("socket");
close(s);
return;
}
while (1) {
FD_ZERO(&read_fd);
FD_SET(s, &read_fd);
select(s + 1, &read_fd, NULL, NULL, NULL);
if (FD_ISSET(s, &read_fd)) {
n = recv(source_sock, buffer, BUF_SIZE, 0);
}
if (n < 0) break;
write(destination_sock, buffer, n); // send data to output socket
}
On one side of AX.25 link it accepts TCP connections on port 6789 and initiates an AX.25 connection to UR5VIB-8. On the other side of the link proxy accepts AX.25 connections on UR5VIB-8 and forwards data to local TCP port 22.
It generally works. For a while. You can log in by SSH (or telnet) via proxied link to the remote site. The overal interactivity (reaction on packet loss) is far better than in IP encapsulation mode. But after a while you've got a connection reset from SSH with message:
Bad packet length 573483957.
ssh_dispatch_run_fatal: Connection to 127.0.0.1 port 6789: Connection corrupted
I tried to figure out what is the problem with axlisten and tcpdump, and I'm not 100% sure, but I think I found that there is data duplication in the middle of the transfer. The inserted data makes SSH confused.