From d25b799e4ed72108e5a9552c673a186b4eebd062 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Thu, 18 Jun 2020 18:50:24 -0400 Subject: [PATCH] Moving right along! --- include/patty/ax25.h | 3 +- include/patty/ax25/route.h | 2 +- src/server.c | 72 +++++++++++++++++++++++++------------- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/include/patty/ax25.h b/include/patty/ax25.h index 1bdc752..41acf69 100644 --- a/include/patty/ax25.h +++ b/include/patty/ax25.h @@ -31,6 +31,7 @@ typedef struct _patty_ax25_if patty_ax25_if; #include #include #include +#include enum patty_ax25_sock_status { PATTY_AX25_SOCK_CLOSED, @@ -71,7 +72,7 @@ typedef struct _patty_ax25_sock { int fd; char path[PATTY_AX25_SOCK_PATH_SIZE]; - patty_ax25_if *iface; + patty_ax25_route *route; patty_ax25_addr local, remote, diff --git a/include/patty/ax25/route.h b/include/patty/ax25/route.h index 7699131..c9b7b4a 100644 --- a/include/patty/ax25/route.h +++ b/include/patty/ax25/route.h @@ -3,7 +3,7 @@ typedef struct _patty_ax25_route { patty_ax25_addr dest, - gateway; + hops[PATTY_AX25_MAX_HOPS]; patty_ax25_if *iface; } patty_ax25_route; diff --git a/src/server.c b/src/server.c index 79bbc9b..7a880fd 100644 --- a/src/server.c +++ b/src/server.c @@ -246,30 +246,6 @@ error_dict_set_with_hash: return -1; } -static int server_connect(patty_ax25_server *server, - int socket, - patty_ax25_addr *addr) { - patty_ax25_sock *sock; - - if ((sock = sock_by_fd(server->socks_by_fd, socket)) == NULL) { - goto error_sock_by_fd; - } - - if (sock->remote.callsign[0] != '\0') { - errno = EEXIST; - - goto error_exists; - } - - memcpy(&sock->remote, addr, sizeof(*addr)); - - return 0; - -error_exists: -error_sock_by_fd: - return -1; -} - int patty_ax25_server_add_if(patty_ax25_server *server, patty_ax25_if *iface) { int fd; @@ -652,3 +628,51 @@ error_malloc_remote: error_io: return -1; } + +static int server_connect(patty_ax25_server *server, + int client) { + patty_ax25_call_connect_request request; + patty_ax25_call_connect_response response; + + patty_ax25_sock *sock; + + if (read(client, &request, sizeof(request)) < 0) { + goto error_io; + } + + if ((sock = sock_by_fd(server->socks_by_fd, request.socket)) == NULL) { + response.ret = -1; + response.eno = EBADF; + + goto error_sock_by_fd; + } + + if (sock->remote.callsign[0] != '\0') { + response.ret = -1; + response.eno = EEXIST; + + goto error_exists; + } + + memcpy(&sock->remote, &request.peer, sizeof(request.peer)); + + if (sock_save_by_addrpair(server->socks_established, + sock, + &sock->local, + &sock->remote) < 0) { + goto error_sock_save_by_addrpair; + } + +error_exists: +error_sock_by_fd: + if (write(client, &response, sizeof(response)) < 0) { + goto error_io; + } + + return 0; + +error_sock_save_by_addrpair: +error_io: + return -1; +} +