net-dns 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +6 -14
 - data/.gitignore +1 -1
 - data/.rspec +1 -0
 - data/.rubocop.yml +3 -0
 - data/.rubocop_defaults.yml +364 -0
 - data/.rubocop_todo.yml +207 -0
 - data/.travis.yml +9 -16
 - data/CHANGELOG.md +12 -1
 - data/Gemfile +6 -2
 - data/LICENSE.txt +56 -0
 - data/README.md +94 -77
 - data/Rakefile +23 -56
 - data/bin/console +14 -0
 - data/demo/check_soa.rb +27 -38
 - data/demo/threads.rb +3 -7
 - data/lib/net/dns.rb +4 -11
 - data/lib/net/dns/core_ext.rb +8 -15
 - data/lib/net/dns/header.rb +58 -66
 - data/lib/net/dns/names.rb +25 -23
 - data/lib/net/dns/packet.rb +136 -139
 - data/lib/net/dns/question.rb +36 -39
 - data/lib/net/dns/resolver.rb +103 -113
 - data/lib/net/dns/resolver/socks.rb +45 -51
 - data/lib/net/dns/resolver/timeouts.rb +17 -26
 - data/lib/net/dns/rr.rb +107 -117
 - data/lib/net/dns/rr/a.rb +46 -55
 - data/lib/net/dns/rr/aaaa.rb +40 -49
 - data/lib/net/dns/rr/classes.rb +26 -29
 - data/lib/net/dns/rr/cname.rb +33 -41
 - data/lib/net/dns/rr/hinfo.rb +44 -56
 - data/lib/net/dns/rr/mr.rb +33 -42
 - data/lib/net/dns/rr/mx.rb +37 -47
 - data/lib/net/dns/rr/ns.rb +33 -41
 - data/lib/net/dns/rr/null.rb +8 -11
 - data/lib/net/dns/rr/ptr.rb +14 -20
 - data/lib/net/dns/rr/soa.rb +27 -30
 - data/lib/net/dns/rr/srv.rb +13 -17
 - data/lib/net/dns/rr/txt.rb +8 -11
 - data/lib/net/dns/rr/types.rb +97 -99
 - data/lib/net/dns/version.rb +5 -13
 - data/net-dns.gemspec +17 -29
 - data/{fixtures → spec/fixtures}/resolv.conf +0 -0
 - data/spec/spec_helper.rb +14 -0
 - data/spec/unit/resolver/dns_timeout_spec.rb +36 -0
 - data/spec/unit/resolver/tcp_timeout_spec.rb +46 -0
 - data/spec/unit/resolver/udp_timeout_spec.rb +46 -0
 - data/test/test_helper.rb +12 -3
 - data/test/{header_test.rb → unit/header_test.rb} +43 -46
 - data/test/{names_test.rb → unit/names_test.rb} +1 -1
 - data/test/{packet_test.rb → unit/packet_test.rb} +3 -5
 - data/test/{question_test.rb → unit/question_test.rb} +3 -5
 - data/test/{resolver_test.rb → unit/resolver_test.rb} +10 -13
 - data/test/{rr → unit/rr}/a_test.rb +10 -17
 - data/test/{rr → unit/rr}/aaaa_test.rb +7 -14
 - data/test/{rr → unit/rr}/classes_test.rb +14 -16
 - data/test/{rr → unit/rr}/cname_test.rb +7 -14
 - data/test/{rr → unit/rr}/hinfo_test.rb +16 -22
 - data/test/{rr → unit/rr}/mr_test.rb +12 -18
 - data/test/{rr → unit/rr}/mx_test.rb +18 -24
 - data/test/{rr → unit/rr}/ns_test.rb +10 -16
 - data/test/{rr → unit/rr}/types_test.rb +10 -8
 - data/test/{rr_test.rb → unit/rr_test.rb} +33 -37
 - metadata +77 -49
 - data/test/resolver/timeouts_test.rb +0 -109
 
    
        data/.travis.yml
    CHANGED
    
    | 
         @@ -1,20 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            language: ruby
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            rvm:
         
     | 
| 
       4 
     | 
    
         
            -
              - 1 
     | 
| 
       5 
     | 
    
         
            -
              -  
     | 
| 
       6 
     | 
    
         
            -
              -  
     | 
| 
       7 
     | 
    
         
            -
              - 2. 
     | 
| 
       8 
     | 
    
         
            -
               
     | 
| 
       9 
     | 
    
         
            -
               
     | 
| 
       10 
     | 
    
         
            -
              -  
     | 
