Class: DNS::Question

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

Overview

– The question section is used to carry the “question” in most queries, i.e., the parameters that define what is being asked. The section contains QDCOUNT (usually 1) entries, each of the following format:

                                1  1  1  1  1  1
  0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                                               |
/                     QNAME                     /
/                                               /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                     QTYPE                     |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                     QCLASS                    |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

where:

QNAME a domain name represented as a sequence of labels, where

each label consists of a length octet followed by that
number of octets.  The domain name terminates with the
zero length octet for the null label of the root.  Note
that this field may be an odd number of octets; no
padding is used.

QTYPE a two octet code which specifies the type of the query.

The values for this field include all codes valid for a
TYPE field, together with some more general codes which
can match more than one type of RR.

QCLASS a two octet code that specifies the class of the query.

For example, the QCLASS field is IN for the Internet.

++

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(what = {}) ⇒ Question

Returns a new instance of Question.



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/faildns/question.rb', line 76

def initialize (what={})
  if !what.is_a? Hash
    raise ArgumentError.new('You have to pass a Hash.')
  end

  @data = what

  if block_given?
    yield self
  end
end

Class Method Details

.length(string) ⇒ Object



70
71
72
73
74
# File 'lib/faildns/question.rb', line 70

def self.length (string)
  DomainName.length(string) + QType.length + QClass.length

  return result
end

.parse(string, original) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/faildns/question.rb', line 62

def self.parse (string, original)
  Question.new {|q|
    q.name  = DomainName.parse(string, original);
    q.type  = QType.parse(string);
    q.class = QClass.parse(string);
  }
end

Instance Method Details

#classObject



90
# File 'lib/faildns/question.rb', line 90

def class; @data[:QCLASS] end

#class=(val) ⇒ Object



94
# File 'lib/faildns/question.rb', line 94

def class= (val); @data[:QCLASS] = QClass.new(val)     end

#nameObject



88
# File 'lib/faildns/question.rb', line 88

def name;  @data[:QNAME]  end

#name=(val) ⇒ Object



92
# File 'lib/faildns/question.rb', line 92

def name= (val);  @data[:QNAME]  = DomainName.new(val) end

#packObject



96
97
98
# File 'lib/faildns/question.rb', line 96

def pack
  self.name.pack + self.type.pack + self.class.pack
end

#typeObject



89
# File 'lib/faildns/question.rb', line 89

def type;  @data[:QTYPE]  end

#type=(val) ⇒ Object



93
# File 'lib/faildns/question.rb', line 93

def type= (val);  @data[:QTYPE]  = QType.new(val)      end