Class: Resolv::DNS::Message
- Inherits:
-
Object
- Object
- Resolv::DNS::Message
- Defined in:
- lib/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.
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 |
# File 'lib/resolv.rb', line 1260 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 = [] @authority = [] @additional = [] end |
Instance Attribute Details
#aa ⇒ Object
Returns the value of attribute aa
1275 1276 1277 |
# File 'lib/resolv.rb', line 1275 def aa @aa end |
#additional ⇒ Object (readonly)
Returns the value of attribute additional
1276 1277 1278 |
# File 'lib/resolv.rb', line 1276 def additional @additional end |
#answer ⇒ Object (readonly)
Returns the value of attribute answer
1276 1277 1278 |
# File 'lib/resolv.rb', line 1276 def answer @answer end |
#authority ⇒ Object (readonly)
Returns the value of attribute authority
1276 1277 1278 |
# File 'lib/resolv.rb', line 1276 def @authority end |
#id ⇒ Object
Returns the value of attribute id
1275 1276 1277 |
# File 'lib/resolv.rb', line 1275 def id @id end |
#opcode ⇒ Object
Returns the value of attribute opcode
1275 1276 1277 |
# File 'lib/resolv.rb', line 1275 def opcode @opcode end |
#qr ⇒ Object
Returns the value of attribute qr
1275 1276 1277 |
# File 'lib/resolv.rb', line 1275 def qr @qr end |
#question ⇒ Object (readonly)
Returns the value of attribute question
1276 1277 1278 |
# File 'lib/resolv.rb', line 1276 def question @question end |
#ra ⇒ Object
Returns the value of attribute ra
1275 1276 1277 |
# File 'lib/resolv.rb', line 1275 def ra @ra end |
#rcode ⇒ Object
Returns the value of attribute rcode
1275 1276 1277 |
# File 'lib/resolv.rb', line 1275 def rcode @rcode end |
#rd ⇒ Object
Returns the value of attribute rd
1275 1276 1277 |
# File 'lib/resolv.rb', line 1275 def rd @rd end |
#tc ⇒ Object
Returns the value of attribute tc
1275 1276 1277 |
# File 'lib/resolv.rb', line 1275 def tc @tc end |
Class Method Details
.decode(m) ⇒ Object
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 |
# File 'lib/resolv.rb', line 1432 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
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 |
# File 'lib/resolv.rb', line 1278 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 && @authority == other. && @additional == other.additional end |
#add_additional(name, ttl, data) ⇒ Object
1323 1324 1325 |
# File 'lib/resolv.rb', line 1323 def add_additional(name, ttl, data) @additional << [Name.create(name), ttl, data] end |
#add_answer(name, ttl, data) ⇒ Object
1303 1304 1305 |
# File 'lib/resolv.rb', line 1303 def add_answer(name, ttl, data) @answer << [Name.create(name), ttl, data] end |
#add_authority(name, ttl, data) ⇒ Object
1313 1314 1315 |
# File 'lib/resolv.rb', line 1313 def (name, ttl, data) @authority << [Name.create(name), ttl, data] end |
#add_question(name, typeclass) ⇒ Object
1293 1294 1295 |
# File 'lib/resolv.rb', line 1293 def add_question(name, typeclass) @question << [Name.create(name), typeclass] end |
#each_additional ⇒ Object
1327 1328 1329 1330 1331 |
# File 'lib/resolv.rb', line 1327 def each_additional @additional.each {|name, ttl, data| yield name, ttl, data } end |
#each_answer ⇒ Object
1307 1308 1309 1310 1311 |
# File 'lib/resolv.rb', line 1307 def each_answer @answer.each {|name, ttl, data| yield name, ttl, data } end |
#each_authority ⇒ Object
1317 1318 1319 1320 1321 |
# File 'lib/resolv.rb', line 1317 def @authority.each {|name, ttl, data| yield name, ttl, data } end |
#each_question ⇒ Object
1297 1298 1299 1300 1301 |
# File 'lib/resolv.rb', line 1297 def each_question @question.each {|name, typeclass| yield name, typeclass } end |
#each_resource ⇒ Object
1333 1334 1335 1336 1337 |
# File 'lib/resolv.rb', line 1333 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
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 |
# File 'lib/resolv.rb', line 1339 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, @authority.length, @additional.length) @question.each {|q| name, typeclass = q msg.put_name(name) msg.put_pack('nn', typeclass::TypeValue, typeclass::ClassValue) } [@answer, @authority, @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 |