| 
       11 
     | 
    
         
            -
              # - ruby-head
         
     | 
| 
       12 
     | 
    
         
            -
              # - jruby-head
         
     | 
| 
      
 4 
     | 
    
         
            +
              - 2.1
         
     | 
| 
      
 5 
     | 
    
         
            +
              - 2.2
         
     | 
| 
      
 6 
     | 
    
         
            +
              - 2.3
         
     | 
| 
      
 7 
     | 
    
         
            +
              - 2.4
         
     | 
| 
      
 8 
     | 
    
         
            +
              - 2.5
         
     | 
| 
      
 9 
     | 
    
         
            +
              - jruby-9.1.5.0
         
     | 
| 
      
 10 
     | 
    
         
            +
              - ruby-head
         
     | 
| 
       13 
11 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
               
     | 
| 
       16 
     | 
    
         
            -
                - weppos@weppos.net
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
            matrix:
         
     | 
| 
       19 
     | 
    
         
            -
              allow_failures:
         
     | 
| 
       20 
     | 
    
         
            -
                - rvm: 2.0.0
         
     | 
| 
      
 12 
     | 
    
         
            +
            cache:
         
     | 
| 
      
 13 
     | 
    
         
            +
              - bundler
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -1,7 +1,18 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Changelog
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            ##  
     | 
| 
      
 4 
     | 
    
         
            +
            ## Release 0.9.0
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            - FIXED: Fixed CI run (GH-77).
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            - FIXED: Fixed deprecated references to Fixnum.
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            - CHANGED: Major code cleanup.
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            - CHANGED: Minimum Ruby version is now 2.1
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            ## Release 0.8.0
         
     | 
| 
       5 
16 
     | 
    
         | 
| 
       6 
17 
     | 
    
         
             
            - FIXED: undefined local variable or method `source_address_inet6' (GH-40). [Thanks @simsicon]
         
     | 
| 
       7 
18 
     | 
    
         | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | 
         @@ -0,0 +1,56 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            net-dns is copyrighted free software by Marco Ceresa (@bluemonk) and Simone Carletti (@weppos).
         
     | 
| 
      
 2 
     | 
    
         
            +
            You can redistribute it and/or modify it under either the terms of the
         
     | 
| 
      
 3 
     | 
    
         
            +
            2-clause BSDL (see the file BSDL), or the conditions below:
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              1. You may make and give away verbatim copies of the source form of the
         
     | 
| 
      
 6 
     | 
    
         
            +
                 software without restriction, provided that you duplicate all of the
         
     | 
| 
      
 7 
     | 
    
         
            +
                 original copyright notices and associated disclaimers.
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              2. You may modify your copy of the software in any way, provided that
         
     | 
| 
      
 10 
     | 
    
         
            +
                 you do at least ONE of the following:
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                   a) place your modifications in the Public Domain or otherwise
         
     | 
| 
      
 13 
     | 
    
         
            +
                      make them Freely Available, such as by posting said
         
     | 
| 
      
 14 
     | 
    
         
            +
            	  modifications to Usenet or an equivalent medium, or by allowing
         
     | 
| 
      
 15 
     | 
    
         
            +
            	  the author to include your modifications in the software.
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                   b) use the modified software only within your corporation or
         
     | 
| 
      
 18 
     | 
    
         
            +
                      organization.
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                   c) give non-standard binaries non-standard names, with
         
     | 
| 
      
 21 
     | 
    
         
            +
                      instructions on where to get the original software distribution.
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                   d) make other distribution arrangements with the author.
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              3. You may distribute the software in object code or binary form,
         
     | 
| 
      
 26 
     | 
    
         
            +
                 provided that you do at least ONE of the following:
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                   a) distribute the binaries and library files of the software,
         
     | 
| 
      
 29 
     | 
    
         
            +
            	  together with instructions (in the manual page or equivalent)
         
     | 
| 
      
 30 
     | 
    
         
            +
            	  on where to get the original distribution.
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                   b) accompany the distribution with the machine-readable source of
         
     | 
| 
      
 33 
     | 
    
         
            +
            	  the software.
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                   c) give non-standard binaries non-standard names, with
         
     | 
| 
      
 36 
     | 
    
         
            +
                      instructions on where to get the original software distribution.
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                   d) make other distribution arrangements with the author.
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
              4. You may modify and include the part of the software into any other
         
     | 
| 
      
 41 
     | 
    
         
            +
                 software (possibly commercial).  But some files in the distribution
         
     | 
| 
      
 42 
     | 
    
         
            +
                 are not written by the author, so that they are not under these terms.
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                 For the list of those files and their copying conditions, see the
         
     | 
| 
      
 45 
     | 
    
         
            +
                 file LEGAL.
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              5. The scripts and library files supplied as input to or produced as 
         
     | 
| 
      
 48 
     | 
    
         
            +
                 output from the software do not automatically fall under the
         
     | 
| 
      
 49 
     | 
    
         
            +
                 copyright of the software, but belong to whomever generated them, 
         
     | 
| 
      
 50 
     | 
    
         
            +
                 and may be sold commercially, and may be aggregated with this
         
     | 
| 
      
 51 
     | 
    
         
            +
                 software.
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
              6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
         
     | 
| 
      
 54 
     | 
    
         
            +
                 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
         
     | 
| 
      
 55 
     | 
    
         
            +
                 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
         
     | 
| 
      
 56 
     | 
    
         
            +
                 PURPOSE.
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -12,16 +12,16 @@ Net::DNS is a DNS library written in pure Ruby. It started as a port of Perl Net 
     | 
|
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
            ## Requirements
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
            Ruby >= 2.1
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
            ## Installation
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
            The best way to install this library is via [RubyGems](https://rubygems.org/).
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 22 
     | 
    
         
            +
            ```
         
     | 
