Commands show and path now support pipe output
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
70
src/path.c
70
src/path.c
@@ -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,33 +50,46 @@ gt_path_status(int fd)
|
||||
default: return -2;
|
||||
}
|
||||
|
||||
printf("path %s\n"
|
||||
" bind: %s port %"PRIu16"\n"
|
||||
" public: %s port %"PRIu16"\n"
|
||||
" peer: %s port %"PRIu16"\n"
|
||||
" mtu: %zu bytes\n"
|
||||
" rtt: %.3f ms\n"
|
||||
" rttvar: %.3f ms\n"
|
||||
" upload: %"PRIu64" bytes/s (max: %"PRIu64")\n"
|
||||
" download: %"PRIu64" bytes/s (max: %"PRIu64")\n"
|
||||
" output: %"PRIu64" packets\n"
|
||||
" input: %"PRIu64" packets\n",
|
||||
statestr,
|
||||
bindstr[0] ? bindstr : "-",
|
||||
gt_get_port((struct sockaddr *)&res.path_status.local_addr),
|
||||
publstr[0] ? publstr : "-",
|
||||
gt_get_port((struct sockaddr *)&res.path_status.r_addr),
|
||||
peerstr[0] ? peerstr : "-",
|
||||
gt_get_port((struct sockaddr *)&res.path_status.addr),
|
||||
res.path_status.mtu.ok,
|
||||
res.path_status.rtt/(double)1e3,
|
||||
res.path_status.rttvar/(double)1e3,
|
||||
res.path_status.r_rate,
|
||||
res.path_status.r_ratemax,
|
||||
res.path_status.recv.rate,
|
||||
res.path_status.recv.ratemax,
|
||||
res.path_status.send.total,
|
||||
res.path_status.recv.total);
|
||||
printf(term ? "path %s\n"
|
||||
" bind: %s port %"PRIu16"\n"
|
||||
" public: %s port %"PRIu16"\n"
|
||||
" peer: %s port %"PRIu16"\n"
|
||||
" mtu: %zu bytes\n"
|
||||
" rtt: %.3f ms\n"
|
||||
" rttvar: %.3f ms\n"
|
||||
" upload: %"PRIu64" bytes/s (max: %"PRIu64")\n"
|
||||
" download: %"PRIu64" bytes/s (max: %"PRIu64")\n"
|
||||
" output: %"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),
|
||||
publstr[0] ? publstr : "-",
|
||||
gt_get_port((struct sockaddr *)&res.path_status.r_addr),
|
||||
peerstr[0] ? peerstr : "-",
|
||||
gt_get_port((struct sockaddr *)&res.path_status.addr),
|
||||
res.path_status.mtu.ok,
|
||||
res.path_status.rtt/(double)1e3,
|
||||
res.path_status.rttvar/(double)1e3,
|
||||
res.path_status.r_rate,
|
||||
res.path_status.r_ratemax,
|
||||
res.path_status.recv.rate,
|
||||
res.path_status.recv.ratemax,
|
||||
res.path_status.send.total,
|
||||
res.path_status.recv.total);
|
||||
} while (res.ret == EAGAIN);
|
||||
|
||||
return 0;
|
||||
|
||||
38
src/show.c
38
src/show.c
@@ -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"
|
||||
" pid: %li\n"
|
||||
" bind: %s port %"PRIu16"\n"
|
||||
" mtu: %zu\n"
|
||||
" cipher: %s\n",
|
||||
printf(term ? "server %s:\n"
|
||||
" pid: %li\n"
|
||||
" bind: %s port %"PRIu16"\n"
|
||||
" mtu: %zu\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"
|
||||
" pid: %li\n"
|
||||
" bind: %s port %"PRIu16"\n"
|
||||
" peer: %s port %"PRIu16"\n"
|
||||
" mtu: %zu\n"
|
||||
" cipher: %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"
|
||||
: "client %s"
|
||||
" %li"
|
||||
" %s %"PRIu16
|
||||
" %s %"PRIu16
|
||||
" %zu"
|
||||
" %s"
|
||||
"\n",
|
||||
dev,
|
||||
res.status.pid,
|
||||
bindstr[0] ? bindstr : "-",
|
||||
|
||||
Reference in New Issue
Block a user