Moving right along!
This commit is contained in:
parent
710b5ef069
commit
d25b799e4e
3 changed files with 51 additions and 26 deletions
|
@ -31,6 +31,7 @@ typedef struct _patty_ax25_if patty_ax25_if;
|
||||||
#include <patty/ax25/server.h>
|
#include <patty/ax25/server.h>
|
||||||
#include <patty/ax25/call.h>
|
#include <patty/ax25/call.h>
|
||||||
#include <patty/ax25/if.h>
|
#include <patty/ax25/if.h>
|
||||||
|
#include <patty/ax25/route.h>
|
||||||
|
|
||||||
enum patty_ax25_sock_status {
|
enum patty_ax25_sock_status {
|
||||||
PATTY_AX25_SOCK_CLOSED,
|
PATTY_AX25_SOCK_CLOSED,
|
||||||
|
@ -71,7 +72,7 @@ typedef struct _patty_ax25_sock {
|
||||||
int fd;
|
int fd;
|
||||||
char path[PATTY_AX25_SOCK_PATH_SIZE];
|
char path[PATTY_AX25_SOCK_PATH_SIZE];
|
||||||
|
|
||||||
patty_ax25_if *iface;
|
patty_ax25_route *route;
|
||||||
|
|
||||||
patty_ax25_addr local,
|
patty_ax25_addr local,
|
||||||
remote,
|
remote,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
typedef struct _patty_ax25_route {
|
typedef struct _patty_ax25_route {
|
||||||
patty_ax25_addr dest,
|
patty_ax25_addr dest,
|
||||||
gateway;
|
hops[PATTY_AX25_MAX_HOPS];
|
||||||
|
|
||||||
patty_ax25_if *iface;
|
patty_ax25_if *iface;
|
||||||
} patty_ax25_route;
|
} patty_ax25_route;
|
||||||
|
|
72
src/server.c
72
src/server.c
|
@ -246,30 +246,6 @@ error_dict_set_with_hash:
|
||||||
return -1;
|
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,
|
int patty_ax25_server_add_if(patty_ax25_server *server,
|
||||||
patty_ax25_if *iface) {
|
patty_ax25_if *iface) {
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -652,3 +628,51 @@ error_malloc_remote:
|
||||||
error_io:
|
error_io:
|
||||||
return -1;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue