aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/tools/show.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tools/show.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/tools/show.c b/src/tools/show.c
index d315ee8..05777b1 100644
--- a/src/tools/show.c
+++ b/src/tools/show.c
@@ -23,6 +23,7 @@ static int peer_cmp(const void *first, const void *second)
{
time_t diff;
const struct wgpeer *a = *(const void **)first, *b = *(const void **)second;
+
if (!a->last_handshake_time.tv_sec && !a->last_handshake_time.tv_usec && (b->last_handshake_time.tv_sec || b->last_handshake_time.tv_usec))
return 1;
if (!b->last_handshake_time.tv_sec && !b->last_handshake_time.tv_usec && (a->last_handshake_time.tv_sec || a->last_handshake_time.tv_usec))
@@ -65,6 +66,7 @@ static void sort_peers(struct wgdevice *device)
static char *key(const uint8_t key[static WG_KEY_LEN])
{
static char base64[WG_KEY_LEN_BASE64];
+
if (key_is_zero(key))
return "(none)";
key_to_base64(base64, key);
@@ -74,6 +76,7 @@ static char *key(const uint8_t key[static WG_KEY_LEN])
static char *masked_key(const uint8_t masked_key[static WG_KEY_LEN])
{
const char *var = getenv("WG_HIDE_KEYS");
+
if (var && !strcmp(var, "never"))
return key(masked_key);
return "(hidden)";
@@ -82,6 +85,7 @@ static char *masked_key(const uint8_t masked_key[static WG_KEY_LEN])
static char *ip(const struct wgallowedip *ip)
{
static char buf[INET6_ADDRSTRLEN + 1];
+
memset(buf, 0, INET6_ADDRSTRLEN + 1);
if (ip->family == AF_INET)
inet_ntop(AF_INET, &ip->ip4, buf, INET6_ADDRSTRLEN);
@@ -161,6 +165,7 @@ static char *ago(const struct timeval *t)
static char *every(uint16_t seconds)
{
static char buf[1024] = "every ";
+
pretty_time(buf + strlen("every "), sizeof(buf) - strlen("every ") - 1, seconds);
return buf;
}
@@ -170,7 +175,7 @@ static char *bytes(uint64_t b)
static char buf[1024];
if (b < 1024ULL)
- snprintf(buf, sizeof(buf) - 1, "%u " TERMINAL_FG_CYAN "B" TERMINAL_RESET, (unsigned)b);
+ snprintf(buf, sizeof(buf) - 1, "%u " TERMINAL_FG_CYAN "B" TERMINAL_RESET, (unsigned int)b);
else if (b < 1024ULL * 1024ULL)
snprintf(buf, sizeof(buf) - 1, "%.2f " TERMINAL_FG_CYAN "KiB" TERMINAL_RESET, (double)b / 1024);
else if (b < 1024ULL * 1024ULL * 1024ULL)
@@ -183,7 +188,7 @@ static char *bytes(uint64_t b)
return buf;
}
-static const char *COMMAND_NAME = NULL;
+static const char *COMMAND_NAME;
static void show_usage(void)
{
fprintf(stderr, "Usage: %s %s { <interface> | all | interfaces } [public-key | private-key | listen-port | fwmark | peers | preshared-keys | endpoints | allowed-ips | latest-handshakes | transfer | persistent-keepalive | dump]\n", PROG_NAME, COMMAND_NAME);
@@ -275,6 +280,7 @@ static bool ugly_print(struct wgdevice *device, const char *param, bool with_int
{
struct wgpeer *peer;
struct wgallowedip *allowedip;
+
if (!strcmp(param, "public-key")) {
if (with_interface)
printf("%s\t", device->name);
@@ -362,6 +368,7 @@ static bool ugly_print(struct wgdevice *device, const char *param, bool with_int
int show_main(int argc, char *argv[])
{
int ret = 0;
+
COMMAND_NAME = argv[0];
if (argc > 3) {
@@ -371,6 +378,7 @@ int show_main(int argc, char *argv[])
if (argc == 1 || !strcmp(argv[1], "all")) {
char *interfaces = ipc_list_devices(), *interface;
+
if (!interfaces) {
perror("Unable to get devices");
return 1;
@@ -378,6 +386,7 @@ int show_main(int argc, char *argv[])
interface = interfaces;
for (size_t len = 0; (len = strlen(interface)); interface += len + 1) {
struct wgdevice *device = NULL;
+
if (ipc_get_device(&device, interface) < 0) {
perror("Unable to get device");
continue;
@@ -398,6 +407,7 @@ int show_main(int argc, char *argv[])
free(interfaces);
} else if (!strcmp(argv[1], "interfaces")) {
char *interfaces, *interface;
+
if (argc > 2) {
show_usage();
return 1;
@@ -415,6 +425,7 @@ int show_main(int argc, char *argv[])
show_usage();
else {
struct wgdevice *device = NULL;
+
if (ipc_get_device(&device, argv[1]) < 0) {
perror("Unable to get device");
return 1;