From: Florian Forster Date: Sun, 16 Jul 2006 10:19:42 +0000 (+0200) Subject: liboping.c: Catch `EHOSTUNREACH' and `ENETUNREACH' X-Git-Tag: liboping-0.3.3~1^2~1 X-Git-Url: https://git.tokkee.org/?p=liboping.git;a=commitdiff_plain;h=3e913e60cfcca693feed7eb89c8252f3b2815a6c liboping.c: Catch `EHOSTUNREACH' and `ENETUNREACH' When the kernel cannot send out a packet to a host because the host or network is unreachable, `sendto' may return with `EHOSTUNREACH' or `ENETUNREACH'. So far all errors returned by `sendto' were considered fatal and the pinging was aborted. This is wrong when the host is unreachable, so catching and ignoring these errors is reasonable.. Thanks to Wolfgang Kroener for reporting and debigging this problem with me :) --- diff --git a/src/liboping.c b/src/liboping.c index debd432..13bcc92 100644 --- a/src/liboping.c +++ b/src/liboping.c @@ -537,7 +537,17 @@ static ssize_t ping_sendto (pingobj_t *obj, pinghost_t *ph, (struct sockaddr *) ph->addr, ph->addrlen); if (ret < 0) + { +#if defined(EHOSTUNREACH) + if (errno == EHOSTUNREACH) + return (0); +#endif +#if defined(ENETUNREACH) + if (errno == ENETUNREACH) + return (0); +#endif ping_set_error (obj, "sendto", strerror (errno)); + } return (ret); }