From: Matt Kimball Date: Fri, 23 Dec 2016 17:56:58 +0000 (-0800) Subject: Merge branch mtr-packet into 'master' X-Git-Tag: v0.88~15^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f76affc0e58a64a4238fafe6e61241769fc205d;p=thirdparty%2Fmtr.git Merge branch mtr-packet into 'master' --- 5f76affc0e58a64a4238fafe6e61241769fc205d diff --cc mtr.c index 0f0650e,5b20335..97ad3a3 --- a/mtr.c +++ b/mtr.c @@@ -101,9 -102,11 +101,11 @@@ static void __attribute__((__noreturn__ fputs("\n", out); fputs(" -F, --filename FILE read hostname(s) from a file\n", out); fputs(" -4 use IPv4 only\n", out); + #ifdef ENABLE_IPV6 fputs(" -6 use IPv6 only\n", out); + #endif - fputs(" -u, --udp use udp instead of icmp echo\n", out); - fputs(" -T, --tcp use tcp instead of icmp echo\n", out); + fputs(" -u, --udp use UDP instead of ICMP echo\n", out); + fputs(" -T, --tcp use TCP instead of ICMP echo\n", out); fputs(" -a, --address ADDRESS bind the outgoing socket to ADDRESS\n", out); fputs(" -f, --first-ttl NUMBER set what TTL to start\n", out); fputs(" -m, --max-ttl NUMBER maximum number of hops\n", out); @@@ -116,8 -119,10 +118,10 @@@ fputs(" -G, --gracetime SECONDS number of seconds to wait for responses\n", out); fputs(" -Q, --tos NUMBER type of service field in IP header\n", out); fputs(" -e, --mpls display information from ICMP extensions\n", out); - fputs(" -Z, --timeout SECONDS seconds to keep the TCP socket open\n", out); + fputs(" -Z, --timeout SECONDS seconds to keep probe sockets open\n", out); + #ifdef SO_MARK fputs(" -M, --mark MARK mark each sent packet\n", out); + #endif fputs(" -r, --report output using report mode\n", out); fputs(" -w, --report-wide output wide report\n", out); fputs(" -c, --report-cycles COUNT set the number of pings sent\n", out); @@@ -320,10 -330,12 +329,12 @@@ static void parse_arg (struct mtr_ctl * { "max-unknown", 1, NULL, 'U' }, { "udp", 0, NULL, 'u' }, /* UDP (default is ICMP) */ { "tcp", 0, NULL, 'T' }, /* TCP (default is ICMP) */ + #ifdef HAS_SCTP { "sctp", 0, NULL, 'S' }, /* SCTP (default is ICMP) */ + #endif { "port", 1, NULL, 'P' }, /* target port number for TCP/SCTP/UDP */ { "localport", 1, NULL, 'L' }, /* source port number for UDP */ - { "timeout", 1, NULL, 'Z' }, /* timeout for TCP sockets */ + { "timeout", 1, NULL, 'Z' }, /* timeout for probe sockets */ { "gracetime", 1, NULL, 'G' }, /* gracetime for replies after last probe */ #ifdef SO_MARK { "mark", 1, NULL, 'M' }, /* use SO_MARK */ @@@ -630,8 -629,9 +627,8 @@@ extern int main(int argc, char **argv #ifdef ENABLE_IPV6 struct sockaddr_in6 * sa6; #endif - names_t *names_root = NULL; - names_t **names_head = &names_root; - time_t now; + names_t *names_head = NULL; + names_t *names_walk; struct mtr_ctl ctl; memset(&ctl, 0, sizeof(ctl)); @@@ -681,15 -688,21 +678,16 @@@ while (optind < argc) { char* name = argv[optind++]; - append_to_names(names_head, name); + append_to_names(&names_head, name); } - if (!names_root) append_to_names (names_head, "localhost"); /* default: localhost. */ - /* Now that we know mtrtype we can select which socket to use */ - if (net_selectsocket(&ctl) != 0) { - error(EXIT_FAILURE, 0, "Couldn't determine raw socket type"); - } - + /* default: localhost. */ + if (!names_head) append_to_names(&names_head, "localhost"); - names_head = &names_root; - while (*names_head != NULL) { + names_walk = names_head; + while (names_walk != NULL) { - ctl.Hostname = names_root->name; + ctl.Hostname = names_walk->name; if (gethostname(ctl.LocalHostname, sizeof(ctl.LocalHostname))) { xstrncpy(ctl.LocalHostname, "UNKNOWNHOST", sizeof(ctl.LocalHostname)); } @@@ -752,7 -775,17 +750,6 @@@ } } - if (net_set_interfaceaddress (&ctl) != 0) { - error(0, 0, "Couldn't set interface address: %s", ctl.InterfaceAddress); - if (ctl.Interactive) - exit(EXIT_FAILURE); - else { - names_walk = names_walk->next; - continue; - } - } - -- lock(stdout); dns_open(&ctl); display_open(&ctl); @@@ -760,13 -793,14 +757,13 @@@ display_loop(&ctl); net_end_transit(); - now = time(NULL); - display_close(&ctl, now); + display_close(&ctl); unlock(stdout); - if (ctl.DisplayMode != DisplayCSV) + if (ctl.Interactive) break; else - names_root = names_root->next; + names_walk = names_walk->next; }