Implement patty_ax25_listen()
This commit is contained in:
parent
c17abcf77a
commit
1abc0b6c98
4 changed files with 64 additions and 8 deletions
|
@ -28,10 +28,10 @@ enum patty_ax25_event {
|
||||||
typedef struct _patty_ax25_sock {
|
typedef struct _patty_ax25_sock {
|
||||||
enum patty_ax25_obj_type type;
|
enum patty_ax25_obj_type type;
|
||||||
|
|
||||||
int iface;
|
patty_ax25_if * iface;
|
||||||
int address;
|
patty_ax25_address * address;
|
||||||
int port;
|
patty_ax25_port * port;
|
||||||
int link;
|
patty_ax25_link * link;
|
||||||
} patty_ax25_sock;
|
} patty_ax25_sock;
|
||||||
|
|
||||||
struct _patty_ax25 {
|
struct _patty_ax25 {
|
||||||
|
|
|
@ -10,11 +10,12 @@ typedef struct _patty_ax25_port {
|
||||||
int ssid;
|
int ssid;
|
||||||
} patty_ax25_port;
|
} patty_ax25_port;
|
||||||
|
|
||||||
patty_ax25_port *patty_ax25_port_create(patty_ax25_if *iface,
|
patty_ax25_port *patty_ax25_port_create(const char *callsign, int ssid);
|
||||||
const char *callsign, int ssid);
|
|
||||||
|
|
||||||
void patty_ax25_port_destroy(patty_ax25_port *port);
|
void patty_ax25_port_destroy(patty_ax25_port *port);
|
||||||
|
|
||||||
|
int patty_ax25_port_bind(patty_ax25_port *port, patty_ax25_if *iface);
|
||||||
|
|
||||||
int patty_ax25_each_port(patty_ax25 *ax25,
|
int patty_ax25_each_port(patty_ax25 *ax25,
|
||||||
int (*callback)(patty_ax25_port *, void *), void *ctx);
|
int (*callback)(patty_ax25_port *, void *), void *ctx);
|
||||||
|
|
||||||
|
|
39
src/ax25.c
39
src/ax25.c
|
@ -87,3 +87,42 @@ error_dict_set:
|
||||||
error_malloc_sock:
|
error_malloc_sock:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int patty_ax25_listen(patty_ax25 *ax25, int socket, const char *callsign, int ssid) {
|
||||||
|
patty_ax25_port *port;
|
||||||
|
patty_ax25_sock *sock;
|
||||||
|
|
||||||
|
if ((sock = patty_dict_get(ax25->fd_lookup, &socket, sizeof(socket))) == NULL) {
|
||||||
|
goto error_dict_get;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If there is already a port associated with this socket, then that's a
|
||||||
|
* problem.
|
||||||
|
*/
|
||||||
|
if (sock->port != NULL) {
|
||||||
|
errno = EBUSY;
|
||||||
|
|
||||||
|
goto error_busy;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((port = patty_ax25_port_create(callsign, ssid)) == NULL) {
|
||||||
|
goto error_port_create;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (patty_dict_set(ax25->fd_lookup, &ax25->fd, sizeof(ax25->fd), port) == NULL) {
|
||||||
|
goto error_dict_set;
|
||||||
|
}
|
||||||
|
|
||||||
|
sock->port = port;
|
||||||
|
|
||||||
|
return ax25->fd++;
|
||||||
|
|
||||||
|
error_dict_set:
|
||||||
|
patty_ax25_port_destroy(port);
|
||||||
|
|
||||||
|
error_port_create:
|
||||||
|
error_busy:
|
||||||
|
error_dict_get:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
20
src/port.c
20
src/port.c
|
@ -1,9 +1,10 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <patty/ax25.h>
|
#include <patty/ax25.h>
|
||||||
|
|
||||||
patty_ax25_port *patty_ax25_port_create(patty_ax25_if *iface, const char *callsign, int ssid) {
|
patty_ax25_port *patty_ax25_port_create(const char *callsign, int ssid) {
|
||||||
patty_ax25_port *port;
|
patty_ax25_port *port;
|
||||||
|
|
||||||
if ((port = malloc(sizeof(*port))) == NULL) {
|
if ((port = malloc(sizeof(*port))) == NULL) {
|
||||||
|
@ -11,8 +12,8 @@ patty_ax25_port *patty_ax25_port_create(patty_ax25_if *iface, const char *callsi
|
||||||
}
|
}
|
||||||
|
|
||||||
port->type = PATTY_AX25_OBJ_PORT;
|
port->type = PATTY_AX25_OBJ_PORT;
|
||||||
port->iface = iface;
|
|
||||||
port->ssid = ssid;
|
port->ssid = ssid;
|
||||||
|
port->iface = NULL;
|
||||||
|
|
||||||
strncpy(port->callsign, callsign, sizeof(port->callsign));
|
strncpy(port->callsign, callsign, sizeof(port->callsign));
|
||||||
|
|
||||||
|
@ -26,6 +27,21 @@ void patty_ax25_port_destroy(patty_ax25_port *port) {
|
||||||
free(port);
|
free(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int patty_ax25_port_bind(patty_ax25_port *port, patty_ax25_if *iface) {
|
||||||
|
if (port->iface != NULL) {
|
||||||
|
errno = EBUSY;
|
||||||
|
|
||||||
|
goto error_busy;
|
||||||
|
}
|
||||||
|
|
||||||
|
port->iface = iface;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
error_busy:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int patty_ax25_each_port(patty_ax25 *ax25, int (*callback)(patty_ax25_port *, void *), void *ctx) {
|
int patty_ax25_each_port(patty_ax25 *ax25, int (*callback)(patty_ax25_port *, void *), void *ctx) {
|
||||||
patty_list_iterator *iter;
|
patty_list_iterator *iter;
|
||||||
patty_ax25_port *port;
|
patty_ax25_port *port;
|
||||||
|
|
Loading…
Add table
Reference in a new issue