Method: Dap::Filter::FilterDecodeDNSVersionReply#decode

Defined in:
lib/dap/filter/udp.rb

#decode(data) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dap/filter/udp.rb', line 48

def decode(data)
  begin
    r = Net::DNS::Packet.parse(data)
  rescue ::Exception
    r = nil
  end

  unless r
    begin
      # Perhaps a TCP DNS response, trim the first two bytes (length value)
      # and try again..
      trimmed_data = data[2..-1]
      r = Net::DNS::Packet.parse(trimmed_data)
    rescue ::Exception
      return {}
    end
  end

  return {} unless r

  begin
    # XXX: This can throw an exception on bad data
    vers = r.answer.map{|x| x.txt.strip rescue nil }.reject{|x| x.nil? }.first
    return {} unless vers
    return { 'dns_version' => vers }
  rescue ::Exception
    {}
  end
end