Class: Resolv::DNS::Message
- Inherits:
-
Object
- Object
- Resolv::DNS::Message
- Defined in:
- lib/rubysl/resolv/resolv.rb
Overview
:nodoc:
Defined Under Namespace
Classes: MessageDecoder, MessageEncoder
Constant Summary collapse
- @@identifier =
-1
Instance Attribute Summary collapse
-
#aa ⇒ Object
Returns the value of attribute aa.
-
#additional ⇒ Object
readonly
Returns the value of attribute additional.
-
#answer ⇒ Object
readonly
Returns the value of attribute answer.
-
#authority ⇒ Object
readonly
Returns the value of attribute authority.
-
#id ⇒ Object
Returns the value of attribute id.
-
#opcode ⇒ Object
Returns the value of attribute opcode.
-
#qr ⇒ Object
Returns the value of attribute qr.
-
#question ⇒ Object
readonly
Returns the value of attribute question.
-
#ra ⇒ Object
Returns the value of attribute ra.
-
#rcode ⇒ Object
Returns the value of attribute rcode.
-
#rd ⇒ Object
Returns the value of attribute rd.
-
#tc ⇒ Object
Returns the value of attribute tc.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_additional(name, ttl, data) ⇒ Object
- #add_answer(name, ttl, data) ⇒ Object
- #add_authority(name, ttl, data) ⇒ Object
- #add_question(name, typeclass) ⇒ Object
- #each_additional ⇒ Object
- #each_answer ⇒ Object
- #each_authority ⇒ Object
- #each_question ⇒ Object
- #each_resource ⇒ Object
- #encode ⇒ Object
-
#initialize(id = (@@identifier += 1) & 0xffff) ⇒ Message
constructor
A new instance of Message.
Constructor Details
#initialize(id = (@@identifier += 1) & 0xffff) ⇒ Message
Returns a new instance of Message.
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 |
# File 'lib/rubysl/resolv/resolv.rb', line 1143 def initialize(id = (@@identifier += 1) & 0xffff) @id = id @qr = 0 @opcode = 0 @aa = 0 @tc = 0 @rd = 0 # recursion desired @ra = 0 # recursion available @rcode = 0 @question = [] @answer = [] = [] @additional = [] end |
Instance Attribute Details
#aa ⇒ Object
Returns the value of attribute aa.
1158 1159 1160 |
# File 'lib/rubysl/resolv/resolv.rb', line 1158 def aa @aa end |
#additional ⇒ Object (readonly)
Returns the value of attribute additional.
1159 1160 1161 |
# File 'lib/rubysl/resolv/resolv.rb', line 1159 def additional @additional end |
#answer ⇒ Object (readonly)
Returns the value of attribute answer.
1159 1160 1161 |
# File 'lib/rubysl/resolv/resolv.rb', line 1159 def answer @answer end |
#authority ⇒ Object (readonly)
Returns the value of attribute authority.
1159 1160 1161 |
# File 'lib/rubysl/resolv/resolv.rb', line 1159 def end |
#id ⇒ Object
Returns the value of attribute id.
1158 1159 1160 |
# File 'lib/rubysl/resolv/resolv.rb', line 1158 def id @id end |
#opcode ⇒ Object
Returns the value of attribute opcode.
1158 1159 1160 |
# File 'lib/rubysl/resolv/resolv.rb', line 1158 def opcode @opcode end |
#qr ⇒ Object
Returns the value of attribute qr.
1158 1159 1160 |
# File 'lib/rubysl/resolv/resolv.rb', line 1158 def qr @qr end |
#question ⇒ Object (readonly)
Returns the value of attribute question.
1159 1160 1161 |
# File 'lib/rubysl/resolv/resolv.rb', line 1159 def question @question end |
#ra ⇒ Object
Returns the value of attribute ra.
1158 1159 1160 |
# File 'lib/rubysl/resolv/resolv.rb', line 1158 def ra @ra end |
#rcode ⇒ Object
Returns the value of attribute rcode.
1158 1159 1160 |
# File 'lib/rubysl/resolv/resolv.rb', line 1158 def rcode @rcode end |
#rd ⇒ Object
Returns the value of attribute rd.
1158 1159 1160 |
# File 'lib/rubysl/resolv/resolv.rb', line 1158 def rd @rd end |
#tc ⇒ Object
Returns the value of attribute tc.
1158 1159 1160 |
# File 'lib/rubysl/resolv/resolv.rb', line 1158 def tc @tc end |
Class Method Details
.decode(m) ⇒ Object
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 |
# File 'lib/rubysl/resolv/resolv.rb', line 1315 def Message.decode(m) o = Message.new(0) MessageDecoder.new(m) {|msg| id, flag, qdcount, ancount, nscount, arcount = msg.get_unpack('nnnnnn') o.id = id o.qr = (flag >> 15) & 1 o.opcode = (flag >> 11) & 15 o.aa = (flag >> 10) & 1 o.tc = (flag >> 9) & 1 o.rd = (flag >> 8) & 1 o.ra = (flag >> 7) & 1 o.rcode = flag & 15 (1..qdcount).each { name, typeclass = msg.get_question o.add_question(name, typeclass) } (1..ancount).each { name, ttl, data = msg.get_rr o.add_answer(name, ttl, data) } (1..nscount).each { name, ttl, data = msg.get_rr o.(name, ttl, data) } (1..arcount).each { name, ttl, data = msg.get_rr o.add_additional(name, ttl, data) } } return o end |
Instance Method Details
#==(other) ⇒ Object
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 |
# File 'lib/rubysl/resolv/resolv.rb', line 1161 def ==(other) return @id == other.id && @qr == other.qr && @opcode == other.opcode && @aa == other.aa && @tc == other.tc && @rd == other.rd && @ra == other.ra && @rcode == other.rcode && @question == other.question && @answer == other.answer && == other. && @additional == other.additional end |
#add_additional(name, ttl, data) ⇒ Object
1206 1207 1208 |
# File 'lib/rubysl/resolv/resolv.rb', line 1206 def add_additional(name, ttl, data) @additional << [Name.create(name), ttl, data] end |
#add_answer(name, ttl, data) ⇒ Object
1186 1187 1188 |
# File 'lib/rubysl/resolv/resolv.rb', line 1186 def add_answer(name, ttl, data) @answer << [Name.create(name), ttl, data] end |
#add_authority(name, ttl, data) ⇒ Object
1196 1197 1198 |
# File 'lib/rubysl/resolv/resolv.rb', line 1196 def (name, ttl, data) << [Name.create(name), ttl, data] end |
#add_question(name, typeclass) ⇒ Object
1176 1177 1178 |
# File 'lib/rubysl/resolv/resolv.rb', line 1176 def add_question(name, typeclass) @question << [Name.create(name), typeclass] end |
#each_additional ⇒ Object
1210 1211 1212 1213 1214 |
# File 'lib/rubysl/resolv/resolv.rb', line 1210 def each_additional @additional.each {|name, ttl, data| yield name, ttl, data } end |
#each_answer ⇒ Object
1190 1191 1192 1193 1194 |
# File 'lib/rubysl/resolv/resolv.rb', line 1190 def each_answer @answer.each {|name, ttl, data| yield name, ttl, data } end |
#each_authority ⇒ Object
1200 1201 1202 1203 1204 |
# File 'lib/rubysl/resolv/resolv.rb', line 1200 def .each {|name, ttl, data| yield name, ttl, data } end |
#each_question ⇒ Object
1180 1181 1182 1183 1184 |
# File 'lib/rubysl/resolv/resolv.rb', line 1180 def each_question @question.each {|name, typeclass| yield name, typeclass } end |
#each_resource ⇒ Object
1216 1217 1218 1219 1220 |
# File 'lib/rubysl/resolv/resolv.rb', line 1216 def each_resource each_answer {|name, ttl, data| yield name, ttl, data} {|name, ttl, data| yield name, ttl, data} each_additional {|name, ttl, data| yield name, ttl, data} end |
#encode ⇒ Object
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 |
# File 'lib/rubysl/resolv/resolv.rb', line 1222 def encode return MessageEncoder.new {|msg| msg.put_pack('nnnnnn', @id, (@qr & 1) << 15 | (@opcode & 15) << 11 | (@aa & 1) << 10 | (@tc & 1) << 9 | (@rd & 1) << 8 | (@ra & 1) << 7 | (@rcode & 15), @question.length, @answer.length, .length, @additional.length) @question.each {|q| name, typeclass = q msg.put_name(name) msg.put_pack('nn', typeclass::TypeValue, typeclass::ClassValue) } [@answer, , @additional].each {|rr| rr.each {|r| name, ttl, data = r msg.put_name(name) msg.put_pack('nnN', data.class::TypeValue, data.class::ClassValue, ttl) msg.put_length16 {data.encode_rdata(msg)} } } }.to_s end |