diff --git a/ci/test-05-options-c-e.pl b/ci/test-05-options-c-e.pl index 9e7825d..10ed4bc 100755 --- a/ci/test-05-options-c-e.pl +++ b/ci/test-05-options-c-e.pl @@ -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 @@ }); } +# 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 @@ }); } +# 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"); diff --git a/ci/test-07-options-i-m.pl b/ci/test-07-options-i-m.pl index 185d015..426286a 100755 --- a/ci/test-07-options-i-m.pl +++ b/ci/test-07-options-i-m.pl @@ -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 @@ }); } +# 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') { diff --git a/src/fping.c b/src/fping.c index 90a91a9..93832c7 100644 --- a/src/fping.c +++ b/src/fping.c @@ -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"); }