From: Guilherme Maciel Ferreira Date: Thu, 23 Feb 2012 02:37:21 +0000 (-0200) Subject: Refactor: moved the 'A' resource record filling to a dedicated method. X-Git-Tag: v1.5~1^2~36 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=52866160cb77e05bf7cf3b972f39a31f0497ada9;p=pingcheck Refactor: moved the 'A' resource record filling to a dedicated method. --- diff --git a/src/dns/dnsresolver.cpp b/src/dns/dnsresolver.cpp index eebd9c8..219c35c 100644 --- a/src/dns/dnsresolver.cpp +++ b/src/dns/dnsresolver.cpp @@ -21,6 +21,7 @@ on this file might be covered by the GNU General Public License. #include +#include #include #include #include @@ -101,7 +102,6 @@ bool DnsResolver::resolve() ResolvedHostAddressList.clear(); fill_resolved_ip_list( answers_list, &ResolvedHostAddressList ); - } catch ( const std::exception &ex ) { @@ -244,22 +244,17 @@ void DnsResolver::fill_resolved_ip_list( BOOST_FOREACH( shared_ptr resource_record, answers_list ) { - if ( resource_record && - ( resource_record->rtype() == boost::net::dns::type_a ) ) + if ( resource_record ) { - a_resource *a_rr = dynamic_cast ( - resource_record.get() - ); - if ( a_rr != NULL ) + switch ( resource_record->rtype() ) { - string current_ip = a_rr->address().to_string(); - uint32_t current_ttl = a_rr->ttl(); - - HostAddress resolved_host( current_ip, current_ttl ); - resolved_host_address_list->push_back( resolved_host ); - - GlobalLogger.info() << "- " << current_ip - << " [" << current_ttl << "s]" << endl; + case boost::net::dns::type_a: + // 'A' resource records carry IPv4 addresses + append_resolved_ipv4( resource_record, resolved_host_address_list ); + break; + default: + // other types of resource records + break; } } } @@ -270,3 +265,23 @@ void DnsResolver::fill_resolved_ip_list( bool size_equal_minus_cname = ( resolve_host_list_size == ( answer_list_size - 1 ) ); BOOST_ASSERT( size_equal || size_equal_minus_cname ); } + +void DnsResolver::append_resolved_ipv4( + const shared_ptr resource_record, + list *resolved_host_address_list +) const +{ + BOOST_ASSERT( resource_record->rtype() == boost::net::dns::type_a ); + + a_resource *a_rr = dynamic_cast ( resource_record.get() ); + if ( a_rr != NULL ) + { + string current_ip = a_rr->address().to_string(); + uint32_t current_ttl = a_rr->ttl(); + + HostAddress resolved_host( current_ip, current_ttl ); + resolved_host_address_list->push_back( resolved_host ); + + GlobalLogger.info() << "- " << current_ip << " [" << current_ttl << "s]" << endl; + } +} diff --git a/src/dns/dnsresolver.h b/src/dns/dnsresolver.h index 249e356..1c3dd0a 100644 --- a/src/dns/dnsresolver.h +++ b/src/dns/dnsresolver.h @@ -59,6 +59,10 @@ private: const boost::net::dns::rr_list_t& answers_list, std::list *resolved_host_address_list ) const; + void append_resolved_ipv4( + const shared_ptr resource_record, + std::list *resolved_host_address_list + ) const; private: /// The list of IPs available to the host DNS.