def response_address(message)
id = message[0..1].unpack('n').first.to_i
return unless id == 2
qr = message[2..2].unpack('B1').first.to_i
return unless qr == 1
rcode = message[3..3].unpack('B8').first[4..7].to_i(2)
return unless rcode == 0
qdcount, ancount = message[4..7].unpack('nn').map { |n| n.to_i }
return unless qdcount == 1
message.slice!(0, 12)
return unless message[0..(@question.size-1)] == @question
message.slice!(0, @question.size)
while not message.empty?
type = message[2..3].unpack('n').first.to_i
rdlength = message[10..11].unpack('n').first.to_i
rdata = message[12..(12 + rdlength - 1)]
message.slice!(0, 12 + rdlength)
next unless rdlength == 4
return rdata.unpack('CCCC').join('.') if type == 1
end
nil
end