diff --git a/src/ax25.c b/src/ax25.c index 89917a8..dc3d593 100644 --- a/src/ax25.c +++ b/src/ax25.c @@ -62,8 +62,8 @@ error_dict_get: return NULL; } -static int fd_store(patty_ax25 *ax25, void *obj) { - if (patty_dict_set(ax25->fd_lookup, &ax25->fd, sizeof(ax25->fd), obj) == NULL) { +static int fd_store(patty_ax25 *ax25, patty_ax25_sock *sock) { + if (patty_dict_set(ax25->fd_lookup, &ax25->fd, sizeof(ax25->fd), sock) == NULL) { goto error_dict_set; } @@ -73,19 +73,6 @@ error_dict_set: return -1; } -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; - } - - return fd_store(ax25, iface); - -error_get_if: - return -1; -} - int patty_ax25_socket(patty_ax25 *ax25) { patty_ax25_sock *sock; int fd; @@ -111,6 +98,28 @@ error_malloc_sock: return -1; } +int patty_ax25_open(patty_ax25 *ax25, const char *ifname) { + patty_ax25_sock *sock; + + if ((sock = malloc(sizeof(*sock))) == NULL) { + goto error_malloc_sock; + } + + memset(sock, '\0', sizeof(*sock)); + + if ((sock->iface = patty_ax25_get_if(ax25, ifname)) == NULL) { + goto error_get_if; + } + + return fd_store(ax25, sock); + +error_get_if: + free(sock); + +error_malloc_sock: + return -1; +} + int patty_ax25_bind(patty_ax25 *ax25, int socket, const char *callsign, int ssid) { patty_ax25_sock *sock;