From 5dbeb8f1b4084c38103e92dbd028da2762c1f0a9 Mon Sep 17 00:00:00 2001 From: russor Date: Thu, 28 Jul 2016 22:46:48 -0700 Subject: [PATCH] add option to set graceperiod useful when running a single probe on a network where many hops never respond --- mtr.8 | 7 +++++++ mtr.c | 13 +++++++++++-- select.c | 4 ++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/mtr.8 b/mtr.8 index 33f82d6..03af3af 100644 --- a/mtr.8 +++ b/mtr.8 @@ -65,6 +65,9 @@ mtr \- a network diagnostic tool .BI \-B \ BITPATTERN\c ] [\c +.BI \-G \ GRACEPERIOD\c +] +[\c .BI \-Q \ TOS\c ] [\c @@ -337,6 +340,10 @@ Specifies bit pattern to use in payload. Should be within range 0 - 255. If .I NUM is greater than 255, a random pattern is used. .TP +.B \-G \fISECONDS\fR, \fB\-\-graceperiod \fISECONDS +Use this option to specify the positive number of seconds to wait for responses +after the final request. The default value is five seconds. +.TP .B \-Q \fINUM\fR, \fB\-\-tos \fINUM Specifies value for type of service field in IP header. Should be within range 0 - 255. diff --git a/mtr.c b/mtr.c index 2e1c630..88aea6c 100644 --- a/mtr.c +++ b/mtr.c @@ -67,6 +67,7 @@ int PrintHelp = 0; int MaxPing = 10; int ForceMaxPing = 0; float WaitTime = 1.0; +float GraceTime = 5.0; char *Hostname = NULL; char *InterfaceAddress = NULL; char LocalHostname[128]; @@ -312,6 +313,7 @@ void parse_arg (int argc, char **argv) { "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 */ + { "gracetime", 1, NULL, 'G' }, /* graceperiod for replies after last probe */ #ifdef SO_MARK { "mark", 1, NULL, 'M' }, /* use SO_MARK */ #endif @@ -321,7 +323,7 @@ void parse_arg (int argc, char **argv) opt = 0; while(1) { opt = getopt_long(argc, argv, - "hv46F:rwxtglCpnbo:y:zi:c:s:B:Q:ea:f:m:U:uTSP:L:Z:M:", long_options, NULL); + "hv46F:rwxtglCpnbo:y:zi:c:s:B:Q:ea:f:m:U:uTSP:L:Z:G:M:", long_options, NULL); if(opt == -1) break; @@ -438,6 +440,13 @@ void parse_arg (int argc, char **argv) if (bitpattern > 255) bitpattern = -1; break; + case 'G': + GraceTime = atof (optarg); + if (GraceTime <= 0.0) { + fprintf (stderr, "mtr: wait time must be positive\n"); + exit (1); + } + break; case 'Q': tos = atoi (optarg); if (tos > 255 || tos < 0) { @@ -642,7 +651,7 @@ int main(int argc, char **argv) "\t\t[-Q TOS] [--mpls]\n" "\t\t[-a ADDRESS] [-f FIRST-TTL] [-m MAX-TTL] [-U MAX_UNKNOWN]\n" "\t\t[--udp] [--tcp] [--sctp] [-P PORT] [-L LOCALPORT] [-Z TIMEOUT]\n" - "\t\t[-M MARK] HOSTNAME\n", argv[0]); + "\t\t[-G GRACEPERIOD] [-M MARK] HOSTNAME\n", argv[0]); printf("See the man page for details.\n"); exit(0); } diff --git a/select.c b/select.c index b2c4349..ed0ae5e 100644 --- a/select.c +++ b/select.c @@ -39,14 +39,14 @@ extern int Interactive; extern int MaxPing; extern int ForceMaxPing; extern float WaitTime; +extern float GraceTime; double dnsinterval; extern int mtrtype; static struct timeval intervaltime; int display_offset = 0; - -#define GRACETIME (5 * 1000*1000) +#define GRACETIME (GraceTime * 1000*1000) void select_loop(void) { fd_set readfd; -- 2.47.2