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

View File

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