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

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



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

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)


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

define_field :name, Name, default: '.'

#rrclassInteger

16-bit question class

Returns:

  • (Integer)


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

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

#typeInteger

16-bit question type

Returns:

  • (Integer)


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

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

Instance Method Details

#human_rrclassString

Get human readable class

Returns:

  • (String)

Since:

  • 1.3.0



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

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



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

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

#to_humanString

Returns:

  • (String)

Since:

  • 1.3.0



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

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



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

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