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

Inherits:
BinStruct::Struct
  • Object
show all
Includes:
BinStruct::Structable
Defined in:
lib/packetgen/header/dns/question.rb

Overview

DNS Question

Author:

  • Sylvain Daubert

Since:

  • 1.3.0

Direct Known Subclasses

RR

Constant Summary collapse

TYPES =

Ressource Record types

Since:

  • 1.3.0

{
  '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,
  'SRV' => 33,
  'NAPTR' => 35,
  'KX' => 36,
  'CERT' => 37,
  'OPT' => 41,
  'DS' => 43,
  'RRSIG' => 46,
  'NSEC' => 47,
  'DNSKEY' => 48,
  'TKEY' => 249,
  'TSIG' => 250,
  '*' => 255
}.freeze
CLASSES =

Ressource Record classes

Since:

  • 1.3.0

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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’

Since:

  • 1.3.0



77
78
79
80
# File 'lib/packetgen/header/dns/question.rb', line 77

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

Instance Attribute Details

#nameString

Question domain name

Returns:

  • (String)


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

define_attr :name, Name, default: '.'

#rrclassInteger

16-bit question class

Returns:

  • (Integer)


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

define_attr :rrclass, BinStruct::Int16Enum, default: 1, enum: CLASSES

#typeInteger

16-bit question type

Returns:

  • (Integer)


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

define_attr :type, BinStruct::Int16Enum, default: 1, enum: TYPES

Instance Method Details

#human_rrclassString

Get human readable class

Returns:

  • (String)

Since:

  • 1.3.0



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

def human_rrclass
  if self[:name].dns.is_a? MDNS
    self.class::CLASSES.key(self.rrclass & 0x7fff) || '0x%04x' % (self.rrclass & 0x7fff)
  else
    self.class::CLASSES.key(self.rrclass) || '0x%04x' % self.rrclass
  end
end

#human_typeString

Get human readable type

Returns:

  • (String)

Since:

  • 1.3.0



109
110
111
# File 'lib/packetgen/header/dns/question.rb', line 109

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

#to_humanString

Human-readable string for this question

Returns:

  • (String)

Since:

  • 1.3.0



125
126
127
128
129
130
131
132
# File 'lib/packetgen/header/dns/question.rb', line 125

def to_human
  if self[:name].dns.is_a? MDNS
    unicast_bit = self.rrclass & 0x8000 == 0x8000 ? 'QU' : 'QM'
    "#{human_type} #{human_rrclass} #{unicast_bit} #{name}"
  else
    "#{human_type} #{human_rrclass} #{name}"
  end
end

#type?(type) ⇒ Boolean

Check type

Parameters:

  • type (String)

    name

Returns:

  • (Boolean)

Since:

  • 2.7.0



103
104
105
# File 'lib/packetgen/header/dns/question.rb', line 103

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