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

Inherits:
Types::Fields show all
Includes:
Types::Fieldable
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

Methods included from Types::Fieldable

#format_inspect, #read, #sz, #to_s, #type_name

Methods inherited from Types::Fields

#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, fields, #fields, inherited, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

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


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

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)

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

define_field :name, Name, default: '.'

#rrclassInteger

16-bit question class

Returns:

  • (Integer)

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

define_field :rrclass, Types::Int16Enum, default: 1, enum: CLASSES

#typeInteger

16-bit question type

Returns:

  • (Integer)

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

define_field :type, Types::Int16Enum, default: 1, enum: TYPES

Instance Method Details

#human_rrclassString

Get human readable class

Returns:

  • (String)

Since:

  • 1.3.0


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

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


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

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

#to_humanString

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


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

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