diff --git a/src/Makefile b/src/Makefile index 51567cb..6d05857 100644 --- a/src/Makefile +++ b/src/Makefile @@ -10,7 +10,7 @@ LDFLAGS = HEADERS = kiss.h ax25.h ax25/if.h ax25/macros.h ax25/proto.h \ ax25/frame.h list.h hash.h dict.h -OBJS = kiss.o ax25.o if.o frame.o list.o hash.o dict.o test.o +OBJS = kiss.o ax25.o if.o port.o frame.o list.o hash.o dict.o test.o PROGRAM = test diff --git a/src/port.c b/src/port.c new file mode 100644 index 0000000..587791e --- /dev/null +++ b/src/port.c @@ -0,0 +1,52 @@ +#include +#include + +#include + +patty_ax25_port *patty_ax25_port_create(patty_ax25_if *iface, const char *callsign, int ssid) { + patty_ax25_port *port; + + if ((port = malloc(sizeof(*port))) == NULL) { + goto error_malloc_port; + } + + port->type = PATTY_AX25_OBJ_PORT; + port->iface = iface; + port->ssid = ssid; + + strncpy(port->callsign, callsign, sizeof(port->callsign)); + + return port; + +error_malloc_port: + return NULL; +} + +void patty_ax25_port_destroy(patty_ax25_port *port) { + free(port); +} + +int patty_ax25_each_port(patty_ax25 *ax25, int (*callback)(patty_ax25_port *, void *), void *ctx) { + patty_list_iterator *iter; + patty_ax25_port *port; + + if ((iter = patty_list_start(ax25->ports)) == NULL) { + goto error_list_start; + } + + while ((port = patty_list_next(iter)) != NULL) { + if (callback(port, ctx) < 0) { + goto error_callback; + } + } + + patty_list_finish(iter); + + return 0; + +error_callback: + patty_list_finish(iter); + +error_list_start: + return -1; +}