From 87ec27dd9242c0ff329555c68d22bb4060ca0166 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sat, 25 Jul 2015 14:43:45 -0500 Subject: [PATCH] Implement patty_ax25_open() --- include/patty/ax25.h | 18 ++++++++++++++++++ include/patty/ax25/defs.h | 10 ++-------- src/ax25.c | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/include/patty/ax25.h b/include/patty/ax25.h index 7b52402..23aacde 100644 --- a/include/patty/ax25.h +++ b/include/patty/ax25.h @@ -25,6 +25,24 @@ enum patty_ax25_event { PATTY_AX25_IO_WRITE }; +typedef struct _patty_ax25_sock { + enum patty_ax25_obj_type type; + + int iface; + int address; + int port; + int link; +} patty_ax25_sock; + +struct _patty_ax25 { + patty_list * ifaces; + patty_list * ports; + patty_list * links; + + patty_dict * fd_lookup; + int fd; +}; + int patty_ax25_init(patty_ax25 *ax25); void patty_ax25_stop(patty_ax25 *ax25); diff --git a/include/patty/ax25/defs.h b/include/patty/ax25/defs.h index d8d1e81..af3a726 100644 --- a/include/patty/ax25/defs.h +++ b/include/patty/ax25/defs.h @@ -9,6 +9,7 @@ enum patty_ax25_obj_type { PATTY_AX25_OBJ_UNKNOWN, PATTY_AX25_OBJ_IF, + PATTY_AX25_OBJ_SOCKET, PATTY_AX25_OBJ_PORT, PATTY_AX25_OBJ_LINK }; @@ -19,13 +20,6 @@ typedef struct _patty_ax25_stats { size_t dropped; } patty_ax25_stats; -typedef struct _patty_ax25 { - patty_list * ifaces; - patty_list * ports; - patty_list * links; - - patty_dict * fd_lookup; - int fd; -} patty_ax25; +typedef struct _patty_ax25 patty_ax25; #endif /* _PATTY_AX25_DEFS_H */ diff --git a/src/ax25.c b/src/ax25.c index 00273b6..47843da 100644 --- a/src/ax25.c +++ b/src/ax25.c @@ -47,3 +47,21 @@ void patty_ax25_stop(patty_ax25 *ax25) { patty_list_destroy(ax25->ports); patty_list_destroy(ax25->ifaces); } + +int patty_ax25_open(patty_ax25 *ax25, const char *ifname) { + patty_ax25_if *iface; + + if ((iface = patty_ax25_get_if(ax25, ifname)) == NULL) { + goto error_get_if; + } + + if (patty_dict_set(ax25->fd_lookup, &ax25->fd, sizeof(ax25->fd), iface) == NULL) { + goto error_dict_set; + } + + return ax25->fd++; + +error_dict_set: +error_get_if: + return -1; +}