From: Christian Herdtweck Date: Fri, 22 May 2015 10:01:24 +0000 (+0200) Subject: deal with case that have no IP from DNS nor from Cache X-Git-Url: http://developer.intra2net.com/git/?p=pingcheck;a=commitdiff_plain;h=838e0acff33fc8b09edcd945cd5a38efab53a814 deal with case that have no IP from DNS nor from Cache --- diff --git a/src/host/hoststatus.cpp b/src/host/hoststatus.cpp index 6f7d590..d620e58 100644 --- a/src/host/hoststatus.cpp +++ b/src/host/hoststatus.cpp @@ -63,7 +63,7 @@ HostStatus::~HostStatus() */ void HostStatus::set_resolved_ip_count( const int resolved_ip_count ) { - BOOST_ASSERT( 1 <= resolved_ip_count ); + BOOST_ASSERT( 0 <= resolved_ip_count ); if (resolved_ip_count != ResolvedIpCount) { // assume that the target has changed --> reset counters diff --git a/src/host/pingscheduler.cpp b/src/host/pingscheduler.cpp index 481d394..abeb02d 100644 --- a/src/host/pingscheduler.cpp +++ b/src/host/pingscheduler.cpp @@ -205,7 +205,10 @@ void PingScheduler::ping_when_ready() << "-- treat like a failed ping."; // skip the ping and directly call ping_done_handler + HostAnalyzer.set_resolved_ip_count(1); // must have been 0 --> failed + // ping would create failed assumption (nPings > nIPs) ping_done_handler(false); + HostAnalyzer.set_resolved_ip_count(0); // set back } else { @@ -446,17 +449,25 @@ void PingScheduler::dns_resolve_callback(const bool was_success, else { // host name resolution failed; try again bypassing first outdated CNAME // or using cached IP - ContinueOnOutdatedIps = true; - update_log_prefix(); - std::string skip_host = Resolver->get_skip_cname(); if (skip_host.empty()) - { // continue with IP - GlobalLogger.notice() << LogPrefix << "DNS failed, " - << "try anyway with cached data"; - + { // try to continue with cached IPs int ip_count = Resolver->get_resolved_ip_count(false); + + if (ip_count == 0) + GlobalLogger.notice() << LogPrefix << "DNS failed " + << "and have no cached IPs either --> cannot ping"; + // ping_when_ready will deal with this case + else + { + ContinueOnOutdatedIps = true; + update_log_prefix(); + + GlobalLogger.notice() << LogPrefix << "DNS failed, " + << "try anyway with cached data"; + } + GlobalLogger.info() << LogPrefix << "Set resolved_ip_count to " << ip_count << " (IPs may be outdated=" << true << ")"; HostAnalyzer.set_resolved_ip_count( ip_count ); @@ -465,6 +476,8 @@ void PingScheduler::dns_resolve_callback(const bool was_success, } else { // have CNAME to continue + ContinueOnOutdatedIps = true; + update_log_prefix(); GlobalLogger.notice() << LogPrefix << "DNS failed, " << "try again skipping a CNAME and resolving " << skip_host << " directly";