summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a951a70)
raw | patch | inline | side by side (parent: a951a70)
author | Florian Forster <ff@octo.it> | |
Fri, 5 May 2017 09:11:55 +0000 (11:11 +0200) | ||
committer | Florian Forster <ff@octo.it> | |
Fri, 5 May 2017 09:11:55 +0000 (11:11 +0200) |
This is the documented behavior.
src/liboping.c | patch | blob | history |
diff --git a/src/liboping.c b/src/liboping.c
index 117cbfac893b16639be2beb926ac54159d66ebf8..f4cf614ca0704258a63bf79f32261d88e21e5f06 100644 (file)
--- a/src/liboping.c
+++ b/src/liboping.c
struct timeval nowtime;
struct timeval timeout;
- int ret = 0;
-
_Bool need_ipv4_socket = 0;
_Bool need_ipv6_socket = 0;
* receive a "pong" yet. */
int pings_in_flight = 0;
+ /* pongs_received is the number of echo replies received. Unless there
+ * is an error, this is used as the return value of ping_send(). */
+ int pongs_received = 0;
+
+ int error_count = 0;
+
while (pings_in_flight > 0 || host_to_ping != NULL)
{
fd_set read_fds;
if (obj->fd6 != -1 && FD_ISSET (obj->fd6, &read_fds))
{
if (ping_receive_one (obj, &nowtime, AF_INET6) == 0)
+ {
pings_in_flight--;
+ pongs_received++;
+ }
continue;
}
if (obj->fd4 != -1 && FD_ISSET (obj->fd4, &read_fds))
{
if (ping_receive_one (obj, &nowtime, AF_INET) == 0)
+ {
pings_in_flight--;
+ pongs_received++;
+ }
continue;
}
if (ping_send_one (obj, host_to_ping, write_fd) == 0)
pings_in_flight++;
else
- ret--;
+ error_count++;
host_to_ping = host_to_ping->next;
continue;
}
} /* while (1) */
- return (ret);
+ if (error_count)
+ return (-1 * error_count);
+ return (pongs_received);
} /* int ping_send */
static pinghost_t *ping_host_search (pinghost_t *ph, const char *host)