fping: add option to exit immeditely once N hosts have been found

pull/281/head
German Service Network 2 years ago committed by David Schweikert
parent e597c48d77
commit d45438c723

@ -232,6 +232,11 @@ Print B<fping> version information.
Given a list of hosts, this mode checks if number of reachable hosts is >= N Given a list of hosts, this mode checks if number of reachable hosts is >= N
and exits true in that case. and exits true in that case.
=item B<-X>, B<--fast-reachable>=I<N>
Given a list of hosts, this mode immediately exits true once N alive hosts
have been found.
=back =back
=head1 EXAMPLES =head1 EXAMPLES

@ -353,7 +353,7 @@ 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; 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, fast_reachable;
int outage_flag = 0; int outage_flag = 0;
int timestamp_flag = 0; int timestamp_flag = 0;
int random_data_flag = 0; int random_data_flag = 0;
@ -536,6 +536,7 @@ int main(int argc, char **argv)
{ "unreach", 'u', OPTPARSE_NONE }, { "unreach", 'u', OPTPARSE_NONE },
{ "version", 'v', OPTPARSE_NONE }, { "version", 'v', OPTPARSE_NONE },
{ "reachable", 'x', OPTPARSE_REQUIRED }, { "reachable", 'x', OPTPARSE_REQUIRED },
{ "fast-reachable", 'X', OPTPARSE_REQUIRED },
#if defined(DEBUG) || defined(_DEBUG) #if defined(DEBUG) || defined(_DEBUG)
{ NULL, 'z', OPTPARSE_REQUIRED }, { NULL, 'z', OPTPARSE_REQUIRED },
#endif #endif
@ -750,6 +751,12 @@ int main(int argc, char **argv)
usage(1); usage(1);
break; break;
case 'X':
if (!(min_reachable = (unsigned int)atoi(optparse_state.optarg)))
usage(1);
fast_reachable = 1;
break;
case 'f': case 'f':
filename = optparse_state.optarg; filename = optparse_state.optarg;
break; break;
@ -2409,6 +2416,9 @@ int wait_for_reply(int64_t wait_time)
/* print "is alive" */ /* print "is alive" */
if (h->num_recv == 1) { if (h->num_recv == 1) {
num_alive++; num_alive++;
if (fast_reachable && num_alive >= min_reachable)
finish_requested = 1;
if (verbose_flag || alive_flag) { if (verbose_flag || alive_flag) {
printf("%s", h->host); printf("%s", h->host);
@ -2944,5 +2954,6 @@ void usage(int is_error)
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, --reachable=N shows if >=N hosts are reachable or not\n");
fprintf(out, " -X, --fast-reachable=N exits true immediately when N hosts are found\n");
exit(is_error); exit(is_error);
} }

Loading…
Cancel
Save