| 
      
 23 
     | 
    
         
            +
            gem install net-dns
         
     | 
| 
      
 24 
     | 
    
         
            +
            ```
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
27 
     | 
    
         
             
            ## API Documentation
         
     | 
| 
         @@ -33,71 +33,80 @@ Visit the page http://rdoc.info/gems/net-dns 
     | 
|
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
            The simplest way to use the library is to invoke the Resolver() method:
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
      
 36 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 37 
     | 
    
         
            +
            require 'rubygems' 
         
     | 
| 
      
 38 
     | 
    
         
            +
            require 'net/dns'
         
     | 
| 
      
 39 
     | 
    
         
            +
            p Resolver("www.google.com")
         
     | 
| 
      
 40 
     | 
    
         
            +
            ```
         
     | 
| 
       39 
41 
     | 
    
         | 
| 
       40 
42 
     | 
    
         
             
            The output is compatible with BIND zone files and it's the same you would get with the dig utility.
         
     | 
| 
       41 
43 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
      
 44 
     | 
    
         
            +
            ```
         
     | 
| 
      
 45 
     | 
    
         
            +
            ;; Answer received from localhost:53 (212 bytes)
         
     | 
| 
      
 46 
     | 
    
         
            +
            ;;
         
     | 
| 
      
 47 
     | 
    
         
            +
            ;; HEADER SECTION
         
     | 
| 
      
 48 
     | 
    
         
            +
            ;; id = 64075
         
     | 
| 
      
 49 
     | 
    
         
            +
            ;; qr = 1       opCode: QUERY   aa = 0  tc = 0  rd = 1
         
     | 
| 
      
 50 
     | 
    
         
            +
            ;; ra = 1       ad = 0  cd = 0  rcode = NoError
         
     | 
| 
      
 51 
     | 
    
         
            +
            ;; qdCount = 1  anCount = 3     nsCount = 4     arCount = 4
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
            ;; QUESTION SECTION (1 record):
         
     | 
| 
      
 54 
     | 
    
         
            +
            ;; google.com.                  IN      A
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
            ;; ANSWER SECTION (3 records):
         
     | 
| 
      
 57 
     | 
    
         
            +
            google.com.             212     IN      A       74.125.45.100
         
     | 
| 
      
 58 
     | 
    
         
            +
            google.com.             212     IN      A       74.125.67.100
         
     | 
| 
      
 59 
     | 
    
         
            +
            google.com.             212     IN      A       209.85.171.100
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
            ;; AUTHORITY SECTION (4 records):
         
     | 
| 
      
 62 
     | 
    
         
            +
            google.com.             345512  IN      NS      ns1.google.com.
         
     | 
| 
      
 63 
     | 
    
         
            +
            google.com.             345512  IN      NS      ns4.google.com.
         
     | 
| 
      
 64 
     | 
    
         
            +
            google.com.             345512  IN      NS      ns2.google.com.
         
     | 
| 
      
 65 
     | 
    
         
            +
            google.com.             345512  IN      NS      ns3.google.com.
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
            ;; ADDITIONAL SECTION (4 records):
         
     | 
| 
      
 68 
     | 
    
         
            +
            ns1.google.com.         170275  IN      A       216.239.32.10
         
     | 
| 
      
 69 
     | 
    
         
            +
            ns2.google.com.         170275  IN      A       216.239.34.10
         
     | 
| 
      
 70 
     | 
    
         
            +
            ns3.google.com.         170275  IN      A       216.239.36.10
         
     | 
| 
      
 71 
     | 
    
         
            +
            ns4.google.com.         170275  IN      A       216.239.38.10
         
     | 
| 
      
 72 
     | 
    
         
            +
            ```
         
     | 
