Commands show and path now support pipe output

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2018-06-15 17:38:51 +00:00
parent 41f66e55bc
commit c15343f8f6
2 changed files with 70 additions and 38 deletions

View File

@@ -4,6 +4,7 @@
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
#include "../argz/argz.h"
@@ -17,6 +18,8 @@ gt_path_status(int fd)
if (send(fd, &req, sizeof(struct ctl_msg), 0) == -1)
return -1;
int term = isatty(1);
do {
if (recv(fd, &res, sizeof(struct ctl_msg), 0) == -1)
return -1;
@@ -47,7 +50,7 @@ gt_path_status(int fd)
default: return -2;
}
printf("path %s\n"
printf(term ? "path %s\n"
" bind: %s port %"PRIu16"\n"
" public: %s port %"PRIu16"\n"
" peer: %s port %"PRIu16"\n"
@@ -57,7 +60,20 @@ gt_path_status(int fd)
" upload: %"PRIu64" bytes/s (max: %"PRIu64")\n"
" download: %"PRIu64" bytes/s (max: %"PRIu64")\n"
" output: %"PRIu64" packets\n"
" input: %"PRIu64" packets\n",
" input: %"PRIu64" packets\n"
: "path %s"
" %s %"PRIu16
" %s %"PRIu16
" %s %"PRIu16
" %zu"
" %.3f %.3f"
" %"PRIu64
" %"PRIu64
" %"PRIu64
" %"PRIu64
" %"PRIu64
" %"PRIu64
"\n",
statestr,
bindstr[0] ? bindstr : "-",
gt_get_port((struct sockaddr *)&res.path_status.local_addr),

View File

@@ -9,6 +9,7 @@
#include <dirent.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <unistd.h>
static int
gt_show_dev_status(int fd, const char *dev)
@@ -27,12 +28,20 @@ gt_show_dev_status(int fd, const char *dev)
int server = gt_toaddr(peerstr, sizeof(peerstr),
(struct sockaddr *)&res.status.peer);
int term = isatty(1);
if (server) {
printf("server %s:\n"
printf(term ? "server %s:\n"
" pid: %li\n"
" bind: %s port %"PRIu16"\n"
" mtu: %zu\n"
" cipher: %s\n",
" cipher: %s\n"
: "server %s"
" %li"
" %s %"PRIu16
" %zu"
" %s"
"\n",
dev,
res.status.pid,
bindstr[0] ? bindstr : "-",
@@ -40,12 +49,19 @@ gt_show_dev_status(int fd, const char *dev)
res.status.mtu,
res.status.chacha ? "chacha20poly1305" : "aes256gcm");
} else {
printf("client %s:\n"
printf(term ? "client %s:\n"
" pid: %li\n"
" bind: %s port %"PRIu16"\n"
" peer: %s port %"PRIu16"\n"
" mtu: %zu\n"
" cipher: %s\n",
" cipher: %s\n"
: "client %s"
" %li"
" %s %"PRIu16
" %s %"PRIu16
" %zu"
" %s"
"\n",
dev,
res.status.pid,
bindstr[0] ? bindstr : "-",