]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
add option to set graceperiod 126/head
authorrussor <russor@whatsapp.com>
Fri, 29 Jul 2016 05:46:48 +0000 (22:46 -0700)
committerrussor <russor@whatsapp.com>
Fri, 29 Jul 2016 05:48:46 +0000 (22:48 -0700)
useful when running a single probe on a network where many hops never
respond

mtr.8
mtr.c
select.c

diff --git a/mtr.8 b/mtr.8
index 33f82d612512a0ef2ae8aba41646e68d9d81bc2a..03af3af1ed56c7ffd02c414868cd0884f2cff5dc 100644 (file)
--- 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 2e1c630aa58dc101f74c1756f144adc6c55a9ae7..88aea6c9f24927aeab3f4237912f170cf80ba9a9 100644 (file)
--- 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);
   }
index b2c434977fbc844f09f539c49e60bdfeca15de95..ed0ae5e199a401fc80f995b094f75b680a602639 100644 (file)
--- 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;