From: David Schweikert Date: Thu, 29 Sep 2016 08:14:27 +0000 (+0200) Subject: Add option -o for accumulated outage time (#90) X-Git-Url: https://git.gsnw.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d12dfbbcc862e78b3e770cb306a2fa086d82003;p=fping.git Add option -o for accumulated outage time (#90) --- 6d12dfbbcc862e78b3e770cb306a2fa086d82003 diff --cc ChangeLog index b05932d,d9d90fc..8ed21c3 --- a/ChangeLog +++ b/ChangeLog @@@ -1,10 -1,3 +1,11 @@@ +UNRELEASED + * (feature) Ignore network and broadcast for cidrs /31 and /32 (#102, Martin Topholm) + * (feature) New option '-M' to set the "Don't Fragment" flag (#91, Don Bowman) ++ * (feature) New option '-o' to calculate total outage time (#90, @jgerbeck) + * (bugfix) Exit code should be 2 when the hostname can't be resolved + (fixes #98, reported by @green-fox) + * (bugfix) Fix issue compliling on RHEL/Centos 7 (#95, @jbackman) + 2015-10-21 David Schweikert * Version 3.13 * (bugfix) Fix ICMP errors sometimes causing crashes with fping >= 3.11 diff --cc ci/test-02-help.pl index d8693f4,ed7dcf3..ca78a40 --- a/ci/test-02-help.pl +++ b/ci/test-02-help.pl @@@ -27,8 -27,8 +27,9 @@@ Usage: fping [options] [targets... -i n interval between sending ping packets (in millisec) (default 25) ${I_HELP} -l loop sending pings forever -m ping multiple interfaces on target host + -M set the Don't Fragment flag -n show targets by name (-d is equivalent) - -o show the accumulated outage time (lost packets * packet interval [option -i]) ++ -o show the accumulated outage time (lost packets * packet interval) -O n set the type of service (tos) flag on the ICMP packets -p n interval between ping packets to one target (in millisec) (in looping and counting modes, default 1000) diff --cc ci/test-08-options-n-q.pl index 66630b8,66630b8..c490c19 --- a/ci/test-08-options-n-q.pl +++ b/ci/test-08-options-n-q.pl @@@ -1,6 -1,6 +1,6 @@@ #!/usr/bin/perl -w --use Test::Command tests => 9; ++use Test::Command tests => 12; # -n show targets by name (-d is equivalent) # -O n set the type of service (tos) flag on the ICMP packets @@@ -11,6 -11,6 +11,14 @@@ # fping -n -> test-14-internet-hosts ++# fping -o ++{ ++my $cmd = Test::Command->new(cmd => "fping -t100 -p 100 -o -c 5 8.8.8.7"); ++$cmd->exit_is_num(1); ++$cmd->stdout_is_eq(""); ++$cmd->stderr_like(qr{^\s*8\.8\.8\.7 : xmt/rcv/%loss = 5/0/100%, outage\(ms\) = 50\d\s*$}); ++} ++ # fping -O { my $cmd = Test::Command->new(cmd => "fping -O 2 127.0.0.1"); diff --cc doc/fping.pod index 86d6a71,fc8cc4e..a193383 --- a/doc/fping.pod +++ b/doc/fping.pod @@@ -127,10 -127,10 +127,23 @@@ Ctrl-C; statistics about responses for Send pings to each of a target host's multiple interfaces. ++=item B<-M> ++ ++Set the "Don't Fragment" bit in the IP header (used to determine/test the MTU). ++ =item B<-n> Same as -d. ++=item B<-o> ++ ++Calculate "outage time" based on the number of lost pings and the interval used (useful for network convergence tests). ++ ++=item B<-O> I ++ ++Set the typ of service flag (TOS). I can be either decimal or hexadecimal ++(0xh) format. ++ =item B<-p> In looping or counting modes (B<-l>, B<-c>, or B<-C>), this parameter sets @@@ -184,11 -184,11 +197,6 @@@ Ignored (for compatibility with fping 2 Show targets that are unreachable. --=item B<-O> I -- --Set the typ of service flag (TOS). I can be either decimal or hexadecimal --(0xh) format. -- =item B<-v> Print B version information. diff --cc src/fping.c index 453c530,bcbbd58..f185a2e --- a/src/fping.c +++ b/src/fping.c @@@ -376,7 -378,7 +377,7 @@@ int main( int argc, char **argv /* get command line options */ - while( ( c = getopt( argc, argv, "gedhlmnqusaAvDRz:t:H:i:p:f:r:c:b:C:Q:B:S:I:T:O:M" ) ) != EOF ) - while( ( c = getopt( argc, argv, "gedhlmnqusaAvDRz:t:H:i:p:f:r:c:b:C:Q:B:S:I:T:O:o" ) ) != EOF ) ++ while( ( c = getopt( argc, argv, "gedhlmnqusaAvDRz:t:H:i:p:f:r:c:b:C:Q:B:S:I:T:O:M:o" ) ) != EOF ) { switch( c ) { @@@ -561,6 -554,11 +562,11 @@@ usage(1); } break; - ++ + case 'o': + outage_flag = 1; + break; - ++ default: fprintf(stderr, "see 'fping -h' for usage information\n"); exit(1); @@@ -1221,7 -1212,14 +1228,13 @@@ void print_per_system_stats( void h->num_sent, h->num_recv, h->num_sent > 0 ? ( ( h->num_sent - h->num_recv ) * 100 ) / h->num_sent : 0 ); - if (outage_flag) - { - /* Time outage total */ - outage_ms = (h->num_sent - h->num_recv) * perhost_interval/100; - fprintf( stderr, ", outage(ms) = %d", outage_ms ); ++ if (outage_flag) { ++ /* Time outage total */ ++ outage_ms = (h->num_sent - h->num_recv) * perhost_interval/100; ++ fprintf( stderr, ", outage(ms) = %d", outage_ms ); + } + - }/* IF */ + }/* IF */ else { fprintf( stderr, " xmt/rcv/%%return = %d/%d/%d%%", @@@ -1313,6 -1312,12 +1326,11 @@@ void print_per_system_splits( void h->num_sent_i, h->num_recv_i, h->num_sent_i > 0 ? ( ( h->num_sent_i - h->num_recv_i ) * 100 ) / h->num_sent_i : 0 ); - if (outage_flag) - { - /* Time outage */ ++ if (outage_flag) { ++ /* Time outage */ + outage_ms_i = (h->num_sent_i - h->num_recv_i) * perhost_interval/100; + fprintf( stderr, ", outage(ms) = %d", outage_ms_i ); - } ++ } }/* IF */ else { @@@ -2395,8 -2401,8 +2413,9 @@@ void usage(int is_error #endif fprintf(out, " -l loop sending pings forever\n" ); fprintf(out, " -m ping multiple interfaces on target host\n" ); + fprintf(out, " -M set the Don't Fragment flag\n" ); fprintf(out, " -n show targets by name (-d is equivalent)\n" ); - fprintf(out, " -o show the accumulated outage time (lost packets * packet interval [option -i]) \n" ); ++ fprintf(out, " -o show the accumulated outage time (lost packets * packet interval)\n" ); fprintf(out, " -O n set the type of service (tos) flag on the ICMP packets\n" ); fprintf(out, " -p n interval between ping packets to one target (in millisec)\n" ); fprintf(out, " (in looping and counting modes, default %d)\n", perhost_interval / 100 );