diff --git a/doc/fping.pod b/doc/fping.pod index 7702df1..619e5ef 100644 --- a/doc/fping.pod +++ b/doc/fping.pod @@ -232,6 +232,11 @@ Print B version information. Given a list of hosts, this mode checks if number of reachable hosts is >= N and exits true in that case. +=item B<-X>, B<--fast-reachable>=I + +Given a list of hosts, this mode immediately exits true once N alive hosts +have been found. + =back =head1 EXAMPLES diff --git a/src/fping.c b/src/fping.c index f4dcdcd..1e5af89 100644 --- a/src/fping.c +++ b/src/fping.c @@ -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 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 multif_flag, timeout_flag; +int multif_flag, timeout_flag, fast_reachable; int outage_flag = 0; int timestamp_flag = 0; int random_data_flag = 0; @@ -536,6 +536,7 @@ int main(int argc, char **argv) { "unreach", 'u', OPTPARSE_NONE }, { "version", 'v', OPTPARSE_NONE }, { "reachable", 'x', OPTPARSE_REQUIRED }, + { "fast-reachable", 'X', OPTPARSE_REQUIRED }, #if defined(DEBUG) || defined(_DEBUG) { NULL, 'z', OPTPARSE_REQUIRED }, #endif @@ -750,6 +751,12 @@ int main(int argc, char **argv) usage(1); break; + case 'X': + if (!(min_reachable = (unsigned int)atoi(optparse_state.optarg))) + usage(1); + fast_reachable = 1; + break; + case 'f': filename = optparse_state.optarg; break; @@ -2409,6 +2416,9 @@ int wait_for_reply(int64_t wait_time) /* print "is alive" */ if (h->num_recv == 1) { num_alive++; + if (fast_reachable && num_alive >= min_reachable) + finish_requested = 1; + if (verbose_flag || alive_flag) { 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, " -v, --version show version\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); }