Implement src/port.c

This commit is contained in:
XANTRONIX Development 2015-07-25 00:31:39 -05:00 committed by XANTRONIX Industrial
parent e85df9e29e
commit b923ad3566
2 changed files with 53 additions and 1 deletions

View file

@ -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

52
src/port.c Normal file
View file

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