Class: Dnsruby::Question
- Inherits:
-
Object
- Object
- Dnsruby::Question
- Defined in:
- lib/Dnsruby/message.rb
Overview
A Dnsruby::Question object represents a record in the question section of a DNS packet.
RFC 1035 Section 4.1.2
Instance Attribute Summary collapse
-
#qclass ⇒ Object
(also: #zclass)
The Question class.
-
#qname ⇒ Object
(also: #zname)
The Question name.
-
#qtype ⇒ Object
(also: #ztype, #type)
The Question type.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Question
constructor
Creates a question object from the domain, type, and class passed as arguments.
-
#to_s ⇒ Object
Returns a string representation of the question record.
Constructor Details
#initialize(*args) ⇒ Question
Creates a question object from the domain, type, and class passed as arguments.
If a String is passed in, a Name, IPv4 or IPv6 object is created.
If an IPv4 or IPv6 object is used then the type is set to PTR.
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 |
# File 'lib/Dnsruby/message.rb', line 1137 def initialize(*args) @qtype = Types::A @qclass = Classes::IN type_given = false if (args.length > 0) if (args.length > 1) @qtype = Types.new(args[1]) type_given = true if (args.length > 2) @qclass = Classes.new(args[2]) end end else raise ArgumentError.new("Must pass at least a name!") end # If the name looks like an IP address then do an appropriate # PTR query, unless the user specified the qtype @qname=args[0] if (!type_given) case @qname.to_s when IPv4::Regex @qname = IPv4.create(@qname).to_name @qtype = Types.PTR when IPv6::Regex @qname = IPv6.create(@qname).to_name @qtype = Types.PTR when Name when IPv6 @qtype = Types.PTR when IPv4 @qtype = Types.PTR else @qname = Name.create(@qname) end else case @qtype when Types.PTR case @qname.to_s when IPv4::Regex @qname = IPv4.create(@qname).to_name when IPv6::Regex @qname = IPv6.create(@qname).to_name when IPv6 when IPv4 else @qname = Name.create(@qname) end else @qname = Name.create(@qname) end end end |
Instance Attribute Details
#qclass ⇒ Object Also known as: zclass
The Question class
1129 1130 1131 |
# File 'lib/Dnsruby/message.rb', line 1129 def qclass @qclass end |
#qname ⇒ Object Also known as: zname
The Question name
1125 1126 1127 |
# File 'lib/Dnsruby/message.rb', line 1125 def qname @qname end |
#qtype ⇒ Object Also known as: ztype, type
The Question type
1127 1128 1129 |
# File 'lib/Dnsruby/message.rb', line 1127 def qtype @qtype end |
Instance Method Details
#to_s ⇒ Object
Returns a string representation of the question record.
1217 1218 1219 |
# File 'lib/Dnsruby/message.rb', line 1217 def to_s return "#{@qname}.\t#{@qclass.string}\t#{@qtype.string}"; end |