]> git.gsnw.org Git - fping.git/commitdiff
Update fping.c
authorbrownowski <35676387+brownowski@users.noreply.github.com>
Sun, 7 Jul 2019 01:18:29 +0000 (11:18 +1000)
committerGitHub <noreply@github.com>
Sun, 7 Jul 2019 01:18:29 +0000 (11:18 +1000)
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

index 9650db9185d64551ea5f3db90e9ca5f24adb5c79..7f1b80d47c549654a4f3a09c06ff18c8ec992c98 100644 (file)
@@ -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] ",