This commit is contained in:
XANTRONIX Development 2015-07-24 21:49:57 -05:00 committed by XANTRONIX Industrial
parent b0c014f6c1
commit 1397c7e479

74
src/if.c Normal file
View file

@ -0,0 +1,74 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <patty/ax25.h>
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;
}
}