def get_a_root(args)
aaaa = args[:aaaa] || false
Log.debug { "get_a_root entry" }
begin
msg = @lresolver.query('', 'NS')
rescue Exception => e
puts "Failed to get roots, local resolver returned exception: #{e}"
raise e
end
msg_validate(msg, :qname => '', :qtype => 'NS')
msg_comment(msg, :want_recursion => true)
ans1 = msg_answers?(msg, :qname => '', :qtype => 'NS')
unless ans1 then
raise ResolveError, "No root nameservers found"
end
roots = ans1.map {|x| x.domainname.to_s }
Log.debug { "Local resolver lists: " + roots.join(', ') }
types = aaaa ? TYPE_ARRAY_AAAA : TYPE_ARRAY_A
for type in types do
for root in roots do
if (add = msg_additional?(msg, :qname => root, :qtype => type)) then
rootip = add[0].rdata.to_s
return root, rootip
end
end
end
Log.debug { "Nothing in additional section of help" }
for type in types do
for root in roots do
Log.debug { "Resolving root #{root} type #{type}" }
msg = @lresolver.query(root, type)
msg_validate(msg, :qname => root, :qtype => type)
msg_comment(msg, :want_recursion => true)
ans2 = msg_answers?(msg, :qname => root, :qtype => type)
if ans2 then
rootip = ans2[0].rdata.to_s
Log.debug { "get_a_root exit: #{root} #{rootip}" }
return root, rootip
end
Log.debug { "#{root}/#{type}: No suitable answers found" }
end
end
raise ResolveError, "No address could be found for any root server"
end