From 1bef463d8b4c58c68e48f6408d1b9a46a1b9707f Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Tue, 21 Jul 2015 21:49:53 +0000 Subject: [PATCH] Incremental... --- include/patty/ax25.h | 13 +++++++------ src/ax25.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/include/patty/ax25.h b/include/patty/ax25.h index 326a997..59e1299 100644 --- a/include/patty/ax25.h +++ b/include/patty/ax25.h @@ -33,12 +33,6 @@ typedef struct _patty_ax25_stats { typedef struct _patty_ax25_address patty_ax25_port; -typedef struct _patty_ax25_link { - patty_ax25_port local; - patty_ax25_port remote; - patty_ax25_stats stats; -} patty_ax25_link; - typedef struct _patty_ax25_if { enum patty_ax25_if_type type; patty_kiss_tnc * tnc; @@ -46,6 +40,13 @@ typedef struct _patty_ax25_if { patty_dict * ports; } patty_ax25_if; +typedef struct _patty_ax25_link { + patty_ax25_if * iface; + patty_ax25_port * local; + patty_ax25_port * remote; + patty_ax25_stats * stats; +} patty_ax25_link; + typedef struct _patty_ax25 { patty_dict * ifaces; /* Key: AX.25 interface name */ patty_dict * ports; /* Key: Integer port descriptor */ diff --git a/src/ax25.c b/src/ax25.c index 3cafc33..ba4aab7 100644 --- a/src/ax25.c +++ b/src/ax25.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -90,3 +91,41 @@ patty_ax25_if *patty_ax25_create_if(patty_ax25 *ax25, int opts, void *info) { return NULL; } + +patty_ax25_port *patty_ax25_listen(patty_ax25 *ax25, patty_ax25_if *iface, const char *callsign, int ssid) { + patty_ax25_port *port; + char key[10]; + + if ((port = malloc(sizeof(*port))) == NULL) { + goto error_malloc_port; + } + + if (strncpy(port->callsign, callsign, 7) == NULL) { + goto error_strncpy_callsign; + } + + port->ssid = ssid; + port->repeated = 0; + + if (snprintf(key, sizeof(key), "%s/%d", callsign, ssid) < 0) { + goto error_snprintf_key; + } + + if (patty_dict_set(iface->ports, (void *)key, strlen(key), port) == NULL) { + goto error_dict_set_port; + } + + if (patty_dict_set(ax25->ports, (void *)key, strlen(key), port) == NULL) { + goto error_dict_set_port; + } + + return port; + +error_dict_set_port: +error_strncpy_callsign: +error_snprintf_key: + free(port); + +error_malloc_port: + return NULL; +}