]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
Report secondary servers when CSV + wide report is enabled 416/head
authorgaamox@tutanota.com <gaamox@tutanota.com>
Tue, 14 Dec 2021 06:34:22 +0000 (22:34 -0800)
committergaamox@tutanota.com <gaamox@tutanota.com>
Tue, 14 Dec 2021 06:34:22 +0000 (22:34 -0800)
ui/report.c

index ee7d6d419886967e496175cbd371d01033e85621..c6add0761c75a384d09ef0d1165591c42d14a8c9 100644 (file)
@@ -470,8 +470,9 @@ void csv_close(
     struct mtr_ctl *ctl,
     time_t now)
 {
-    int i, j, at, max;
+    int i, j, at, max, z, w;
     ip_t *addr;
+    ip_t *addr2 = NULL;
     char name[MAX_FORMAT_STR];
 
     for (i = 0; i < MAXFLD; i++) {
@@ -527,5 +528,61 @@ void csv_close(
             }
         }
         printf("\n");
+        if (ctl->reportwide == 0)
+            continue;
+        
+        for (z = 0; z < MAX_PATH; z++) {
+            int found = 0;
+            addr2 = net_addrs(at, z);
+            snprint_addr(ctl, name, sizeof(name), addr2);
+            if ((addrcmp
+                    ((void *) &ctl->unspec_addr, (void *) addr2,
+                     ctl->af)) == 0) {
+                break;
+            } else if ((addrcmp
+                    ((void *) addr, (void *) addr2,
+                     ctl->af)) == 0) {
+                continue; /* Latest Host is already printed */
+            } else {
+                for (w = 0; w < z; w++)
+                    /* Ok... checking if there are ips repeated on same hop */
+                    if ((addrcmp
+                            ((void *) addr2, (void *) net_addrs(at, w),
+                             ctl->af)) == 0) {
+                        found = 1;
+                        break;
+                    }
+
+                if (!found) {
+#ifdef HAVE_IPINFO
+                    if (!ctl->ipinfo_no) {
+                        char *fmtinfo = fmt_ipinfo(ctl, addr2);
+                        fmtinfo = trim(fmtinfo, '\0');
+                        printf("MTR.%s,%lld,%s,%s,%d,%s,%s", PACKAGE_VERSION,
+                            (long long) now, "OK", ctl->Hostname, at + 1, name,
+                            fmtinfo);
+                    } else
+#endif
+                        printf("MTR.%s,%lld,%s,%s,%d,%s", PACKAGE_VERSION,
+                           (long long) now, "OK", ctl->Hostname, at + 1, name);
+
+                    /* Use values associated with the first ip discovered for this hop */
+                    for (i = 0; i < MAXFLD; i++) {
+                        j = ctl->fld_index[ctl->fld_active[i]];
+                        if (j < 0)
+                            continue;
+
+                        /* 1000.0 is a temporary hack for stats usec to ms, impacted net_loss. */
+                        if (strchr(data_fields[j].format, 'f')) {
+                            printf(",%.2f",
+                                   (double) (data_fields[j].net_xxx(at) / 1000.0));
+                        } else {
+                            printf(",%d", data_fields[j].net_xxx(at));
+                        }
+                    }
+                    printf("\n");
+                }
+            }    
+        }
     }
 }