Enable and fix many extra warnings supported by GCC and Clang.
[tinc] / src / info.c
index 09e6580..25e6b60 100644 (file)
@@ -1,6 +1,6 @@
 /*
     info.c -- Show information about a node, subnet or address
-    Copyright (C) 2012-2017 Guus Sliepen <guus@tinc-vpn.org>
+    Copyright (C) 2012-2022 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 #include "system.h"
 
 #include "control_common.h"
-#include "list.h"
+#include "info.h"
+#include "logger.h"
 #include "subnet.h"
 #include "tincctl.h"
-#include "info.h"
 #include "utils.h"
-#include "xalloc.h"
 
 void logger(int level, int priority, const char *format, ...) {
+       (void)level;
+       (void)priority;
        va_list ap;
+
        va_start(ap, format);
        vfprintf(stderr, format, ap);
        va_end(ap);
+
        fputc('\n', stderr);
 }
 
 char *strip_weight(char *netstr) {
-       int len = strlen(netstr);
+       size_t len = strlen(netstr);
 
        if(len >= 3 && !strcmp(netstr + len - 3, "#10")) {
                netstr[len - 3] = 0;
@@ -70,15 +73,17 @@ static int info_node(int fd, const char *item) {
        } status_union;
        node_status_t status;
        long int last_state_change;
+       int udp_ping_rtt;
+       uint64_t in_packets, in_bytes, out_packets, out_bytes;
 
        while(recvline(fd, line, sizeof(line))) {
-               int n = sscanf(line, "%d %d %4095s %4095s %4095s port %4095s %d %d %d %d %x %"PRIx32" %4095s %4095s %d %hd %hd %hd %ld", &code, &req, node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_union.raw, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change);
+               int n = sscanf(line, "%d %d %4095s %4095s %4095s port %4095s %d %d %d %d %x %"PRIx32" %4095s %4095s %d %hd %hd %hd %ld %d %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, &code, &req, node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_union.raw, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change, &udp_ping_rtt, &in_packets, &in_bytes, &out_packets, &out_bytes);
 
                if(n == 2) {
                        break;
                }
 
-               if(n != 19) {
+               if(n != 24) {
                        fprintf(stderr, "Unable to parse node dump from tincd.\n");
                        return 1;
                }
@@ -179,12 +184,19 @@ static int info_node(int fd, const char *item) {
                printf("unknown\n");
        } else if(minmtu > 0) {
                printf("directly with UDP\nPMTU:         %d\n", pmtu);
+
+               if(udp_ping_rtt != -1) {
+                       printf("RTT:          %d.%03d\n", udp_ping_rtt / 1000, udp_ping_rtt % 1000);
+               }
        } else if(!strcmp(nexthop, item)) {
                printf("directly with TCP\n");
        } else {
                printf("none, forwarded via %s\n", nexthop);
        }
 
+       printf("RX:           %"PRIu64" packets  %"PRIu64" bytes\n", in_packets, in_bytes);
+       printf("TX:           %"PRIu64" packets  %"PRIu64" bytes\n", out_packets, out_bytes);
+
        // List edges
        printf("Edges:       ");
        sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_EDGES, item);
@@ -286,7 +298,7 @@ static int info_subnet(int fd, const char *item) {
                                        continue;
                                }
 
-                               if(memcmp(&find.net.ipv4.address, &subnet.net.ipv4.address, sizeof(subnet.net.ipv4))) {
+                               if(memcmp(&find.net.ipv4.address, &subnet.net.ipv4.address, sizeof(subnet.net.ipv4.address))) {
                                        continue;
                                }
                        }
@@ -300,14 +312,14 @@ static int info_subnet(int fd, const char *item) {
                                        continue;
                                }
 
-                               if(memcmp(&find.net.ipv6.address, &subnet.net.ipv6.address, sizeof(subnet.net.ipv6))) {
+                               if(memcmp(&find.net.ipv6.address, &subnet.net.ipv6.address, sizeof(subnet.net.ipv6.address))) {
                                        continue;
                                }
                        }
                }
 
                if(find.type == SUBNET_MAC) {
-                       if(memcmp(&find.net.mac.address, &subnet.net.mac.address, sizeof(subnet.net.mac))) {
+                       if(memcmp(&find.net.mac.address, &subnet.net.mac.address, sizeof(subnet.net.mac.address))) {
                                continue;
                        }
                }