Class: PacketGen::Header::DNS::Question

Inherits:
Base show all
Defined in:
lib/packetgen/header/dns/question.rb

Overview

DNS Question

Author:

  • Sylvain Daubert

Direct Known Subclasses

RR

Constant Summary collapse

TYPES =

Ressource Record types

{
  'A'        => 1,
  'NS'       => 2,
  'MD'       => 3,
  'MF'       => 4,
  'CNAME'    => 5,
  'SOA'      => 6,
  'MB'       => 7,
  'MG'       => 8,
  'MR'       => 9,
  'NULL'     => 10,
  'WKS'      => 11,
  'PTR'      => 12,
  'HINFO'    => 13,
  'MINFO'    => 14,
  'MX'       => 15,
  'TXT'      => 16,
  'AAAA'     => 28,
  'NAPTR'    => 35,
  'KX'       => 36,
  'CERT'     => 37,
  'OPT'      => 41,
  'DS'       => 43,
  'RRSIG'    => 46,
  'NSEC'     => 47,
  'DNSKEY'   => 48,
  'TKEY'     => 249,
  'TSIG'     => 250,
  '*'        => 255
}
CLASSES =

Ressource Record classes

{
  'IN'   => 1,
  'CH'   => 3,
  'HS'   => 4,
  'NONE' => 254,
  '*'    => 255
}

Instance Attribute Summary collapse

Attributes inherited from Base

#packet

Instance Method Summary collapse

Methods inherited from Base

bind_header, #header_id, inherited, #ip_header, known_headers, #parse?, #protocol_name

Methods inherited from Types::Fields

#[], #[]=, #body=, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, #force_binary, inherited, #inspect, #read, #sz, #to_h, #to_s

Constructor Details

#initialize(dns, options = {}) ⇒ Question

Returns a new instance of Question.

Parameters:

  • dns (DNS)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :name (String)

    domain as a dotted string

  • :type (Integer, String)

    see TYPES. Default to ‘A’

  • :rrclass (Integer, String)

    see CLASSES. Default to ‘IN’



68
69
70
71
72
73
# File 'lib/packetgen/header/dns/question.rb', line 68

def initialize(dns, options={})
  super(options)
  self[:name].dns = dns
  self.type = options[:type] if options[:type]
  self.rrclass = options[:rrclass] if options[:rrclass]
end

Instance Attribute Details

#nameString

Question domain name

Returns:

  • (String)


12
# File 'lib/packetgen/header/dns/question.rb', line 12

define_field :name, Name, default: '.'

#rrclassInteger

16-bit question class

Returns:

  • (Integer)


20
# File 'lib/packetgen/header/dns/question.rb', line 20

define_field :rrclass, Types::Int16, default: 1

#typeInteger

16-bit question type

Returns:

  • (Integer)


16
# File 'lib/packetgen/header/dns/question.rb', line 16

define_field :type, Types::Int16, default: 1

Instance Method Details

#has_type?(type) ⇒ Boolean

Check type

Parameters:

  • type (String)

    name

Returns:

  • (Boolean)


106
107
108
# File 'lib/packetgen/header/dns/question.rb', line 106

def has_type?(type)
  self.class::TYPES[type] == self.type
end

#human_rrclassString

Get human readable class

Returns:

  • (String)


118
119
120
# File 'lib/packetgen/header/dns/question.rb', line 118

def human_rrclass
  self.class::CLASSES.key(self.rrclass) || "0x%04x" % self.rrclass
end

#human_typeString

Get human readable type

Returns:

  • (String)


112
113
114
# File 'lib/packetgen/header/dns/question.rb', line 112

def human_type
  self.class::TYPES.key(type) || "0x%04x" % type
end

#to_humanString

Returns:

  • (String)


123
124
125
# File 'lib/packetgen/header/dns/question.rb', line 123

def to_human
  "#{human_type} #{human_rrclass} #{name}"
end