]> git.gsnw.org Git - fping.git/commitdiff
support --print-{tos,ttl} with -cN, -CN, and -l
authorErik Auerswald <auerswal@unix-ag.uni-kl.de>
Mon, 9 Dec 2024 18:41:40 +0000 (19:41 +0100)
committerDavid Schweikert <david@schweikert.ch>
Sat, 14 Dec 2024 17:47:38 +0000 (18:47 +0100)
This addresses GitHub issue #367.

ci/test-05-options-c-e.pl
ci/test-07-options-i-m.pl
src/fping.c

index 9e7825d6f46402cec80a4168a5dfe87ac37991f5..10ed4bcd0e4e55f501c7ad20e2e045e8e608ec84 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-use Test::Command tests => 78;
+use Test::Command tests => 84;
 use Test::More;
 
 #  -c n           count of pings to send to each target (default 1)
@@ -25,6 +25,21 @@ $cmd->stderr_like(qr{localhost : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\
 });
 }
 
+# fping -c n --print-tos --print-ttl
+{
+my $cmd = Test::Command->new(cmd => "fping -4 -c 2 -p 100 --print-tos --print-ttl localhost 127.0.0.1");
+$cmd->exit_is_num(0);
+$cmd->stdout_like(qr{localhost : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+localhost : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+});
+
+$cmd->stderr_like(qr{localhost : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
+127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
+});
+}
+
 # fping -c n -q
 {
 my $cmd = Test::Command->new(cmd => "fping -q -c 2 -p 100 localhost 127.0.0.1");
@@ -107,6 +122,21 @@ $cmd->stderr_like(qr{localhost : \d\.\d+ \d\.\d+
 });
 }
 
+# fping -C n --print-tos --print-ttl
+{
+my $cmd = Test::Command->new(cmd => "fping -4 -C 2 -p 100 --print-tos --print-ttl localhost 127.0.0.1");
+$cmd->exit_is_num(0);
+$cmd->stdout_like(qr{localhost : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+localhost : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+});
+
+$cmd->stderr_like(qr{localhost : \d\.\d+ \d\.\d+
+127\.0\.0\.1 : \d\.\d+ \d\.\d+
+});
+}
+
 # fping -C n -q
 {
 my $cmd = Test::Command->new(cmd => "fping -C 5 -q -p 100 localhost");
index 185d015620dd530b4a4c67615276c0aad8ad3f7e..426286a558098acd00c37c1f850b4517a5ca268a 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-use Test::Command tests => 15;
+use Test::Command tests => 16;
 use Test::More;
 
 #  -i n       interval between sending ping packets (in millisec) (default 25)
@@ -25,6 +25,14 @@ $cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0
 });
 }
 
+# fping -l --print-tos --print-ttl
+{
+my $cmd = Test::Command->new(cmd => '(sleep 2; pkill fping)& fping -p 900 --print-ttl --print-tos -l 127.0.0.1');
+$cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+});
+}
+
 # fping -k
 SKIP: {
 if($^O ne 'linux') {
index 90a91a96203d09beaf11410c96d2b79d25a9b5e3..93832c750b145546440cd701b0b7d1bb04cf0329 100644 (file)
@@ -2574,41 +2574,6 @@ int wait_for_reply(int64_t wait_time)
 
             if (verbose_flag)
                 printf(" is alive");
-
-            if(print_tos_flag) {
-                if(ip_header_tos != -1) {
-                    printf(" (TOS %d)", ip_header_tos);
-                }
-                else {
-                    printf(" (TOS unknown)");
-                }
-            }
-
-            if (print_ttl_flag) {
-              if(ip_header_ttl != -1) {
-                  printf(" (TTL %d)", ip_header_ttl);
-              }
-              else {
-                  printf(" (TTL unknown)");
-              }
-            }
-
-            if (icmp_request_typ == 13) {
-                printf(" (Timestamp Originate=%u Receive=%u Transmit=%u Localreceive=%u)",
-                       ip_header_otime_ms, ip_header_rtime_ms, ip_header_ttime_ms,
-                       ms_since_midnight_utc(recv_time));
-            }
-
-            if (elapsed_flag)
-                printf(" (%s ms)", sprint_tm(this_reply));
-
-            if (addr_cmp((struct sockaddr *)&response_addr, (struct sockaddr *)&h->saddr)) {
-                char buf[INET6_ADDRSTRLEN];
-                getnameinfo((struct sockaddr *)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
-                fprintf(stderr, " [<- %s]", buf);
-            }
-
-            printf("\n");
         }
     }
 
@@ -2630,6 +2595,9 @@ int wait_for_reply(int64_t wait_time)
             printf("%d%% return)",
                 (h->num_recv_total * 100) / h->num_sent);
         }
+    }
+
+    if (verbose_flag || alive_flag || per_recv_flag) {
 
         if (addr_cmp((struct sockaddr *)&response_addr, (struct sockaddr *)&h->saddr)) {
             char buf[INET6_ADDRSTRLEN];
@@ -2637,12 +2605,36 @@ int wait_for_reply(int64_t wait_time)
             fprintf(stderr, " [<- %s]", buf);
         }
 
+            if(print_tos_flag) {
+                if(ip_header_tos != -1) {
+                    printf(" (TOS %d)", ip_header_tos);
+                }
+                else {
+                    printf(" (TOS unknown)");
+                }
+            }
+
+            if (print_ttl_flag) {
+              if(ip_header_ttl != -1) {
+                  printf(" (TTL %d)", ip_header_ttl);
+              }
+              else {
+                  printf(" (TTL unknown)");
+              }
+            }
+
         if (icmp_request_typ == 13) {
-            printf(", ICMP timestamp: Originate=%u Receive=%u Transmit=%u Localreceive=%u",
+            printf("%simestamp%s Originate=%u Receive=%u Transmit=%u Localreceive=%u%s",
+                   per_recv_flag ? ", ICMP t" : " (T",
+                   per_recv_flag ? ":" : "",
                    ip_header_otime_ms, ip_header_rtime_ms, ip_header_ttime_ms,
-                   ms_since_midnight_utc(recv_time));
+                   ms_since_midnight_utc(recv_time),
+                   per_recv_flag ? "" : ")");
         }
 
+        if (elapsed_flag && !per_recv_flag)
+                printf(" (%s ms)", sprint_tm(this_reply));
+
         printf("\n");
     }