]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
fix(report): show hop errors in report outputs 613/head
authorDarafei Praliaskouski <me@komzpa.net>
Thu, 7 May 2026 22:19:27 +0000 (02:19 +0400)
committerDarafei Praliaskouski <me@komzpa.net>
Fri, 8 May 2026 03:21:33 +0000 (07:21 +0400)
ui/display.h
ui/report.c

index bfe1aa3616686aa6ef505d65b381f11238de0485..cafcca4b00f72ed01b49811bf9d8a27653f5269c 100644 (file)
@@ -88,6 +88,8 @@ extern void display_rawhost(
     struct mplslen *mpls);
 extern int display_keyaction(
     struct mtr_ctl *ctl);
+extern char *host_error_to_string(
+    int err);
 extern void display_loop(
     struct mtr_ctl *ctl);
 extern void display_clear(
index 4b03c0d78afab2985d217b138d2fe847b0294a2c..9c1c72afe8438b2ada9ff7ac523513b62e0accc5 100644 (file)
@@ -40,6 +40,7 @@
 #include "net.h"
 #include "dns.h"
 #include "asn.h"
+#include "display.h"
 #include "utils.h"
 
 #define MAXLOADBAL 5
@@ -75,6 +76,22 @@ static size_t snprint_addr(
         return snprintf(dst, dst_len, "%s", "???");
 }
 
+static size_t snprint_hop_name(
+    struct mtr_ctl *ctl,
+    char *dst,
+    size_t dst_len,
+    int at,
+    ip_t *addr)
+{
+    int err = net_err(at);
+
+    if (err != 0) {
+        return snprintf(dst, dst_len, "(%s)", host_error_to_string(err));
+    }
+
+    return snprint_addr(ctl, dst, dst_len, addr);
+}
+
 
 #ifdef HAVE_IPINFO
 static void print_mpls(
@@ -112,7 +129,7 @@ void report_close(
         for (; at < max; at++) {
             size_t nlen;
             addr = net_addr(at);
-            if ((nlen = snprint_addr(ctl, name, sizeof(name), addr)))
+            if ((nlen = snprint_hop_name(ctl, name, sizeof(name), at, addr)))
                 if (len_hosts < nlen)
                     len_hosts = nlen;
         }
@@ -150,7 +167,7 @@ void report_close(
     for (; at < max; at++) {
         addr = net_addr(at);
         mpls = net_mpls(at);
-        snprint_addr(ctl, name, sizeof(name), addr);
+        snprint_hop_name(ctl, name, sizeof(name), at, addr);
 
 #ifdef HAVE_IPINFO
         if (is_printii(ctl)) {
@@ -337,7 +354,7 @@ void json_close(struct mtr_ctl *ctl)
     at = net_min(ctl);
     for (; at < max; at++) {
         addr = net_addr(at);
-        snprint_addr(ctl, name, sizeof(name), addr);
+        snprint_hop_name(ctl, name, sizeof(name), at, addr);
 
         jh = json_pack("{si ss}", "count", at + 1, "host", name);
         if (!jh)
@@ -484,7 +501,7 @@ void csv_close(
     at = net_min(ctl);
     for (; at < max; at++) {
         addr = net_addr(at);
-        snprint_addr(ctl, name, sizeof(name), addr);
+        snprint_hop_name(ctl, name, sizeof(name), at, addr);
 
         if (at == net_min(ctl)) {
             printf("Mtr_Version,Start_Time,Status,Host,Hop,Ip,");