From 5883c6f27221184efed83aaea0eb7435e06a92cb Mon Sep 17 00:00:00 2001 From: brownowski <35676387+brownowski@users.noreply.github.com> Date: Sun, 7 Jul 2019 11:18:29 +1000 Subject: [PATCH] Update fping.c Should only increase num_alive if response is not a duplicate. In cases where multiple pings are sent, num_alive can increase past one for a host if a duplicate ping response is received while h->num_recv ==1. --- src/fping.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/fping.c b/src/fping.c index 9650db9..7f1b80d 100644 --- a/src/fping.c +++ b/src/fping.c @@ -2149,6 +2149,27 @@ int wait_for_reply(long wait_time) sum_replies += this_reply; h->total_time += this_reply; total_replies++; + + if (h->num_recv == 1) { + num_alive++; + if (verbose_flag || alive_flag) { + printf("%s", h->host); + + if (verbose_flag) + printf(" is alive"); + + 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"); + } + } } /* received ping is cool, so process it */ @@ -2185,27 +2206,6 @@ int wait_for_reply(long wait_time) } } - if (h->num_recv == 1) { - num_alive++; - if (verbose_flag || alive_flag) { - printf("%s", h->host); - - if (verbose_flag) - printf(" is alive"); - - 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"); - } - } - if (per_recv_flag) { if (timestamp_flag) { printf("[%lu.%06lu] ",