Class: Net::DNS::Question
- Inherits:
-
Object
- Object
- Net::DNS::Question
- Includes:
- Names
- Defined in:
- lib/net/dns/question.rb
Overview
Name
Net::DNS::Question - DNS packet question class
Synopsis
require 'net/dns/question'
Description
This class represent the Question portion of a DNS packet. The number of question entries is stored in the qdCount
variable of an Header object.
A new object can be created passing the name of the query and the type of answer desired, plus an optional argument containing the class:
question = Net::DNS::Question.new("google.com.", Net::DNS::A)
#=> "google.com. A IN"
Alternatevly, a new object is created when processing a binary packet, as when an answer is received. To obtain the binary data from a question object you can use the method Question#data:
question.data
#=> "\006google\003com\000\000\001\000\001"
A lot of methods were written to keep a compatibility layer with the Perl version of the library, as long as methods name which are more or less the same.
Defined Under Namespace
Classes: Error, NameInvalid
Constant Summary
Constants included from Names
Instance Attribute Summary collapse
-
#qClass ⇒ Object
readonly
class
part of a Question entry. -
#qName ⇒ Object
readonly
name
part of a Question entry. -
#qType ⇒ Object
readonly
type
part of a Question entry.
Class Method Summary collapse
-
.parse(arg) ⇒ Object
Return a new Net::DNS::Question object created by parsing binary data, such as an answer from the nameserver.
Instance Method Summary collapse
-
#comp_data ⇒ Object
Return the binary data of the objects, plus an offset and an Hash with references to compressed names.
-
#data ⇒ Object
Outputs binary data from a Question object.
-
#initialize(name, type = Net::DNS::A, cls = Net::DNS::IN) ⇒ Question
constructor
If not specified,
type
andcls
arguments defaults to Net::DNS::A and Net::DNS::IN respectively. -
#inspect ⇒ Object
call-seq: question.inspect -> string.
-
#to_s ⇒ Object
call-seq: question.to_s -> string.
Methods included from Names
#dn_comp, #dn_expand, #names_array, #pack_name, #valid?
Constructor Details
#initialize(name, type = Net::DNS::A, cls = Net::DNS::IN) ⇒ Question
If not specified, type
and cls
arguments defaults to Net::DNS::A and Net::DNS::IN respectively.
67 68 69 70 71 |
# File 'lib/net/dns/question.rb', line 67 def initialize(name, type = Net::DNS::A, cls = Net::DNS::IN) @qName = check_name name @qType = Net::DNS::RR::Types.new(type) @qClass = Net::DNS::RR::Classes.new(cls) end |
Instance Attribute Details
#qClass ⇒ Object (readonly)
class
part of a Question entry
53 54 55 |
# File 'lib/net/dns/question.rb', line 53 def qClass @qClass end |
#qName ⇒ Object (readonly)
name
part of a Question entry
49 50 51 |
# File 'lib/net/dns/question.rb', line 49 def qName @qName end |
#qType ⇒ Object (readonly)
type
part of a Question entry
51 52 53 |
# File 'lib/net/dns/question.rb', line 51 def qType @qType end |
Class Method Details
.parse(arg) ⇒ Object
81 82 83 84 85 |
# File 'lib/net/dns/question.rb', line 81 def self.parse(arg) o = allocate o.send(:new_from_binary, arg.to_s) o end |
Instance Method Details
#comp_data ⇒ Object
Return the binary data of the objects, plus an offset and an Hash with references to compressed names. For use in Net::DNS::Packet compressed packet creation.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/net/dns/question.rb', line 99 def comp_data arr = @qName.split(".") str = pack_name(@qName) string = "" names = {} offset = Net::DNS::HFIXEDSZ arr.size.times do |i| x = i+1 elem = arr[-x] len = elem.size string = ((string.reverse)+([len,elem].pack("Ca*")).reverse).reverse names[string] = offset offset += len end offset += 2 * Net::DNS::INT16SZ str += "\000" [[str,@qType.to_i,@qClass.to_i].pack("a*nn"),offset,names] end |
#data ⇒ Object
Outputs binary data from a Question object
question.data
#=> "\006google\003com\000\000\001\000\001"
92 93 94 |
# File 'lib/net/dns/question.rb', line 92 def data [pack_name(@qName),@qType.to_i,@qClass.to_i].pack("a*nn") end |
#inspect ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/net/dns/question.rb', line 128 def inspect if @qName.size > 29 then len = @qName.size + 1 else len = 29 end [@qName, @qClass.to_s, @qType.to_s].pack("A#{len} A8 A8") end |