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:
parent
7415ef8573
commit
675e6cf727
4 changed files with 44 additions and 20 deletions
28
bin/if.c
28
bin/if.c
|
@ -44,6 +44,7 @@ static patty_ax25_if *create_kiss(struct context *ctx, int argc, char **argv) {
|
|||
enum mode_kiss mode = MODE_KISS_DEVICE;
|
||||
|
||||
patty_kiss_tnc_info info;
|
||||
patty_ax25_if *iface;
|
||||
|
||||
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,
|
||||
patty_kiss_tnc_driver(),
|
||||
&info);
|
||||
if ((iface = patty_ax25_if_new(patty_kiss_tnc_driver(),
|
||||
&info)) == NULL) {
|
||||
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:
|
||||
return NULL;
|
||||
}
|
||||
|
@ -214,8 +226,7 @@ static patty_ax25_if *create_aprs_is(struct context *ctx,
|
|||
}
|
||||
}
|
||||
|
||||
if ((iface = patty_ax25_if_new(&ctx->addr,
|
||||
patty_ax25_aprs_is_driver(),
|
||||
if ((iface = patty_ax25_if_new(patty_ax25_aprs_is_driver(),
|
||||
&info)) == NULL) {
|
||||
patty_error_fmt(ctx->err, "Unable to connect to APRS-IS service %s:%s: %s",
|
||||
info.host, info.port, strerror(errno));
|
||||
|
@ -223,8 +234,15 @@ static patty_ax25_if *create_aprs_is(struct context *ctx,
|
|||
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:
|
||||
return NULL;
|
||||
|
|
13
bin/pattyd.c
13
bin/pattyd.c
|
@ -303,8 +303,7 @@ static int handle_standalone(patty_daemon *daemon,
|
|||
goto error_kiss_config;
|
||||
}
|
||||
|
||||
if ((iface = patty_ax25_if_new(&addr,
|
||||
patty_kiss_tnc_driver(),
|
||||
if ((iface = patty_ax25_if_new(patty_kiss_tnc_driver(),
|
||||
&info)) == NULL) {
|
||||
fprintf(stderr, "%s: Unable to create network interface %s: %s\n",
|
||||
argv0, DEFAULT_IFNAME, strerror(errno));
|
||||
|
@ -314,6 +313,13 @@ static int handle_standalone(patty_daemon *daemon,
|
|||
int fd = patty_ax25_if_fd(iface);
|
||||
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) {
|
||||
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_if_add:
|
||||
error_if_addr_set:
|
||||
patty_ax25_if_destroy(iface);
|
||||
|
||||
error_if_new:
|
||||
error_kiss_config:
|
||||
error_invalid_callsign:
|
||||
|
|
|
@ -81,12 +81,14 @@ typedef struct _patty_ax25_if {
|
|||
patty_ax25_if_phy *phy;
|
||||
} patty_ax25_if;
|
||||
|
||||
patty_ax25_if *patty_ax25_if_new(patty_ax25_addr *addr,
|
||||
patty_ax25_if_driver *driver,
|
||||
patty_ax25_if *patty_ax25_if_new(patty_ax25_if_driver *driver,
|
||||
patty_ax25_if_info *info);
|
||||
|
||||
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 (*callback)(patty_ax25_addr *, void *),
|
||||
void *ctx);
|
||||
|
|
17
src/if.c
17
src/if.c
|
@ -7,17 +7,10 @@
|
|||
#include <patty/ax25.h>
|
||||
#include <patty/kiss.h>
|
||||
|
||||
patty_ax25_if *patty_ax25_if_new(patty_ax25_addr *addr,
|
||||
patty_ax25_if_driver *driver,
|
||||
patty_ax25_if *patty_ax25_if_new(patty_ax25_if_driver *driver,
|
||||
patty_ax25_if_info *info) {
|
||||
patty_ax25_if *iface;
|
||||
|
||||
if (addr->callsign[0] == '\0') {
|
||||
errno = EINVAL;
|
||||
|
||||
goto error_invalid_address;
|
||||
}
|
||||
|
||||
if ((iface = malloc(sizeof(*iface))) == NULL) {
|
||||
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;
|
||||
}
|
||||
|
||||
memcpy(&iface->addr, addr, sizeof(iface->addr));
|
||||
|
||||
return iface;
|
||||
|
||||
error_dict_new_promisc_fds:
|
||||
|
@ -76,10 +67,14 @@ error_phy_create:
|
|||
free(iface);
|
||||
|
||||
error_malloc_iface:
|
||||
error_invalid_address:
|
||||
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) {
|
||||
if (iface->driver->destroy) {
|
||||
iface->driver->destroy(iface->phy);
|
||||
|
|
Loading…
Add table
Reference in a new issue