From: gaamox@tutanota.com Date: Tue, 14 Dec 2021 06:34:22 +0000 (-0800) Subject: Report secondary servers when CSV + wide report is enabled X-Git-Tag: v0.95~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F416%2Fhead;p=thirdparty%2Fmtr.git Report secondary servers when CSV + wide report is enabled --- diff --git a/ui/report.c b/ui/report.c index ee7d6d4..c6add07 100644 --- a/ui/report.c +++ b/ui/report.c @@ -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"); + } + } + } } }