Update mud and use argz_addr()

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2018-02-15 19:04:05 +00:00
parent 40c6e3bc40
commit 7ba60a5b61
8 changed files with 98 additions and 80 deletions

View File

@@ -6,6 +6,35 @@
#include <sys/socket.h>
#include <dirent.h>
#include <sys/un.h>
#include <arpa/inet.h>
static unsigned short
gt_ss_port(struct sockaddr_storage *ss)
{
switch (ss->ss_family) {
case AF_INET:
return ntohs(((struct sockaddr_in *)ss)->sin_port);
case AF_INET6:
return ntohs(((struct sockaddr_in6 *)ss)->sin6_port);
}
return 0;
}
static int
gt_ss_addr(char *str, size_t size, struct sockaddr_storage *ss)
{
switch (ss->ss_family) {
case AF_INET:
return -!inet_ntop(AF_INET,
&((struct sockaddr_in *)ss)->sin_addr, str, size);
case AF_INET6:
return -!inet_ntop(AF_INET6,
&((struct sockaddr_in6 *)ss)->sin6_addr, str, size);
}
return -1;
}
static int
gt_show_tunnel(int fd, const char *dev)
@@ -28,39 +57,37 @@ gt_show_tunnel(int fd, const char *dev)
if (reply.type != CTL_STATUS_REPLY)
return -1;
if (str_empty(reply.status.addr)) {
char bindstr[INET6_ADDRSTRLEN] = {0};
char peerstr[INET6_ADDRSTRLEN] = {0};
if (gt_ss_addr(bindstr, sizeof(bindstr), &reply.status.bind) ||
gt_ss_addr(peerstr, sizeof(peerstr), &reply.status.peer))
return -1;
if (reply.status.peer.ss_family == 0) {
printf("server %s:\n"
" bind: %s port %hu\n"
" mtu: %zu\n"
" auto mtu: %s\n"
" bind port: %hu\n"
" cipher: %s\n"
" ipv4: %s\n"
" ipv6: %s\n",
" cipher: %s\n",
dev,
bindstr, gt_ss_port(&reply.status.bind),
reply.status.mtu,
reply.status.mtu_auto ? "enabled" : "disabled",
reply.status.bind_port,
reply.status.chacha ? "chacha20poly1305" : "aes256gcm",
reply.status.ipv4 ? "enabled" : "disabled",
reply.status.ipv6 ? "enabled" : "disabled");
reply.status.chacha ? "chacha20poly1305" : "aes256gcm");
} else {
printf("client %s:\n"
" host: %s\n"
" port: %hu\n"
" bind: %s port %hu\n"
" peer: %s port %hu\n"
" mtu: %zu\n"
" auto mtu: %s\n"
" bind port: %hu\n"
" cipher: %s\n"
" ipv4: %s\n"
" ipv6: %s\n",
" cipher: %s\n",
dev,
reply.status.addr, reply.status.port,
bindstr, gt_ss_port(&reply.status.bind),
peerstr, gt_ss_port(&reply.status.peer),
reply.status.mtu,
reply.status.mtu_auto ? "enabled" : "disabled",
reply.status.bind_port,
reply.status.chacha ? "chacha20poly1305" : "aes256gcm",
reply.status.ipv4 ? "enabled" : "disabled",
reply.status.ipv6 ? "enabled" : "disabled");
reply.status.chacha ? "chacha20poly1305" : "aes256gcm");
}
return 0;