From 3e913e60cfcca693feed7eb89c8252f3b2815a6c Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 16 Jul 2006 12:19:42 +0200 Subject: [PATCH] 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 :) --- src/liboping.c | 10 ++++++++++ 1 file changed, 10 insertions(+) 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); } -- 2.30.2