Removing flag variable and its dependencies, printing required and reachable hosts, and changing initialisation of min_reachable

pull/138/head
deepak0004 6 years ago
parent af9b3bfbfe
commit 03d821e983

@ -27,7 +27,7 @@ $cmd->stderr_is_eq("");
{ {
my $cmd = Test::Command->new(cmd => "fping -x 1 8.8.0.0 127.0.0.1"); my $cmd = Test::Command->new(cmd => "fping -x 1 8.8.0.0 127.0.0.1");
$cmd->exit_is_num(0); $cmd->exit_is_num(0);
$cmd->stdout_is_eq("Number of reachable hosts: 1\n"); $cmd->stdout_is_eq("Enough hosts reachable (required: 1, reachable: 1)\n");
$cmd->stderr_is_eq(""); $cmd->stderr_is_eq("");
} }
@ -35,6 +35,6 @@ $cmd->stderr_is_eq("");
{ {
my $cmd = Test::Command->new(cmd => "fping -x 2 8.8.0.0 127.0.0.1"); my $cmd = Test::Command->new(cmd => "fping -x 2 8.8.0.0 127.0.0.1");
$cmd->exit_is_num(1); $cmd->exit_is_num(1);
$cmd->stdout_is_eq("<2 hosts are reachable\n"); $cmd->stdout_is_eq("Not enough hosts reachable (required: 2, reachable: 1)\n");
$cmd->stderr_is_eq(""); $cmd->stderr_is_eq("");
} }

@ -225,7 +225,7 @@ Show targets that are unreachable.
Print B<fping> version information. Print B<fping> version information.
=item B<-x>, B<--reachable>=I<N> =item B<-x>, B<--min_reachable>=I<N>
Given a list of hosts, this mode prints if number of active hosts>=N or not. Given a list of hosts, this mode prints if number of active hosts>=N or not.

@ -248,7 +248,7 @@ unsigned int interval = DEFAULT_INTERVAL * 100;
unsigned int perhost_interval = DEFAULT_PERHOST_INTERVAL * 100; unsigned int perhost_interval = DEFAULT_PERHOST_INTERVAL * 100;
float backoff = DEFAULT_BACKOFF_FACTOR; float backoff = DEFAULT_BACKOFF_FACTOR;
unsigned int ping_data_size = DEFAULT_PING_DATA_SIZE; unsigned int ping_data_size = DEFAULT_PING_DATA_SIZE;
unsigned int count = 1, reachable = 1; unsigned int count = 1, min_reachable = 0;
unsigned int trials; unsigned int trials;
unsigned int report_interval = 0; unsigned int report_interval = 0;
unsigned int ttl = 0; unsigned int ttl = 0;
@ -285,7 +285,7 @@ struct timezone tz;
/* switches */ /* switches */
int generate_flag = 0; /* flag for IP list generation */ int generate_flag = 0; /* flag for IP list generation */
int verbose_flag, quiet_flag, stats_flag, unreachable_flag, alive_flag; int verbose_flag, quiet_flag, stats_flag, unreachable_flag, alive_flag;
int elapsed_flag, version_flag, count_flag, loop_flag, netdata_flag, reachable_flag; int elapsed_flag, version_flag, count_flag, loop_flag, netdata_flag;
int per_recv_flag, report_all_rtts_flag, name_flag, addr_flag, backoff_flag, rdns_flag; int per_recv_flag, report_all_rtts_flag, name_flag, addr_flag, backoff_flag, rdns_flag;
int multif_flag, timeout_flag; int multif_flag, timeout_flag;
int outage_flag = 0; int outage_flag = 0;
@ -414,7 +414,7 @@ int main(int argc, char** argv)
{ NULL, 'T', OPTPARSE_REQUIRED }, { NULL, 'T', OPTPARSE_REQUIRED },
{ "unreach", 'u', OPTPARSE_NONE }, { "unreach", 'u', OPTPARSE_NONE },
{ "version", 'v', OPTPARSE_NONE }, { "version", 'v', OPTPARSE_NONE },
{ "reachable", 'x', OPTPARSE_REQUIRED }, { "min_reachable", 'x', OPTPARSE_REQUIRED },
{ 0, 0, 0 } { 0, 0, 0 }
}; };
@ -606,9 +606,8 @@ int main(int argc, char** argv)
exit(0); exit(0);
case 'x': case 'x':
if (!(reachable = (unsigned int)atoi(optparse_state.optarg))) if (!(min_reachable = (unsigned int)atoi(optparse_state.optarg)))
usage(1); usage(1);
reachable_flag = 1;
break; break;
case 'f': case 'f':
@ -739,7 +738,7 @@ int main(int argc, char** argv)
exit(1); exit(1);
} }
if (alive_flag || unreachable_flag || reachable_flag) if (alive_flag || unreachable_flag || min_reachable)
verbose_flag = 0; verbose_flag = 0;
if (count_flag) { if (count_flag) {
@ -819,8 +818,6 @@ int main(int argc, char** argv)
fprintf(stderr, " unreachable_flag set\n"); fprintf(stderr, " unreachable_flag set\n");
if (alive_flag) if (alive_flag)
fprintf(stderr, " alive_flag set\n"); fprintf(stderr, " alive_flag set\n");
if (reachable_flag)
fprintf(stderr, " reachable_flag set\n");
if (elapsed_flag) if (elapsed_flag)
fprintf(stderr, " elapsed_flag set\n"); fprintf(stderr, " elapsed_flag set\n");
if (version_flag) if (version_flag)
@ -1332,12 +1329,12 @@ void finish()
if (stats_flag) if (stats_flag)
print_global_stats(); print_global_stats();
if (reachable_flag) { if (min_reachable) {
if ((num_hosts-num_unreachable >= reachable)) { if ((num_hosts-num_unreachable) >= min_reachable) {
printf("Number of reachable hosts: %d\n", num_hosts-num_unreachable); printf("Enough hosts reachable (required: %d, reachable: %d)\n", min_reachable, num_hosts-num_unreachable);
exit(0); exit(0);
} else { } else {
printf("<%d hosts are reachable\n", reachable); printf("Not enough hosts reachable (required: %d, reachable: %d)\n", min_reachable, num_hosts-num_unreachable);
exit(1); exit(1);
} }
} }
@ -2786,6 +2783,6 @@ void usage(int is_error)
fprintf(out, " -s, --stats print final stats\n"); fprintf(out, " -s, --stats print final stats\n");
fprintf(out, " -u, --unreach show targets that are unreachable\n"); fprintf(out, " -u, --unreach show targets that are unreachable\n");
fprintf(out, " -v, --version show version\n"); fprintf(out, " -v, --version show version\n");
fprintf(out, " -x, --reachable=N shows if >=N hosts are reachable or not\n"); fprintf(out, " -x, --min_reachable=N shows if >=N hosts are reachable or not\n");
exit(is_error); exit(is_error);
} }
Loading…
Cancel
Save