uapi: use sockaddr union instead of sockaddr_storage
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
48f7c3522a
commit
f43b43376b
|
@ -119,7 +119,7 @@ static inline bool parse_ip(struct wgipmask *ipmask, const char *value)
|
|||
return true;
|
||||
}
|
||||
|
||||
static inline bool parse_endpoint(struct sockaddr_storage *endpoint, const char *value)
|
||||
static inline bool parse_endpoint(struct sockaddr *endpoint, const char *value)
|
||||
{
|
||||
char *mutable = strdup(value);
|
||||
char *begin, *end;
|
||||
|
@ -293,7 +293,7 @@ static bool process_line(struct config_ctx *ctx, const char *line)
|
|||
goto error;
|
||||
} else if (ctx->is_peer_section) {
|
||||
if (key_match("Endpoint"))
|
||||
ret = parse_endpoint(&peer_from_offset(ctx->buf.dev, ctx->peer_offset)->endpoint, value);
|
||||
ret = parse_endpoint(&peer_from_offset(ctx->buf.dev, ctx->peer_offset)->endpoint.addr, value);
|
||||
else if (key_match("PublicKey"))
|
||||
ret = parse_key(peer_from_offset(ctx->buf.dev, ctx->peer_offset)->public_key, value);
|
||||
else if (key_match("AllowedIPs"))
|
||||
|
@ -500,7 +500,7 @@ bool config_read_cmd(struct wgdevice **device, char *argv[], int argc)
|
|||
argv += 1;
|
||||
argc -= 1;
|
||||
} else if (!strcmp(argv[0], "endpoint") && argc >= 2 && buf.dev->num_peers) {
|
||||
if (!parse_endpoint(&peer_from_offset(buf.dev, peer_offset)->endpoint, argv[1]))
|
||||
if (!parse_endpoint(&peer_from_offset(buf.dev, peer_offset)->endpoint.addr, argv[1]))
|
||||
goto error;
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
|
|
18
src/show.c
18
src/show.c
|
@ -107,7 +107,7 @@ static char *ip(const struct wgipmask *ip)
|
|||
return buf;
|
||||
}
|
||||
|
||||
static char *endpoint(const struct sockaddr_storage *addr)
|
||||
static char *endpoint(const struct sockaddr *addr)
|
||||
{
|
||||
char host[4096 + 1];
|
||||
char service[512 + 1];
|
||||
|
@ -116,16 +116,16 @@ static char *endpoint(const struct sockaddr_storage *addr)
|
|||
socklen_t addr_len = 0;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
if (addr->ss_family == AF_INET)
|
||||
if (addr->sa_family == AF_INET)
|
||||
addr_len = sizeof(struct sockaddr_in);
|
||||
else if (addr->ss_family == AF_INET6)
|
||||
else if (addr->sa_family == AF_INET6)
|
||||
addr_len = sizeof(struct sockaddr_in6);
|
||||
|
||||
ret = getnameinfo((struct sockaddr *)addr, addr_len, host, sizeof(host), service, sizeof(service), NI_DGRAM | NI_NUMERICSERV | NI_NUMERICHOST);
|
||||
ret = getnameinfo(addr, addr_len, host, sizeof(host), service, sizeof(service), NI_DGRAM | NI_NUMERICSERV | NI_NUMERICHOST);
|
||||
if (ret)
|
||||
strncpy(buf, gai_strerror(ret), sizeof(buf) - 1);
|
||||
else
|
||||
snprintf(buf, sizeof(buf) - 1, (addr->ss_family == AF_INET6 && strchr(host, ':')) ? "[%s]:%s" : "%s:%s", host, service);
|
||||
snprintf(buf, sizeof(buf) - 1, (addr->sa_family == AF_INET6 && strchr(host, ':')) ? "[%s]:%s" : "%s:%s", host, service);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -228,8 +228,8 @@ static void pretty_print(struct wgdevice *device)
|
|||
}
|
||||
for_each_wgpeer(device, peer, i) {
|
||||
terminal_printf(TERMINAL_FG_YELLOW TERMINAL_BOLD "peer" TERMINAL_RESET ": " TERMINAL_FG_YELLOW "%s" TERMINAL_RESET "\n", key(peer->public_key));
|
||||
if (peer->endpoint.ss_family == AF_INET || peer->endpoint.ss_family == AF_INET6)
|
||||
terminal_printf(" " TERMINAL_BOLD "endpoint" TERMINAL_RESET ": %s\n", endpoint(&peer->endpoint));
|
||||
if (peer->endpoint.addr.sa_family == AF_INET || peer->endpoint.addr.sa_family == AF_INET6)
|
||||
terminal_printf(" " TERMINAL_BOLD "endpoint" TERMINAL_RESET ": %s\n", endpoint(&peer->endpoint.addr));
|
||||
terminal_printf(" " TERMINAL_BOLD "allowed ips" TERMINAL_RESET ": ");
|
||||
if (peer->num_ipmasks) {
|
||||
for_each_wgipmask(peer, ipmask, j)
|
||||
|
@ -276,8 +276,8 @@ static bool ugly_print(struct wgdevice *device, const char *param, bool with_int
|
|||
printf("%s\t", device->interface);
|
||||
for_each_wgpeer(device, peer, i) {
|
||||
printf("%s\t", key(peer->public_key));
|
||||
if (peer->endpoint.ss_family == AF_INET || peer->endpoint.ss_family == AF_INET6)
|
||||
printf("%s\n", endpoint(&peer->endpoint));
|
||||
if (peer->endpoint.addr.sa_family == AF_INET || peer->endpoint.addr.sa_family == AF_INET6)
|
||||
printf("%s\n", endpoint(&peer->endpoint.addr));
|
||||
else
|
||||
printf("(none)\n");
|
||||
}
|
||||
|
|
|
@ -75,18 +75,18 @@ int showconf_main(int argc, char *argv[])
|
|||
if (peer->num_ipmasks)
|
||||
printf("\n");
|
||||
|
||||
if (peer->endpoint.ss_family == AF_INET || peer->endpoint.ss_family == AF_INET6) {
|
||||
if (peer->endpoint.addr.sa_family == AF_INET || peer->endpoint.addr.sa_family == AF_INET6) {
|
||||
char host[4096 + 1];
|
||||
char service[512 + 1];
|
||||
static char buf[sizeof(host) + sizeof(service) + 4];
|
||||
socklen_t addr_len = 0;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
if (peer->endpoint.ss_family == AF_INET)
|
||||
if (peer->endpoint.addr.sa_family == AF_INET)
|
||||
addr_len = sizeof(struct sockaddr_in);
|
||||
else if (peer->endpoint.ss_family == AF_INET6)
|
||||
else if (peer->endpoint.addr.sa_family == AF_INET6)
|
||||
addr_len = sizeof(struct sockaddr_in6);
|
||||
if (!getnameinfo((struct sockaddr *)&peer->endpoint, addr_len, host, sizeof(host), service, sizeof(service), NI_DGRAM | NI_NUMERICSERV | NI_NUMERICHOST)) {
|
||||
snprintf(buf, sizeof(buf) - 1, (peer->endpoint.ss_family == AF_INET6 && strchr(host, ':')) ? "[%s]:%s" : "%s:%s", host, service);
|
||||
if (!getnameinfo(&peer->endpoint.addr, addr_len, host, sizeof(host), service, sizeof(service), NI_DGRAM | NI_NUMERICSERV | NI_NUMERICHOST)) {
|
||||
snprintf(buf, sizeof(buf) - 1, (peer->endpoint.addr.sa_family == AF_INET6 && strchr(host, ':')) ? "[%s]:%s" : "%s:%s", host, service);
|
||||
printf("Endpoint = %s\n", buf);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue