Implement patty_ax25_if_addr_set()

Changes:

    * Remove the initial address argument from patty_ax25_if_new()

    * Implement patty_ax25_if_addr_set() to set the AX.25 address of an
      interface at any time
This commit is contained in:
XANTRONIX Development 2020-10-03 15:18:16 -04:00 committed by XANTRONIX Industrial
parent 7415ef8573
commit 675e6cf727
4 changed files with 44 additions and 20 deletions

View file

@ -44,6 +44,7 @@ static patty_ax25_if *create_kiss(struct context *ctx, int argc, char **argv) {
enum mode_kiss mode = MODE_KISS_DEVICE; enum mode_kiss mode = MODE_KISS_DEVICE;
patty_kiss_tnc_info info; patty_kiss_tnc_info info;
patty_ax25_if *iface;
int i; int i;
@ -115,10 +116,21 @@ static patty_ax25_if *create_kiss(struct context *ctx, int argc, char **argv) {
} }
} }
return patty_ax25_if_new(&ctx->addr, if ((iface = patty_ax25_if_new(patty_kiss_tnc_driver(),
patty_kiss_tnc_driver(), &info)) == NULL) {
&info); goto error_if_new;
}
if (patty_ax25_if_addr_set(iface, &ctx->addr) < 0) {
goto error_if_addr_set;
}
return iface;
error_if_addr_set:
patty_ax25_if_destroy(iface);
error_if_new:
error_invalid: error_invalid:
return NULL; return NULL;
} }
@ -214,8 +226,7 @@ static patty_ax25_if *create_aprs_is(struct context *ctx,
} }
} }
if ((iface = patty_ax25_if_new(&ctx->addr, if ((iface = patty_ax25_if_new(patty_ax25_aprs_is_driver(),
patty_ax25_aprs_is_driver(),
&info)) == NULL) { &info)) == NULL) {
patty_error_fmt(ctx->err, "Unable to connect to APRS-IS service %s:%s: %s", patty_error_fmt(ctx->err, "Unable to connect to APRS-IS service %s:%s: %s",
info.host, info.port, strerror(errno)); info.host, info.port, strerror(errno));
@ -223,8 +234,15 @@ static patty_ax25_if *create_aprs_is(struct context *ctx,
goto error_if_new; goto error_if_new;
} }
if (patty_ax25_if_addr_set(iface, &ctx->addr) < 0) {
goto error_if_addr_set;
}
return iface; return iface;
error_if_addr_set:
patty_ax25_if_destroy(iface);
error_if_new: error_if_new:
error_invalid: error_invalid:
return NULL; return NULL;

View file

@ -303,8 +303,7 @@ static int handle_standalone(patty_daemon *daemon,
goto error_kiss_config; goto error_kiss_config;
} }
if ((iface = patty_ax25_if_new(&addr, if ((iface = patty_ax25_if_new(patty_kiss_tnc_driver(),
patty_kiss_tnc_driver(),
&info)) == NULL) { &info)) == NULL) {
fprintf(stderr, "%s: Unable to create network interface %s: %s\n", fprintf(stderr, "%s: Unable to create network interface %s: %s\n",
argv0, DEFAULT_IFNAME, strerror(errno)); argv0, DEFAULT_IFNAME, strerror(errno));
@ -314,6 +313,13 @@ static int handle_standalone(patty_daemon *daemon,
int fd = patty_ax25_if_fd(iface); int fd = patty_ax25_if_fd(iface);
char *pty; char *pty;
if (patty_ax25_if_addr_set(iface, &addr) < 0) {
fprintf(stderr, "%s: Unable to set address for interface %s: %s\n",
argv[0], DEFAULT_IFNAME, strerror(errno));
goto error_if_addr_set;
}
if (isatty(fd) && (pty = ptsname(fd)) != NULL) { if (isatty(fd) && (pty = ptsname(fd)) != NULL) {
printf("if %s pty %s\n", DEFAULT_IFNAME, pty); printf("if %s pty %s\n", DEFAULT_IFNAME, pty);
} }
@ -337,6 +343,9 @@ static int handle_standalone(patty_daemon *daemon,
error_daemon_route_add_default: error_daemon_route_add_default:
error_daemon_if_add: error_daemon_if_add:
error_if_addr_set:
patty_ax25_if_destroy(iface);
error_if_new: error_if_new:
error_kiss_config: error_kiss_config:
error_invalid_callsign: error_invalid_callsign:

View file

@ -81,12 +81,14 @@ typedef struct _patty_ax25_if {
patty_ax25_if_phy *phy; patty_ax25_if_phy *phy;
} patty_ax25_if; } patty_ax25_if;
patty_ax25_if *patty_ax25_if_new(patty_ax25_addr *addr, patty_ax25_if *patty_ax25_if_new(patty_ax25_if_driver *driver,
patty_ax25_if_driver *driver,
patty_ax25_if_info *info); patty_ax25_if_info *info);
void patty_ax25_if_destroy(patty_ax25_if *iface); void patty_ax25_if_destroy(patty_ax25_if *iface);
int patty_ax25_if_addr_set(patty_ax25_if *iface,
patty_ax25_addr *addr);
int patty_ax25_if_addr_each(patty_ax25_if *iface, int patty_ax25_if_addr_each(patty_ax25_if *iface,
int (*callback)(patty_ax25_addr *, void *), int (*callback)(patty_ax25_addr *, void *),
void *ctx); void *ctx);

View file

@ -7,17 +7,10 @@
#include <patty/ax25.h> #include <patty/ax25.h>
#include <patty/kiss.h> #include <patty/kiss.h>
patty_ax25_if *patty_ax25_if_new(patty_ax25_addr *addr, patty_ax25_if *patty_ax25_if_new(patty_ax25_if_driver *driver,
patty_ax25_if_driver *driver,
patty_ax25_if_info *info) { patty_ax25_if_info *info) {
patty_ax25_if *iface; patty_ax25_if *iface;
if (addr->callsign[0] == '\0') {
errno = EINVAL;
goto error_invalid_address;
}
if ((iface = malloc(sizeof(*iface))) == NULL) { if ((iface = malloc(sizeof(*iface))) == NULL) {
goto error_malloc_iface; goto error_malloc_iface;
} }
@ -56,8 +49,6 @@ patty_ax25_if *patty_ax25_if_new(patty_ax25_addr *addr,
goto error_dict_new_promisc_fds; goto error_dict_new_promisc_fds;
} }
memcpy(&iface->addr, addr, sizeof(iface->addr));
return iface; return iface;
error_dict_new_promisc_fds: error_dict_new_promisc_fds:
@ -76,10 +67,14 @@ error_phy_create:
free(iface); free(iface);
error_malloc_iface: error_malloc_iface:
error_invalid_address:
return NULL; return NULL;
} }
int patty_ax25_if_addr_set(patty_ax25_if *iface,
patty_ax25_addr *addr) {
return patty_ax25_addr_copy(&iface->addr, addr, 0);
}
void patty_ax25_if_destroy(patty_ax25_if *iface) { void patty_ax25_if_destroy(patty_ax25_if *iface) {
if (iface->driver->destroy) { if (iface->driver->destroy) {
iface->driver->destroy(iface->phy); iface->driver->destroy(iface->phy);