| 
       69 
73 
     | 
    
         | 
| 
       70 
74 
     | 
    
         
             
            An optional block can be passed yielding the Net::DNS::Packet object
         
     | 
| 
       71 
75 
     | 
    
         | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
      
 76 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 77 
     | 
    
         
            +
            Resolver("www.google.com") { |packet| puts packet.size + " bytes" }
         
     | 
| 
      
 78 
     | 
    
         
            +
            # => 484 bytes
         
     | 
| 
      
 79 
     | 
    
         
            +
            ```
         
     | 
| 
       74 
80 
     | 
    
         | 
| 
       75 
81 
     | 
    
         
             
            Same for Net::DNS::Resolver.start():
         
     | 
| 
       76 
82 
     | 
    
         | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
      
 83 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 84 
     | 
    
         
            +
            Net::DNS::Resolver.start("google.com").answer.size
         
     | 
| 
      
 85 
     | 
    
         
            +
            # => 5
         
     | 
| 
      
 86 
     | 
    
         
            +
            ```
         
     | 
| 
       79 
87 
     | 
    
         | 
| 
       80 
88 
     | 
    
         
             
            As optional parameters, +TYPE+ and +CLASS+ can be specified.
         
     | 
| 
       81 
89 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
                ;; QUESTION SECTION (1 record):
         
     | 
| 
       93 
     | 
    
         
            -
                ;; google.com.                  IN      MX
         
     | 
| 
       94 
     | 
    
         
            -
                
         
     | 
| 
       95 
     | 
    
         
            -
                ;; ANSWER SECTION (4 records):
         
     | 
| 
       96 
     | 
    
         
            -
                google.com.             10800   IN      MX      10 smtp2.google.com.
         
     | 
| 
       97 
     | 
    
         
            -
                google.com.             10800   IN      MX      10 smtp3.google.com.
         
     | 
| 
       98 
     | 
    
         
            -
                google.com.             10800   IN      MX      10 smtp4.google.com.
         
     | 
| 
       99 
     | 
    
         
            -
                google.com.             10800   IN      MX      10 smtp1.google.com.
         
     | 
| 
      
 90 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 91 
     | 
    
         
            +
            p Net::DNS::Resolver.start("google.com", Net::DNS::MX)
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
            ;; Answer received from localhost:53 (316 bytes)
         
     | 
| 
      
 94 
     | 
    
         
            +
            ;;
         
     | 
| 
      
 95 
     | 
    
         
            +
            ;; HEADER SECTION
         
     | 
| 
      
 96 
     | 
    
         
            +
            ;; id = 59980
         
     | 
| 
      
 97 
     | 
    
         
            +
            ;; qr = 1       opCode: QUERY   aa = 0  tc = 0  rd = 1
         
     | 
| 
      
 98 
     | 
    
         
            +
            ;; ra = 1       ad = 0  cd = 0  rcode = NoError
         
     | 
| 
      
 99 
     | 
    
         
            +
            ;; qdCount = 1  anCount = 4     nsCount = 4     arCount = 8
         
     | 
| 
       100 
100 
     | 
    
         | 
| 
      
 101 
     | 
    
         
            +
            ;; QUESTION SECTION (1 record):
         
     | 
| 
      
 102 
     | 
    
         
            +
            ;; google.com.                  IN      MX
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
            ;; ANSWER SECTION (4 records):
         
     | 
| 
      
 105 
     | 
    
         
            +
            google.com.             10800   IN      MX      10 smtp2.google.com.
         
     | 
| 
      
 106 
     | 
    
         
            +
            google.com.             10800   IN      MX      10 smtp3.google.com.
         
     | 
| 
      
 107 
     | 
    
         
            +
            google.com.             10800   IN      MX      10 smtp4.google.com.
         
     | 
| 
      
 108 
     | 
    
         
            +
            google.com.             10800   IN      MX      10 smtp1.google.com.
         
     | 
