diff --git a/include/patty/ax25.h b/include/patty/ax25.h index 87f5623..8f8239a 100644 --- a/include/patty/ax25.h +++ b/include/patty/ax25.h @@ -85,8 +85,8 @@ int patty_ax25_accept(patty_ax25 *ax25, int patty_ax25_close(patty_ax25 *ax25, int fd); -int patty_ax25_wait(patty_ax25 *ax25, - int fds, enum patty_ax25_event *ev); +int patty_ax25_next_event(patty_ax25 *ax25, + enum patty_ax25_event *ev); int patty_ax25_recv(patty_ax25 *ax25, int fd, patty_ax25_frame *frame); diff --git a/include/patty/ax25/if.h b/include/patty/ax25/if.h index 09cd200..f3df5ea 100644 --- a/include/patty/ax25/if.h +++ b/include/patty/ax25/if.h @@ -34,6 +34,8 @@ patty_ax25_if *patty_ax25_if_create(int opts, void *info); void patty_ax25_if_destroy(patty_ax25_if *iface); +patty_kiss_tnc *patty_ax25_if_tnc(patty_ax25_if *iface); + int patty_ax25_if_each_address(patty_ax25_if *iface, int (*callback)(patty_ax25_address *, void *), void *ctx); diff --git a/include/patty/kiss.h b/include/patty/kiss.h index 7c0eb0e..0b5fbb9 100644 --- a/include/patty/kiss.h +++ b/include/patty/kiss.h @@ -31,6 +31,8 @@ typedef struct _patty_kiss_tnc patty_kiss_tnc; patty_kiss_tnc *patty_kiss_tnc_open(const char *device, size_t bufsize); +int patty_kiss_tnc_fd_unix(patty_kiss_tnc *tnc); + void patty_kiss_tnc_close(patty_kiss_tnc *tnc); int patty_kiss_tnc_dropped(patty_kiss_tnc *tnc); diff --git a/src/ax25.c b/src/ax25.c index ff0ab4a..1d8465b 100644 --- a/src/ax25.c +++ b/src/ax25.c @@ -187,3 +187,48 @@ error_exists: error_fd_lookup: return -1; } + +static int event_fd_set(patty_ax25 *ax25, fd_set *set) { + patty_list_iterator *ifaces; + patty_ax25_if *iface; + + FD_ZERO(set); + + if ((ifaces = patty_list_start(ax25->ifaces)) == NULL) { + goto error_list_start; + } + + while ((iface = patty_list_next(ifaces)) != NULL) { + patty_kiss_tnc *tnc; + int fd; + + if ((tnc = patty_ax25_if_tnc(iface)) == NULL) { + goto error_if_tnc; + } + + if ((fd = patty_kiss_tnc_fd_unix(tnc)) < 0) { + goto error_kiss_tnc_fd_unix; + } + + FD_SET(fd, set); + } + + patty_list_finish(ifaces); + + return 0; + +error_kiss_tnc_fd_unix: +error_if_tnc: + patty_list_finish(ifaces); + +error_list_start: + return -1; +} + +int patty_ax25_next_event(patty_ax25 *ax25, enum patty_ax25_event *ev) { + fd_set fds; + + event_fd_set(ax25, &fds); + + return 0; +} diff --git a/src/if.c b/src/if.c index 204f63b..0d32d3c 100644 --- a/src/if.c +++ b/src/if.c @@ -79,6 +79,10 @@ void patty_ax25_if_destroy(patty_ax25_if *iface) { } } +patty_kiss_tnc *patty_ax25_if_tnc(patty_ax25_if *iface) { + return iface->tnc; +} + int patty_ax25_if_each_address(patty_ax25_if *iface, int (*callback)(patty_ax25_address *, void *), void *ctx) { patty_list_iterator *iter; patty_ax25_address *address; diff --git a/src/kiss.c b/src/kiss.c index 376545c..d0c0d5c 100644 --- a/src/kiss.c +++ b/src/kiss.c @@ -65,6 +65,10 @@ error_malloc_tnc: return NULL; } +int patty_kiss_tnc_fd_unix(patty_kiss_tnc *tnc) { + return tnc->fd; +} + void patty_kiss_tnc_close(patty_kiss_tnc *tnc) { close(tnc->fd); free(tnc->frame);