#include <iostream>
+#include <boost/assert.hpp>
#include <boost/asio.hpp>
#include <boost/foreach.hpp>
#include <boost/net/resolve.hpp>
ResolvedHostAddressList.clear();
fill_resolved_ip_list( answers_list, &ResolvedHostAddressList );
-
}
catch ( const std::exception &ex )
{
BOOST_FOREACH( shared_ptr<resource_base_t> resource_record, answers_list )
{
- if ( resource_record &&
- ( resource_record->rtype() == boost::net::dns::type_a ) )
+ if ( resource_record )
{
- a_resource *a_rr = dynamic_cast<a_resource *> (
- 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;
}
}
}
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_base_t> resource_record,
+ list<HostAddress> *resolved_host_address_list
+) const
+{
+ BOOST_ASSERT( resource_record->rtype() == boost::net::dns::type_a );
+
+ a_resource *a_rr = dynamic_cast<a_resource *> ( 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;
+ }
+}
const boost::net::dns::rr_list_t& answers_list,
std::list<HostAddress> *resolved_host_address_list
) const;
+ void append_resolved_ipv4(
+ const shared_ptr<boost::net::dns::resource_base_t> resource_record,
+ std::list<HostAddress> *resolved_host_address_list
+ ) const;
private:
/// The list of IPs available to the host DNS.