| 
      
 109 
     | 
    
         
            +
            ```
         
     | 
| 
       101 
110 
     | 
    
         | 
| 
       102 
111 
     | 
    
         
             
            ## Handling the response packet
         
     | 
| 
       103 
112 
     | 
    
         | 
| 
         @@ -113,35 +122,43 @@ A DNS packet is divided into 5 sections: 
     | 
|
| 
       113 
122 
     | 
    
         | 
| 
       114 
123 
     | 
    
         
             
            You can access each section by calling the attribute with the same name on a Packet object:
         
     | 
| 
       115 
124 
     | 
    
         | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
      
 125 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 126 
     | 
    
         
            +
            packet = Net::DNS::Resolver.start("google.com")
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
            header = packet.header
         
     | 
| 
      
 129 
     | 
    
         
            +
            answer = packet.answer
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
            puts "The packet is #{packet.data.size} bytes"
         
     | 
| 
      
 132 
     | 
    
         
            +
            puts "It contains #{header.anCount} answer entries"
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
            answer.any? {|ans| p ans}
         
     | 
| 
      
 135 
     | 
    
         
            +
            ```
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
       126 
137 
     | 
    
         
             
            The output is 
         
     | 
| 
       127 
138 
     | 
    
         | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
      
 139 
     | 
    
         
            +
            ```
         
     | 
| 
      
 140 
     | 
    
         
            +
            The packet is 378 bytes
         
     | 
| 
      
 141 
     | 
    
         
            +
            It contains 3 answer entries
         
     | 
| 
      
 142 
     | 
    
         
            +
            google.com.             244     IN      A       74.125.45.100
         
     | 
| 
      
 143 
     | 
    
         
            +
            google.com.             244     IN      A       74.125.67.100
         
     | 
| 
      
 144 
     | 
    
         
            +
            google.com.             244     IN      A       209.85.171.100
         
     | 
| 
      
 145 
     | 
    
         
            +
            ```
         
     | 
| 
       133 
146 
     | 
    
         | 
| 
       134 
147 
     | 
    
         
             
            A better way to handle the answer section is to use the iterators directly on a Packet object:
         
     | 
| 
       135 
148 
     | 
    
         | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
      
 149 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 150 
     | 
    
         
            +
            packet.each_address do |ip|
         
     | 
| 
      
 151 
     | 
    
         
            +
              puts "#{ip} is alive" if Ping.pingecho(ip.to_s, 10, 80)
         
     | 
| 
      
 152 
     | 
    
         
            +
            end
         
     | 
| 
      
 153 
     | 
    
         
            +
            ```
         
     | 
| 
       139 
154 
     | 
    
         | 
| 
       140 
155 
     | 
    
         
             
            Gives:
         
     | 
| 
       141 
156 
     | 
    
         | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
      
 157 
     | 
    
         
            +
            ```
         
     | 
| 
      
 158 
     | 
    
         
            +
            74.125.45.100 is alive
         
     | 
| 
      
 159 
     | 
    
         
            +
            74.125.67.100 is alive
         
     | 
| 
      
 160 
     | 
    
         
            +
            209.85.171.100 is alive
         
     | 
