mtr/ui/report.c

589 lines
18 KiB
C
Raw Normal View History

mtr v0.21 v0.21 - mtr now drops root permissions after it acquires the raw sockets it needs. - mtr should be a bit happier about building under SCO and Solaris. - Fixed the problem with packets arriving after a reset. v0.20 - The build process for mtr now uses automake. - Fixed a build problem for Irix. - Now uses non-blocking DNS code, so mtr can attempt to do reverse lookup on multiple hosts at once. - Fewer packets are sent out each cycle, so mtr doesn't hog quite so much bandwidth. v0.19 - Fixed a type-o in curses.c v0.18 - Fixed the network code to work properly under FreeBSD. - Hopefully this will fix some other operating systems too. - Also, fixed a build problem and the DNS hanging bug. v0.17 - Fixed the configure script to always like with the math library. Added an icon. v0.16 - Added one #include to select.c. Some people were unable to build mtr without this line. v0.15 - Both the build process and the networking code have been cleaned up and reorganized. mtr now builds cleanly with GTK+ 0.99.8. 2002-03-06 Cougar <cougar@random.ee> - If hop doesn't respond, draw its name in red (GTK) or bold (curses) 2002-02-09 Bohdan Vlasyuk <bohdan@vstu.edu.ua> - Added --address option to bind to given IP addess 2001-04-15 Alan Eldridge <alane@geeksrus.net> - Added this file so that automake won't complain. Commented out the test for res_init in configure.in; it does not work for GLIBC2 systems (e.g., RedHat 7+). - Fixed the subordinate CHECK_LIBS on the test for res_mkquery, so that they test for res_mkquery, not res_init. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.21.tar.gz
1998-10-17 00:00:00 +00:00
/*
mtr -- a network diagnostic tool
Copyright (C) 1997,1998 Matt Kimball
This program is free software; you can redistribute it and/or modify
2017-06-02 06:30:58 +00:00
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
mtr v0.21 v0.21 - mtr now drops root permissions after it acquires the raw sockets it needs. - mtr should be a bit happier about building under SCO and Solaris. - Fixed the problem with packets arriving after a reset. v0.20 - The build process for mtr now uses automake. - Fixed a build problem for Irix. - Now uses non-blocking DNS code, so mtr can attempt to do reverse lookup on multiple hosts at once. - Fewer packets are sent out each cycle, so mtr doesn't hog quite so much bandwidth. v0.19 - Fixed a type-o in curses.c v0.18 - Fixed the network code to work properly under FreeBSD. - Hopefully this will fix some other operating systems too. - Also, fixed a build problem and the DNS hanging bug. v0.17 - Fixed the configure script to always like with the math library. Added an icon. v0.16 - Added one #include to select.c. Some people were unable to build mtr without this line. v0.15 - Both the build process and the networking code have been cleaned up and reorganized. mtr now builds cleanly with GTK+ 0.99.8. 2002-03-06 Cougar <cougar@random.ee> - If hop doesn't respond, draw its name in red (GTK) or bold (curses) 2002-02-09 Bohdan Vlasyuk <bohdan@vstu.edu.ua> - Added --address option to bind to given IP addess 2001-04-15 Alan Eldridge <alane@geeksrus.net> - Added this file so that automake won't complain. Commented out the test for res_init in configure.in; it does not work for GLIBC2 systems (e.g., RedHat 7+). - Fixed the subordinate CHECK_LIBS on the test for res_mkquery, so that they test for res_mkquery, not res_init. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.21.tar.gz
1998-10-17 00:00:00 +00:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2017-08-26 22:21:47 +00:00
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
mtr v0.21 v0.21 - mtr now drops root permissions after it acquires the raw sockets it needs. - mtr should be a bit happier about building under SCO and Solaris. - Fixed the problem with packets arriving after a reset. v0.20 - The build process for mtr now uses automake. - Fixed a build problem for Irix. - Now uses non-blocking DNS code, so mtr can attempt to do reverse lookup on multiple hosts at once. - Fewer packets are sent out each cycle, so mtr doesn't hog quite so much bandwidth. v0.19 - Fixed a type-o in curses.c v0.18 - Fixed the network code to work properly under FreeBSD. - Hopefully this will fix some other operating systems too. - Also, fixed a build problem and the DNS hanging bug. v0.17 - Fixed the configure script to always like with the math library. Added an icon. v0.16 - Added one #include to select.c. Some people were unable to build mtr without this line. v0.15 - Both the build process and the networking code have been cleaned up and reorganized. mtr now builds cleanly with GTK+ 0.99.8. 2002-03-06 Cougar <cougar@random.ee> - If hop doesn't respond, draw its name in red (GTK) or bold (curses) 2002-02-09 Bohdan Vlasyuk <bohdan@vstu.edu.ua> - Added --address option to bind to given IP addess 2001-04-15 Alan Eldridge <alane@geeksrus.net> - Added this file so that automake won't complain. Commented out the test for res_init in configure.in; it does not work for GLIBC2 systems (e.g., RedHat 7+). - Fixed the subordinate CHECK_LIBS on the test for res_mkquery, so that they test for res_mkquery, not res_init. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.21.tar.gz
1998-10-17 00:00:00 +00:00
*/
#include "config.h"
mtr v0.21 v0.21 - mtr now drops root permissions after it acquires the raw sockets it needs. - mtr should be a bit happier about building under SCO and Solaris. - Fixed the problem with packets arriving after a reset. v0.20 - The build process for mtr now uses automake. - Fixed a build problem for Irix. - Now uses non-blocking DNS code, so mtr can attempt to do reverse lookup on multiple hosts at once. - Fewer packets are sent out each cycle, so mtr doesn't hog quite so much bandwidth. v0.19 - Fixed a type-o in curses.c v0.18 - Fixed the network code to work properly under FreeBSD. - Hopefully this will fix some other operating systems too. - Also, fixed a build problem and the DNS hanging bug. v0.17 - Fixed the configure script to always like with the math library. Added an icon. v0.16 - Added one #include to select.c. Some people were unable to build mtr without this line. v0.15 - Both the build process and the networking code have been cleaned up and reorganized. mtr now builds cleanly with GTK+ 0.99.8. 2002-03-06 Cougar <cougar@random.ee> - If hop doesn't respond, draw its name in red (GTK) or bold (curses) 2002-02-09 Bohdan Vlasyuk <bohdan@vstu.edu.ua> - Added --address option to bind to given IP addess 2001-04-15 Alan Eldridge <alane@geeksrus.net> - Added this file so that automake won't complain. Commented out the test for res_init in configure.in; it does not work for GLIBC2 systems (e.g., RedHat 7+). - Fixed the subordinate CHECK_LIBS on the test for res_mkquery, so that they test for res_mkquery, not res_init. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.21.tar.gz
1998-10-17 00:00:00 +00:00
#include <sys/types.h>
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <string.h>
#include <strings.h>
2013-02-05 12:42:37 +00:00
#include <time.h>
2020-07-09 16:40:57 +00:00
#ifdef HAVE_JANSSON
#include <jansson.h>
#endif
#ifdef HAVE_ERROR_H
#include <error.h>
#else
#include "portability/error.h"
#endif
mtr v0.21 v0.21 - mtr now drops root permissions after it acquires the raw sockets it needs. - mtr should be a bit happier about building under SCO and Solaris. - Fixed the problem with packets arriving after a reset. v0.20 - The build process for mtr now uses automake. - Fixed a build problem for Irix. - Now uses non-blocking DNS code, so mtr can attempt to do reverse lookup on multiple hosts at once. - Fewer packets are sent out each cycle, so mtr doesn't hog quite so much bandwidth. v0.19 - Fixed a type-o in curses.c v0.18 - Fixed the network code to work properly under FreeBSD. - Hopefully this will fix some other operating systems too. - Also, fixed a build problem and the DNS hanging bug. v0.17 - Fixed the configure script to always like with the math library. Added an icon. v0.16 - Added one #include to select.c. Some people were unable to build mtr without this line. v0.15 - Both the build process and the networking code have been cleaned up and reorganized. mtr now builds cleanly with GTK+ 0.99.8. 2002-03-06 Cougar <cougar@random.ee> - If hop doesn't respond, draw its name in red (GTK) or bold (curses) 2002-02-09 Bohdan Vlasyuk <bohdan@vstu.edu.ua> - Added --address option to bind to given IP addess 2001-04-15 Alan Eldridge <alane@geeksrus.net> - Added this file so that automake won't complain. Commented out the test for res_init in configure.in; it does not work for GLIBC2 systems (e.g., RedHat 7+). - Fixed the subordinate CHECK_LIBS on the test for res_mkquery, so that they test for res_mkquery, not res_init. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.21.tar.gz
1998-10-17 00:00:00 +00:00
#include "mtr.h"
mtr v0.21 v0.21 - mtr now drops root permissions after it acquires the raw sockets it needs. - mtr should be a bit happier about building under SCO and Solaris. - Fixed the problem with packets arriving after a reset. v0.20 - The build process for mtr now uses automake. - Fixed a build problem for Irix. - Now uses non-blocking DNS code, so mtr can attempt to do reverse lookup on multiple hosts at once. - Fewer packets are sent out each cycle, so mtr doesn't hog quite so much bandwidth. v0.19 - Fixed a type-o in curses.c v0.18 - Fixed the network code to work properly under FreeBSD. - Hopefully this will fix some other operating systems too. - Also, fixed a build problem and the DNS hanging bug. v0.17 - Fixed the configure script to always like with the math library. Added an icon. v0.16 - Added one #include to select.c. Some people were unable to build mtr without this line. v0.15 - Both the build process and the networking code have been cleaned up and reorganized. mtr now builds cleanly with GTK+ 0.99.8. 2002-03-06 Cougar <cougar@random.ee> - If hop doesn't respond, draw its name in red (GTK) or bold (curses) 2002-02-09 Bohdan Vlasyuk <bohdan@vstu.edu.ua> - Added --address option to bind to given IP addess 2001-04-15 Alan Eldridge <alane@geeksrus.net> - Added this file so that automake won't complain. Commented out the test for res_init in configure.in; it does not work for GLIBC2 systems (e.g., RedHat 7+). - Fixed the subordinate CHECK_LIBS on the test for res_mkquery, so that they test for res_mkquery, not res_init. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.21.tar.gz
1998-10-17 00:00:00 +00:00
#include "report.h"
#include "net.h"
#include "dns.h"
#include "asn.h"
#include "utils.h"
mtr v0.21 v0.21 - mtr now drops root permissions after it acquires the raw sockets it needs. - mtr should be a bit happier about building under SCO and Solaris. - Fixed the problem with packets arriving after a reset. v0.20 - The build process for mtr now uses automake. - Fixed a build problem for Irix. - Now uses non-blocking DNS code, so mtr can attempt to do reverse lookup on multiple hosts at once. - Fewer packets are sent out each cycle, so mtr doesn't hog quite so much bandwidth. v0.19 - Fixed a type-o in curses.c v0.18 - Fixed the network code to work properly under FreeBSD. - Hopefully this will fix some other operating systems too. - Also, fixed a build problem and the DNS hanging bug. v0.17 - Fixed the configure script to always like with the math library. Added an icon. v0.16 - Added one #include to select.c. Some people were unable to build mtr without this line. v0.15 - Both the build process and the networking code have been cleaned up and reorganized. mtr now builds cleanly with GTK+ 0.99.8. 2002-03-06 Cougar <cougar@random.ee> - If hop doesn't respond, draw its name in red (GTK) or bold (curses) 2002-02-09 Bohdan Vlasyuk <bohdan@vstu.edu.ua> - Added --address option to bind to given IP addess 2001-04-15 Alan Eldridge <alane@geeksrus.net> - Added this file so that automake won't complain. Commented out the test for res_init in configure.in; it does not work for GLIBC2 systems (e.g., RedHat 7+). - Fixed the subordinate CHECK_LIBS on the test for res_mkquery, so that they test for res_mkquery, not res_init. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.21.tar.gz
1998-10-17 00:00:00 +00:00
#define MAXLOADBAL 5
#define MAX_FORMAT_STR 320
mtr v0.21 v0.21 - mtr now drops root permissions after it acquires the raw sockets it needs. - mtr should be a bit happier about building under SCO and Solaris. - Fixed the problem with packets arriving after a reset. v0.20 - The build process for mtr now uses automake. - Fixed a build problem for Irix. - Now uses non-blocking DNS code, so mtr can attempt to do reverse lookup on multiple hosts at once. - Fewer packets are sent out each cycle, so mtr doesn't hog quite so much bandwidth. v0.19 - Fixed a type-o in curses.c v0.18 - Fixed the network code to work properly under FreeBSD. - Hopefully this will fix some other operating systems too. - Also, fixed a build problem and the DNS hanging bug. v0.17 - Fixed the configure script to always like with the math library. Added an icon. v0.16 - Added one #include to select.c. Some people were unable to build mtr without this line. v0.15 - Both the build process and the networking code have been cleaned up and reorganized. mtr now builds cleanly with GTK+ 0.99.8. 2002-03-06 Cougar <cougar@random.ee> - If hop doesn't respond, draw its name in red (GTK) or bold (curses) 2002-02-09 Bohdan Vlasyuk <bohdan@vstu.edu.ua> - Added --address option to bind to given IP addess 2001-04-15 Alan Eldridge <alane@geeksrus.net> - Added this file so that automake won't complain. Commented out the test for res_init in configure.in; it does not work for GLIBC2 systems (e.g., RedHat 7+). - Fixed the subordinate CHECK_LIBS on the test for res_mkquery, so that they test for res_mkquery, not res_init. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.21.tar.gz
1998-10-17 00:00:00 +00:00
void report_open(
void)
2013-02-05 12:42:37 +00:00
{
const time_t now = time(NULL);
const char *t = iso_time(&now);
2016-08-16 12:40:19 +00:00
printf("Start: %s\n", t);
}
static size_t snprint_addr(
struct mtr_ctl *ctl,
char *dst,
size_t dst_len,
ip_t * addr)
{
if (addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) {
struct hostent *host =
ctl->dns ? addr2host((void *) addr, ctl->af) : NULL;
if (!host)
2021-04-03 22:14:52 +00:00
return snprintf(dst, dst_len, "%s", strlongip(ctl->af, addr));
else if (ctl->dns && ctl->show_ips)
return snprintf(dst, dst_len, "%s (%s)", host->h_name,
2021-04-03 22:14:52 +00:00
strlongip(ctl->af, addr));
else
return snprintf(dst, dst_len, "%s", host->h_name);
} else
return snprintf(dst, dst_len, "%s", "???");
}
#ifdef HAVE_IPINFO
static void print_mpls(
struct mplslen *mpls)
{
int k;
for (k = 0; k < mpls->labels; k++)
printf(" [MPLS: Lbl %lu TC %u S %cu TTL %u]\n",
mpls->label[k], mpls->tc[k], mpls->s[k], mpls->ttl[k]);
}
#endif
void report_close(
struct mtr_ctl *ctl)
{
int i, j, at, max, z, w;
struct mplslen *mpls, *mplss;
ip_t *addr;
ip_t *addr2 = NULL;
char name[MAX_FORMAT_STR];
char buf[1024];
char fmt[16];
size_t len = 0;
size_t len_hosts = 33;
2016-10-04 16:00:34 +00:00
#ifdef HAVE_IPINFO
int len_tmp;
const size_t iiwidth_len = get_iiwidth_len();
2016-10-04 16:00:34 +00:00
#endif
mtr v0.21 v0.21 - mtr now drops root permissions after it acquires the raw sockets it needs. - mtr should be a bit happier about building under SCO and Solaris. - Fixed the problem with packets arriving after a reset. v0.20 - The build process for mtr now uses automake. - Fixed a build problem for Irix. - Now uses non-blocking DNS code, so mtr can attempt to do reverse lookup on multiple hosts at once. - Fewer packets are sent out each cycle, so mtr doesn't hog quite so much bandwidth. v0.19 - Fixed a type-o in curses.c v0.18 - Fixed the network code to work properly under FreeBSD. - Hopefully this will fix some other operating systems too. - Also, fixed a build problem and the DNS hanging bug. v0.17 - Fixed the configure script to always like with the math library. Added an icon. v0.16 - Added one #include to select.c. Some people were unable to build mtr without this line. v0.15 - Both the build process and the networking code have been cleaned up and reorganized. mtr now builds cleanly with GTK+ 0.99.8. 2002-03-06 Cougar <cougar@random.ee> - If hop doesn't respond, draw its name in red (GTK) or bold (curses) 2002-02-09 Bohdan Vlasyuk <bohdan@vstu.edu.ua> - Added --address option to bind to given IP addess 2001-04-15 Alan Eldridge <alane@geeksrus.net> - Added this file so that automake won't complain. Commented out the test for res_init in configure.in; it does not work for GLIBC2 systems (e.g., RedHat 7+). - Fixed the subordinate CHECK_LIBS on the test for res_mkquery, so that they test for res_mkquery, not res_init. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.21.tar.gz
1998-10-17 00:00:00 +00:00
if (ctl->reportwide) {
/* get the longest hostname */
len_hosts = strlen(ctl->LocalHostname);
max = net_max(ctl);
at = net_min(ctl);
for (; at < max; at++) {
size_t nlen;
addr = net_addr(at);
if ((nlen = snprint_addr(ctl, name, sizeof(name), addr)))
if (len_hosts < nlen)
len_hosts = nlen;
}
}
#ifdef HAVE_IPINFO
len_tmp = len_hosts;
if (ctl->ipinfo_no >= 0 && iiwidth_len) {
ctl->ipinfo_no %= iiwidth_len;
if (ctl->reportwide) {
len_hosts++; /* space */
len_tmp += get_iiwidth(ctl->ipinfo_no);
if (!ctl->ipinfo_no)
len_tmp += 2; /* align header: AS */
}
}
snprintf(fmt, sizeof(fmt), "HOST: %%-%ds", len_tmp);
#else
snprintf(fmt, sizeof(fmt), "HOST: %%-%zus", len_hosts);
#endif
snprintf(buf, sizeof(buf), fmt, ctl->LocalHostname);
len = ctl->reportwide ? strlen(buf) : len_hosts;
for (i = 0; i < MAXFLD; i++) {
j = ctl->fld_index[ctl->fld_active[i]];
if (j < 0)
continue;
snprintf(fmt, sizeof(fmt), "%%%ds", data_fields[j].length);
2023-04-11 14:05:36 +00:00
snprintf(buf + len, sizeof(buf) - len, fmt, data_fields[j].title);
len += data_fields[j].length;
}
printf("%s\n", buf);
max = net_max(ctl);
at = net_min(ctl);
for (; at < max; at++) {
addr = net_addr(at);
mpls = net_mpls(at);
snprint_addr(ctl, name, sizeof(name), addr);
mtr v0.21 v0.21 - mtr now drops root permissions after it acquires the raw sockets it needs. - mtr should be a bit happier about building under SCO and Solaris. - Fixed the problem with packets arriving after a reset. v0.20 - The build process for mtr now uses automake. - Fixed a build problem for Irix. - Now uses non-blocking DNS code, so mtr can attempt to do reverse lookup on multiple hosts at once. - Fewer packets are sent out each cycle, so mtr doesn't hog quite so much bandwidth. v0.19 - Fixed a type-o in curses.c v0.18 - Fixed the network code to work properly under FreeBSD. - Hopefully this will fix some other operating systems too. - Also, fixed a build problem and the DNS hanging bug. v0.17 - Fixed the configure script to always like with the math library. Added an icon. v0.16 - Added one #include to select.c. Some people were unable to build mtr without this line. v0.15 - Both the build process and the networking code have been cleaned up and reorganized. mtr now builds cleanly with GTK+ 0.99.8. 2002-03-06 Cougar <cougar@random.ee> - If hop doesn't respond, draw its name in red (GTK) or bold (curses) 2002-02-09 Bohdan Vlasyuk <bohdan@vstu.edu.ua> - Added --address option to bind to given IP addess 2001-04-15 Alan Eldridge <alane@geeksrus.net> - Added this file so that automake won't complain. Commented out the test for res_init in configure.in; it does not work for GLIBC2 systems (e.g., RedHat 7+). - Fixed the subordinate CHECK_LIBS on the test for res_mkquery, so that they test for res_mkquery, not res_init. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.21.tar.gz
1998-10-17 00:00:00 +00:00
#ifdef HAVE_IPINFO
if (is_printii(ctl)) {
snprintf(fmt, sizeof(fmt), " %%2d. %%s%%-%zus", len_hosts);
snprintf(buf, sizeof(buf), fmt, at + 1, fmt_ipinfo(ctl, addr),
name);
} else {
#endif
snprintf(fmt, sizeof(fmt), " %%2d.|-- %%-%zus", len_hosts);
snprintf(buf, sizeof(buf), fmt, at + 1, name);
#ifdef HAVE_IPINFO
}
#endif
len = ctl->reportwide ? strlen(buf) : len_hosts;
for (i = 0; i < MAXFLD; i++) {
j = ctl->fld_index[ctl->fld_active[i]];
if (j < 0)
continue;
2021-09-05 13:18:53 +00:00
/* 1000.0 is a temporary hack for stats usec to ms, impacted net_loss. */
if (strchr(data_fields[j].format, 'f')) {
2023-04-11 14:05:36 +00:00
snprintf(buf + len, sizeof(buf) - len, data_fields[j].format,
data_fields[j].net_xxx(at) / 1000.0);
} else {
2023-04-11 14:05:36 +00:00
snprintf(buf + len, sizeof(buf) - len, data_fields[j].format,
data_fields[j].net_xxx(at));
}
len += data_fields[j].length;
}
printf("%s\n", buf);
/* This feature shows 'loadbalances' on routes */
/* Print list of all hosts that have responded from ttl = at + 1 away */
for (z = 0; z < ctl->maxDisplayPath; z++) {
int found = 0;
addr2 = net_addrs(at, z);
mplss = net_mplss(at, z);
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 {
snprint_addr(ctl, name, sizeof(name), addr2);
snprintf(fmt, sizeof(fmt), " %%-%zus", len_hosts);
snprintf(buf, sizeof(buf), fmt, name);
printf("%s\n", buf);
}
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 (mpls->labels && z == 1 && ctl->enablempls)
print_mpls(mpls);
if (is_printii(ctl)) {
snprint_addr(ctl, name, sizeof(name), addr2);
printf(" %s%s\n", fmt_ipinfo(ctl, addr2), name);
}
if (ctl->enablempls)
print_mpls(mplss);
#else
int k;
if (mpls->labels && z == 1 && ctl->enablempls) {
for (k = 0; k < mpls->labels; k++) {
printf
(" | |+-- [MPLS: Lbl %lu TC %u S %u TTL %u]\n",
mpls->label[k], mpls->tc[k], mpls->s[k],
mpls->ttl[k]);
}
}
if (z == 1) {
2021-04-03 22:14:52 +00:00
printf(" | `|-- %s\n", strlongip(ctl->af, addr2));
for (k = 0; k < mplss->labels && ctl->enablempls; k++) {
printf
(" | +-- [MPLS: Lbl %lu TC %u S %u TTL %u]\n",
mplss->label[k], mplss->tc[k], mplss->s[k],
mplss->ttl[k]);
}
} else {
2021-04-03 22:14:52 +00:00
printf(" | |-- %s\n", strlongip(ctl->af, addr2));
for (k = 0; k < mplss->labels && ctl->enablempls; k++) {
printf
(" | +-- [MPLS: Lbl %lu TC %u S %u TTL %u]\n",
mplss->label[k], mplss->tc[k], mplss->s[k],
mplss->ttl[k]);
}
}
#endif
}
}
/* No multipath */
#ifdef HAVE_IPINFO
if (is_printii(ctl)) {
if (mpls->labels && z == 1 && ctl->enablempls)
print_mpls(mpls);
}
#else
if (mpls->labels && z == 1 && ctl->enablempls) {
int k;
for (k = 0; k < mpls->labels; k++) {
printf(" | +-- [MPLS: Lbl %lu TC %u S %u TTL %u]\n",
mpls->label[k], mpls->tc[k], mpls->s[k],
mpls->ttl[k]);
}
}
#endif
}
}
void txt_open(
void)
{
}
void txt_close(
struct mtr_ctl *ctl)
{
report_close(ctl);
}
2020-07-09 16:40:57 +00:00
#ifdef HAVE_JANSSON
void json_open(
void)
{
}
2020-07-09 16:40:57 +00:00
void json_close(struct mtr_ctl *ctl)
{
2020-07-09 16:40:57 +00:00
int i, j, at, max;
int ret;
char buf[128];
json_t *jreport, *jmtr, *jhubs, *jh;
ip_t *addr;
char name[MAX_FORMAT_STR];
2020-07-09 16:40:57 +00:00
jmtr = json_pack("{ss ss si si}",
"src", ctl->LocalHostname,
"dst", ctl->Hostname,
"tos", ctl->tos,
"tests", ctl->MaxPing);
if (!jmtr)
goto on_error;
if (ctl->cpacketsize >= 0) {
2020-07-09 16:40:57 +00:00
snprintf(buf, sizeof(buf), "%d", ctl->cpacketsize);
} else {
2020-07-09 16:40:57 +00:00
snprintf(buf, sizeof(buf), "rand(%d-%d)", MINPACKET, -ctl->cpacketsize);
}
2020-07-09 16:40:57 +00:00
ret = json_object_set_new(jmtr, "psize", json_string(buf));
if (ret == -1)
goto on_error;
if (ctl->bitpattern >= 0) {
2020-07-09 16:40:57 +00:00
snprintf(buf, sizeof(buf), "0x%02X", (unsigned char)(ctl->bitpattern));
} else {
2020-07-09 16:40:57 +00:00
snprintf(buf, sizeof(buf), "rand(0x00-FF)");
}
2016-10-04 16:00:34 +00:00
2020-07-09 16:40:57 +00:00
ret = json_object_set_new(jmtr, "bitpattern", json_string(buf));
if (ret == -1)
goto on_error;
jhubs = json_array();
if (!jhubs)
goto on_error;
max = net_max(ctl);
2020-07-09 16:40:57 +00:00
at = net_min(ctl);
for (; at < max; at++) {
addr = net_addr(at);
snprint_addr(ctl, name, sizeof(name), addr);
2020-07-09 16:40:57 +00:00
jh = json_pack("{si ss}", "count", at + 1, "host", name);
if (!jh)
goto on_error;
2017-06-02 06:30:58 +00:00
#ifdef HAVE_IPINFO
2021-09-05 13:50:56 +00:00
if (!ctl->ipinfo_no) {
2020-07-09 16:40:57 +00:00
char* fmtinfo = fmt_ipinfo(ctl, addr);
if (fmtinfo != NULL)
fmtinfo = trim(fmtinfo, '\0');
ret = json_object_set_new(jh, "ASN", json_string(fmtinfo));
if (ret == -1)
goto on_error;
2017-06-02 06:30:58 +00:00
}
#endif
2020-07-09 16:40:57 +00:00
for (i = 0; i < MAXFLD; i++) {
j = ctl->fld_index[ctl->fld_active[i]];
if (j <= 0)
2020-07-09 16:40:57 +00:00
continue; /* Field nr 0, " " shouldn't be printed in this method. */
if (strchr(data_fields[j].format, 'f')) {
2020-07-09 16:40:57 +00:00
ret = json_object_set_new(
jh, data_fields[j].title,
json_real(data_fields[j].net_xxx(at) / 1000.0));
} else {
2020-07-09 16:40:57 +00:00
ret = json_object_set_new(
jh, data_fields[j].title,
json_integer(data_fields[j].net_xxx(at)));
}
2020-07-09 16:40:57 +00:00
if (ret == -1)
goto on_error;
}
2020-07-09 16:40:57 +00:00
ret = json_array_append_new(jhubs, jh);
if (ret == -1)
goto on_error;
}
2020-07-09 16:40:57 +00:00
jreport = json_pack("{s{so so}}", "report", "mtr", jmtr, "hubs", jhubs);
ret = json_dumpf(jreport, stdout, JSON_INDENT(4) | JSON_REAL_PRECISION(5));
if (ret == -1)
goto on_error;
2021-09-05 13:18:53 +00:00
printf("\n"); // bash prompt should be on new line
2020-07-09 16:40:57 +00:00
json_decref(jreport);
return;
on_error:
error(EXIT_FAILURE, 0, "json_close failed");
}
#endif
void xml_open(
void)
{
}
void xml_close(
struct mtr_ctl *ctl)
{
int i, j, at, max;
ip_t *addr;
char name[MAX_FORMAT_STR];
printf("<?xml version=\"1.0\"?>\n");
printf("<MTR SRC=\"%s\" DST=\"%s\"", ctl->LocalHostname,
ctl->Hostname);
printf(" TOS=\"0x%X\"", ctl->tos);
if (ctl->cpacketsize >= 0) {
printf(" PSIZE=\"%d\"", ctl->cpacketsize);
} else {
printf(" PSIZE=\"rand(%d-%d)\"", MINPACKET, -ctl->cpacketsize);
}
if (ctl->bitpattern >= 0) {
printf(" BITPATTERN=\"0x%02X\"",
(unsigned char) (ctl->bitpattern));
} else {
printf(" BITPATTERN=\"rand(0x00-FF)\"");
}
printf(" TESTS=\"%d\">\n", ctl->MaxPing);
max = net_max(ctl);
at = net_min(ctl);
for (; at < max; at++) {
addr = net_addr(at);
snprint_addr(ctl, name, sizeof(name), addr);
printf(" <HUB COUNT=\"%d\" HOST=\"%s\">\n", at + 1, name);
for (i = 0; i < MAXFLD; i++) {
const char *title;
j = ctl->fld_index[ctl->fld_active[i]];
if (j <= 0)
continue; /* Field nr 0, " " shouldn't be printed in this method. */
snprintf(name, sizeof(name), "%s%s%s", " <%s>",
data_fields[j].format, "</%s>\n");
/* XML doesn't allow "%" in tag names, rename Loss% to just Loss */
title = data_fields[j].title;
if (strcmp(data_fields[j].title, "Loss%") == 0) {
title = "Loss";
}
2021-09-05 13:18:53 +00:00
/* 1000.0 is a temporary hack for stats usec to ms, impacted net_loss. */
if (strchr(data_fields[j].format, 'f')) {
printf(name,
title, data_fields[j].net_xxx(at) / 1000.0, title);
} else {
printf(name, title, data_fields[j].net_xxx(at), title);
}
}
printf(" </HUB>\n");
}
printf("</MTR>\n");
mtr v0.21 v0.21 - mtr now drops root permissions after it acquires the raw sockets it needs. - mtr should be a bit happier about building under SCO and Solaris. - Fixed the problem with packets arriving after a reset. v0.20 - The build process for mtr now uses automake. - Fixed a build problem for Irix. - Now uses non-blocking DNS code, so mtr can attempt to do reverse lookup on multiple hosts at once. - Fewer packets are sent out each cycle, so mtr doesn't hog quite so much bandwidth. v0.19 - Fixed a type-o in curses.c v0.18 - Fixed the network code to work properly under FreeBSD. - Hopefully this will fix some other operating systems too. - Also, fixed a build problem and the DNS hanging bug. v0.17 - Fixed the configure script to always like with the math library. Added an icon. v0.16 - Added one #include to select.c. Some people were unable to build mtr without this line. v0.15 - Both the build process and the networking code have been cleaned up and reorganized. mtr now builds cleanly with GTK+ 0.99.8. 2002-03-06 Cougar <cougar@random.ee> - If hop doesn't respond, draw its name in red (GTK) or bold (curses) 2002-02-09 Bohdan Vlasyuk <bohdan@vstu.edu.ua> - Added --address option to bind to given IP addess 2001-04-15 Alan Eldridge <alane@geeksrus.net> - Added this file so that automake won't complain. Commented out the test for res_init in configure.in; it does not work for GLIBC2 systems (e.g., RedHat 7+). - Fixed the subordinate CHECK_LIBS on the test for res_mkquery, so that they test for res_mkquery, not res_init. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.21.tar.gz
1998-10-17 00:00:00 +00:00
}
void csv_open(
void)
{
}
void csv_close(
struct mtr_ctl *ctl,
time_t now)
{
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++) {
j = ctl->fld_index[ctl->fld_active[i]];
if (j < 0)
continue;
}
max = net_max(ctl);
at = net_min(ctl);
for (; at < max; at++) {
addr = net_addr(at);
snprint_addr(ctl, name, sizeof(name), addr);
if (at == net_min(ctl)) {
printf("Mtr_Version,Start_Time,Status,Host,Hop,Ip,");
#ifdef HAVE_IPINFO
if (!ctl->ipinfo_no) {
printf("Asn,");
}
#endif
for (i = 0; i < MAXFLD; i++) {
j = ctl->fld_index[ctl->fld_active[i]];
if (j < 0)
continue;
printf("%s,", data_fields[j].title);
}
printf("\n");
}
#ifdef HAVE_IPINFO
if (!ctl->ipinfo_no) {
char *fmtinfo = fmt_ipinfo(ctl, addr);
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
2013-07-05 13:45:52 +00:00
#endif
printf("MTR.%s,%lld,%s,%s,%d,%s", PACKAGE_VERSION,
(long long) now, "OK", ctl->Hostname, at + 1, name);
for (i = 0; i < MAXFLD; i++) {
j = ctl->fld_index[ctl->fld_active[i]];
if (j < 0)
continue;
2021-09-05 13:18:53 +00:00
/* 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");
if (ctl->reportwide == 0)
continue;
for (z = 0; z < ctl->maxDisplayPath; 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");
}
}
}
}
}