ruby/ruby — pull request #797 by ereslibre (2014-12-27 06:11:49+00:00)
Title: When retrieving information from the DNS message object get not only answers, but all resources

A call to `Message#each_answer` does only include answers, however there are also two more kinds of
responses: Authority and Additional. Iterating through `Message#each_resource` allows us to retrieve
all information from the `Message` object.

This is specially important if for example we are trying to retrieve NS entries from a gtld server
(say `a.gtld-servers.net`) for a domain which is controlled by them. In this case this Message include
this information in the authority section, which was not being returned before with `Message#each_answer`.

For example, asking `199.19.56.1` (`a0.org.afilias-nst.info`) for `ruby-lang.org` without this change returns empty array, while with this change the authority section of the response is returned.

require 'resolv'
dns = Resolv::DNS.new(:nameserver => ['199.19.56.1'])
puts dns.getresources('ruby-lang.org', Resolv::DNS::Resource::IN::NS).map(&:name)

Dig (`dig ns ruby-lang.org @199.19.56.1`) returns the information like this:

; <<>> DiG 9.8.3-P1 <<>> ns ruby-lang.org @199.19.56.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17104
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 2, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;ruby-lang.org.	IN	NS

;; AUTHORITY SECTION:
ruby-lang.org.	86400	IN	NS	support.netlab.jp.
ruby-lang.org.	86400	IN	NS	pichu.netlab.jp.

;; Query time: 388 msec
;; SERVER: 199.19.56.1#53(199.19.56.1)
;; WHEN: Sat Dec 27 07:09:22 2014
;; MSG SIZE rcvd: 82