| 
      
 161 
     | 
    
         
            +
            ```
         
     | 
| 
       145 
162 
     | 
    
         | 
| 
       146 
163 
     | 
    
         | 
| 
       147 
164 
     | 
    
         
             
            ## License
         
     | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -1,71 +1,38 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require  
     | 
| 
       2 
     | 
    
         
            -
            require 'bundler'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            $:.unshift(File.dirname(__FILE__) + "/lib")
         
     | 
| 
       5 
     | 
    
         
            -
            require 'net/dns'
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
            # Common package properties
         
     | 
| 
       9 
     | 
    
         
            -
            PKG_NAME    = ENV['PKG_NAME']    || 'net-dns'
         
     | 
| 
       10 
     | 
    
         
            -
            PKG_VERSION = ENV['PKG_VERSION'] || Net::DNS::VERSION
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require "bundler/gem_tasks"
         
     | 
| 
       12 
2 
     | 
    
         | 
| 
       13 
3 
     | 
    
         
             
            # Run test by default.
         
     | 
| 
       14 
     | 
    
         
            -
            task : 
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
            task default: :test
         
     | 
| 
      
 5 
     | 
    
         
            +
            task test: %i[testunit spec]
         
     | 
| 
       16 
6 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
              s.name              = PKG_NAME
         
     | 
| 
       19 
     | 
    
         
            -
              s.version           = PKG_VERSION
         
     | 
| 
       20 
     | 
    
         
            -
              s.summary           = "Pure Ruby DNS library."
         
     | 
| 
       21 
     | 
    
         
            -
              s.description       = "Net::DNS is a pure Ruby DNS library, with a clean OO interface and an extensible API."
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
              s.required_ruby_version = ">= 1.8.7"
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
              s.authors           = ["Marco Ceresa", "Simone Carletti"]
         
     | 
| 
       26 
     | 
    
         
            -
              s.email             = ["ceresa@gmail.com", "weppos@weppos.net"]
         
     | 
| 
       27 
     | 
    
         
            -
              s.homepage          = "http://github.com/bluemonk/net-dns"
         
     | 
| 
       28 
     | 
    
         
            -
              s.rubyforge_project = "net-dns"
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
              s.add_development_dependency "rake",  "~> 10.0"
         
     | 
| 
       31 
     | 
    
         
            -
              s.add_development_dependency "yard"
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'rake/testtask'
         
     | 
| 
       32 
8 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
               
     | 
| 
       35 
     | 
    
         
            -
               
     | 
| 
      
 9 
     | 
    
         
            +
            Rake::TestTask.new(:testunit) do |t|
         
     | 
| 
      
 10 
     | 
    
         
            +
              t.libs = %w[lib test]
         
     | 
| 
      
 11 
     | 
    
         
            +
              t.pattern = "test/**/*_test.rb"
         
     | 
| 
      
 12 
     | 
    
         
            +
              t.verbose = !ENV["VERBOSE"].nil?
         
     | 
| 
      
 13 
     | 
    
         
            +
              t.warning = !ENV["WARNING"].nil?
         
     | 
| 
       36 
14 
     | 
    
         
             
            end
         
     | 
| 
       37 
15 
     | 
    
         | 
| 
      
 16 
     | 
    
         
            +
            require "rubocop/rake_task"
         
     | 
| 
       38 
17 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
            RuboCop::RakeTask.new
         
     | 
| 
       40 
19 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
            require 'rspec/core/rake_task'
         
     | 
| 
      
 21 
     | 
    
         
            +
            begin
         
     | 
| 
      
 22 
     | 
    
         
            +
              require 'fuubar'
         
     | 
| 
      
 23 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
       43 
24 
     | 
    
         
             
            end
         
     | 
| 
       44 
25 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
               
     | 
| 
       48 
     | 
    
         
            -
               
     | 
| 
      
 26 
     | 
    
         
            +
            RSpec::Core::RakeTask.new do |t|
         
     | 
| 
      
 27 
     | 
    
         
            +
              t.verbose = !!ENV["VERBOSE"]
         
     | 
| 
      
 28 
     | 
    
         
            +
              t.rspec_opts = []
         
     | 
| 
      
 29 
     | 
    
         
            +
              t.rspec_opts << ['--format', 'Fuubar'] if defined?(Fuubar)
         
     | 
| 
       49 
30 
     | 
    
         
             
            end
         
     | 
| 
       50 
31 
     | 
    
         | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
            require 'rake/testtask'
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
            # Run all the tests in the /test folder
         
     | 
| 
       55 
     | 
    
         
            -
            Rake::TestTask.new do |t|
         
     | 
| 
       56 
     | 
    
         
            -
              t.libs << "test"
         
     | 
| 
       57 
     | 
    
         
            -
              t.test_files = FileList["test/**/*_test.rb"]
         
     | 
| 
       58 
     | 
    
         
            -
              t.verbose = true
         
     | 
| 
       59 
     | 
    
         
            -
            end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
            require 'yard'
         
     | 
| 
       63 
32 
     | 
    
         
             
            require 'yard/rake/yardoc_task'
         
     | 
| 
       64 
33 
     | 
    
         | 
| 
       65 
     | 
    
         
            -
            YARD::Rake::YardocTask.new(:yardoc)
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
            desc "Open an irb session preloaded with this library"
         
     | 
| 
       69 
     | 
    
         
            -
            task :console do
         
     | 
| 
       70 
     | 
    
         
            -
              sh "irb -rubygems -I lib -r net/dns.rb"
         
     | 
| 
      
 34 
     | 
    
         
            +
            YARD::Rake::YardocTask.new(:yardoc) do |y|
         
     | 
| 
      
 35 
     | 
    
         
            +
              y.options = ["--output-dir", "yardoc"]
         
     | 
| 
       71 
36 
     | 
    
         
             
            end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            CLOBBER.include "yardoc"
         
     | 
    
        data/bin/console
    ADDED
    
    | 
         @@ -0,0 +1,14 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require "bundler/setup"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "net/dns"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            # You can add fixtures and/or initialization code here to make experimenting
         
     | 
| 
      
 7 
     | 
    
         
            +
            # with your gem easier. You can also use a different console, if you like.
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            # (If you use this, don't forget to add pry to your Gemfile!)
         
     | 
| 
      
 10 
     | 
    
         
            +
            # require "pry"
         
     | 
| 
      
 11 
     | 
    
         
            +
            # Pry.start
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            require "irb"
         
     | 
| 
      
 14 
     | 
    
         
            +
            IRB.start
         
     | 
    
        data/demo/check_soa.rb
    CHANGED
    
    | 
         @@ -1,9 +1,8 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #!/usr/bin/env ruby 
     | 
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            require 'rubygems' if  
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rubygems' if RUBY_VERSION.to_s < "1.9.0"
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'net/dns'
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
6 
     | 
    
         
             
            #------------------------------------------------------------------------------
         
     | 
| 
       8 
7 
     | 
    
         
             
            # Get the domain from the command line.
         
     | 
| 
       9 
8 
     | 
    
         
             
            #------------------------------------------------------------------------------
         
     | 
| 
         @@ -16,100 +15,90 @@ domain = ARGV[0] 
     | 
|
| 
       16 
15 
     | 
    
         
             
            # Find all the nameservers for the domain.
         
     | 
| 
       17 
16 
     | 
    
         
             
            #------------------------------------------------------------------------------
         
     | 
| 
       18 
17 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
            res = Net::DNS::Resolver.new(: 
     | 
| 
      
 18 
     | 
    
         
            +
            res = Net::DNS::Resolver.new(defname: false, retry: 2)
         
     | 
| 
       20 
19 
     | 
    
         | 
| 
       21 
20 
     | 
    
         
             
            ns_req = res.query(domain, Net::DNS::NS)
         
     | 
| 
       22 
     | 
    
         
            -
            unless ns_req  
     | 
| 
      
 21 
     | 
    
         
            +
            unless ns_req && (ns_req.header.anCount > 0)
         
     | 
| 
       23 
22 
     | 
    
         
             
              raise ArgumentError, "No nameservers found for domain: #{res.errorstring}"
         
     | 
| 
       24 
23 
     | 
    
         
             
            end
         
     | 
| 
       25 
24 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
25 
     | 
    
         
             
            # Send out non-recursive queries
         
     | 
| 
       28 
26 
     | 
    
         
             
            res.recurse = false
         
     | 
| 
       29 
27 
     | 
    
         
             
            # Do not buffer standard out
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
            # | = 1;
         
     | 
| 
       32 
29 
     | 
    
         | 
| 
       33 
30 
     | 
    
         
             
            #------------------------------------------------------------------------------
         
     | 
| 
       34 
31 
     | 
    
         
             
            # Check the SOA record on each nameserver.
         
     | 
| 
       35 
32 
     | 
    
         
             
            #------------------------------------------------------------------------------
         
     | 
| 
       36 
33 
     | 
    
         | 
| 
       37 
34 
     | 
    
         
             
            ns_req.each_nameserver do |ns|
         
     | 
| 
       38 
     | 
    
         
            -
              
         
     | 
| 
       39 
35 
     | 
    
         
             
              #----------------------------------------------------------------------
         
     | 
| 
       40 
36 
     | 
    
         
             
              # Set the resolver to query this nameserver.
         
     | 
| 
       41 
37 
     | 
    
         
             
              #----------------------------------------------------------------------
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
       43 
39 
     | 
    
         
             
              # In order to lookup the IP(s) of the nameserver, we need a Resolver
         
     | 
| 
       44 
40 
     | 
    
         
             
              # object that is set to our local, recursive nameserver.  So we create
         
     | 
| 
       45 
41 
     | 
    
         
             
              # a new object just to do that.
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
       47 
43 
     | 
    
         
             
              local_res = Net::DNS::Resolver.new
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
       49 
45 
     | 
    
         
             
              a_req = local_res.query(ns, Net::DNS::A)
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
              
         
     | 
| 
       52 
     | 
    
         
            -
              unless a_req 
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              unless a_req
         
     | 
| 
       53 
48 
     | 
    
         
             
                puts "Can not find address for ns: " + res.errorstring + "\n"
         
     | 
| 
       54 
49 
     | 
    
         
             
                next
         
     | 
| 
       55 
50 
     | 
    
         
             
              end
         
     | 
| 
       56 
     | 
    
         
            -
              
         
     | 
| 
       57 
     | 
    
         
            -
              
         
     | 
| 
       58 
     | 
    
         
            -
              a_req.each_address do |ip|
         
     | 
| 
       59 
51 
     | 
    
         | 
| 
      
 52 
     | 
    
         
            +
              a_req.each_address do |ip|
         
     | 
| 
       60 
53 
     | 
    
         
             
                #----------------------------------------------------------------------
         
     | 
| 
       61 
54 
     | 
    
         
             
                # Ask this IP.
         
     | 
| 
       62 
55 
     | 
    
         
             
                #----------------------------------------------------------------------
         
     | 
| 
       63 
     | 
    
         
            -
                res.nameservers=ip 
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
      
 56 
     | 
    
         
            +
                res.nameservers = ip
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
       65 
58 
     | 
    
         
             
                print "#{ns} (#{ip}): "
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
       67 
60 
     | 
    
         
             
                #----------------------------------------------------------------------
         
     | 
| 
       68 
61 
     | 
    
         
             
                # Get the SOA record.
         
     | 
| 
       69 
62 
     | 
    
         
             
                #----------------------------------------------------------------------
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
       71 
64 
     | 
    
         
             
                soa_req = res.send(domain, Net::DNS::SOA, Net::DNS::IN)
         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
                if soa_req 
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                if soa_req.nil?
         
     | 
| 
       74 
67 
     | 
    
         
             
                  puts res.errorstring, "\n"
         
     | 
| 
       75 
68 
     | 
    
         
             
                  next
         
     | 
| 
       76 
69 
     | 
    
         
             
                end
         
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
       78 
71 
     | 
    
         
             
                #----------------------------------------------------------------------
         
     | 
| 
       79 
72 
     | 
    
         
             
                # Is this nameserver authoritative for the domain?
         
     | 
| 
       80 
73 
     | 
    
         
             
                #----------------------------------------------------------------------
         
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
                unless soa_req.header.auth? 
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                unless soa_req.header.auth?
         
     | 
| 
       83 
76 
     | 
    
         
             
                  print "isn't authoritative for domain\n"
         
     | 
| 
       84 
77 
     | 
    
         
             
                  next
         
     | 
| 
       85 
78 
     | 
    
         
             
                end
         
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
       87 
80 
     | 
    
         
             
                #----------------------------------------------------------------------
         
     | 
| 
       88 
81 
     | 
    
         
             
                # We should have received exactly one answer.
         
     | 
| 
       89 
82 
     | 
    
         
             
                #----------------------------------------------------------------------
         
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
                unless soa_req.header.anCount == 1 
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
                unless soa_req.header.anCount == 1
         
     | 
| 
       92 
85 
     | 
    
         
             
                  print "expected 1 answer, got " + soa_req.header.anCount.to_s + "\n"
         
     | 
| 
       93 
86 
     | 
    
         
             
                  next
         
     | 
| 
       94 
87 
     | 
    
         
             
                end
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
       96 
89 
     | 
    
         
             
                #----------------------------------------------------------------------
         
     | 
| 
       97 
90 
     | 
    
         
             
                # Did we receive an SOA record?
         
     | 
| 
       98 
91 
     | 
    
         
             
                #----------------------------------------------------------------------
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
       100 
93 
     | 
    
         
             
                unless soa_req.answer[0].class == Net::DNS::RR::SOA
         
     | 
| 
       101 
94 
     | 
    
         
             
                  print "expected SOA, got " + Net::DNS::RR::RRTypes.to_str(soa_req.answer[0].type) + "\n"
         
     | 
| 
       102 
95 
     | 
    
         
             
                  next
         
     | 
| 
       103 
96 
     | 
    
         
             
                end
         
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
       105 
98 
     | 
    
         
             
                #----------------------------------------------------------------------
         
     | 
| 
       106 
99 
     | 
    
         
             
                # Print the serial number.
         
     | 
| 
       107 
100 
     | 
    
         
             
                #----------------------------------------------------------------------
         
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
       109 
102 
     | 
    
         
             
                print "has serial number " + soa_req.answer[0].serial.to_s + "\n"
         
     | 
| 
       110 
     | 
    
         
            -
                
         
     | 
| 
       111 
103 
     | 
    
         
             
              end
         
     | 
| 
       112 
104 
     | 
    
         
             
            end
         
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
       115 
     | 
    
         
            -
             
     |