Commands show and path now support pipe output
Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
20
src/path.c
20
src/path.c
@@ -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),
|
||||||
|
|||||||
24
src/show.c
24
src/show.c
@@ -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 : "-",
|
||||||
|
|||||||
Reference in New Issue
Block a user