Class: Nesser::Question

Inherits:
Object
  • Object
show all
Defined in:
lib/nesser/packets/question.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, cls:) ⇒ Question

Create a question.

The name is a typical dotted name, like “google.com”. The type and cls are DNS-specific values that can be found in constants.rb.



23
24
25
26
27
# File 'lib/nesser/packets/question.rb', line 23

def initialize(name:, type:, cls:)
  @name  = name
  @type  = type
  @cls  = cls
end

Instance Attribute Details

#clsObject (readonly)

Returns the value of attribute cls.



15
16
17
# File 'lib/nesser/packets/question.rb', line 15

def cls
  @cls
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/nesser/packets/question.rb', line 15

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



15
16
17
# File 'lib/nesser/packets/question.rb', line 15

def type
  @type
end

Class Method Details

.unpack(unpacker) ⇒ Object

Parse a question from a DNS packet.



32
33
34
35
36
37
# File 'lib/nesser/packets/question.rb', line 32

def self.unpack(unpacker)
  name = unpacker.unpack_name()
  type, cls = unpacker.unpack("nn")

  return self.new(name: name, type: type, cls: cls)
end

Instance Method Details

#pack(packer) ⇒ Object

Serialize the question.



42
43
44
45
# File 'lib/nesser/packets/question.rb', line 42

def pack(packer)
  packer.pack_name(@name)
  packer.pack('nn', type, cls)
end

#to_sObject



47
48
49
50
51
52
53
# File 'lib/nesser/packets/question.rb', line 47

def to_s()
  return '%s [%s %s]' % [
    @name,
    TYPES[@type] || '<0x%04x?>' % @type,
    CLSES[@cls]  || '<0x%04x?>' % @cls,
  ]
end