From 1397c7e479f33c1afca32027af11e359b4efff6e Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Fri, 24 Jul 2015 21:49:57 -0500 Subject: [PATCH] Oh cock --- src/if.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/if.c diff --git a/src/if.c b/src/if.c new file mode 100644 index 0000000..91ae4dd --- /dev/null +++ b/src/if.c @@ -0,0 +1,74 @@ +#include +#include +#include + +#include + +static patty_ax25_if *create_tnc(const char *device) { + patty_ax25_if *iface; + + if ((iface = malloc(sizeof(*iface))) == NULL) { + goto error_malloc_iface; + } + + memset(iface, '\0', sizeof(*iface)); + + if ((iface->tnc = patty_kiss_tnc_open(device, PATTY_KISS_BUFSZ)) == NULL) { + goto error_kiss_tnc_open; + } + + iface->type = PATTY_AX25_IF_KISS_TNC_TTY; + + return iface; + +error_kiss_tnc_open: + free(iface); + +error_malloc_iface: + return NULL; +} + +static void destroy_tnc(patty_ax25_if *iface) { + patty_kiss_tnc_close(iface->tnc); +} + +patty_ax25_if *patty_ax25_if_create(int opts, void *info) { + patty_ax25_if *iface; + + switch (PATTY_AX25_IF_OPT_TYPE(opts)) { + case PATTY_AX25_IF_KISS_TNC_TTY: { + iface = create_tnc((const char *)info); + + break; + } + + default: { + errno = EINVAL; + + goto error; + } + } + + if (iface == NULL) { + goto error; + } + + if ((iface->addresses = patty_list_new()) == NULL) { + goto error; + } + + return iface; + +error: + return NULL; +} + +void patty_ax25_if_destroy(patty_ax25_if *iface) { + switch (iface->type) { + case PATTY_AX25_IF_KISS_TNC_TTY: { + destroy_tnc(iface); break; + } + + default: break; + } +}