# File lib/rev/dns_resolver.rb, line 139
139:     def response_address(message)
140:       # Confirm the ID field
141:       id = message[0..1].unpack('n').first.to_i
142:       return unless id == 2
143: 
144:       # Check the QR value and confirm this message is a response
145:       qr = message[2].unpack('B1').first.to_i
146:       return unless qr == 1
147: 
148:       # Check the RCODE (lower nibble) and ensure there wasn't an error
149:       rcode = message[3].unpack('B8').first[4..7].to_i(2)
150:       return unless rcode == 0
151: 
152:       # Extract the question and answer counts
153:       qdcount, ancount = message[4..7].unpack('nn').map { |n| n.to_i }
154: 
155:       # We only asked one question
156:       return unless qdcount == 1
157:       message.slice!(0, 12)
158: 
159:       # Make sure it's the same question
160:       return unless message[0..(@question.size-1)] == @question
161:       message.slice!(0, @question.size)
162: 
163:       # Extract the RDLENGTH
164:       while not message.empty?
165:         type = message[2..3].unpack('n').first.to_i
166:         rdlength = message[10..11].unpack('n').first.to_i
167:         rdata = message[12..(12 + rdlength - 1)]
168:         message.slice!(0, 12 + rdlength)
169: 
170:         # Only IPv4 supported
171:         next unless rdlength == 4
172: 
173:         # If we got an Internet address back, return it
174:         return rdata.unpack('CCCC').join('.') if type == 1
175:       end
176: 
177:       nil
178:     end