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.
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.
1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 |
# File 'lib/resolv.rb', line 1519 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.
1534 1535 1536 |
# File 'lib/resolv.rb', line 1534 def aa @aa end |
#additional ⇒ Object (readonly)
Returns the value of attribute additional.
1535 1536 1537 |
# File 'lib/resolv.rb', line 1535 def additional @additional end |
#answer ⇒ Object (readonly)
Returns the value of attribute answer.
1535 1536 1537 |
# File 'lib/resolv.rb', line 1535 def answer @answer end |
#authority ⇒ Object (readonly)
Returns the value of attribute authority.
1535 1536 1537 |
# File 'lib/resolv.rb', line 1535 def end |
#id ⇒ Object
Returns the value of attribute id.
1534 1535 1536 |
# File 'lib/resolv.rb', line 1534 def id @id end |
#opcode ⇒ Object
Returns the value of attribute opcode.
1534 1535 1536 |
# File 'lib/resolv.rb', line 1534 def opcode @opcode end |
#qr ⇒ Object
Returns the value of attribute qr.
1534 1535 1536 |
# File 'lib/resolv.rb', line 1534 def qr @qr end |
#question ⇒ Object (readonly)
Returns the value of attribute question.
1535 1536 1537 |
# File 'lib/resolv.rb', line 1535 def question @question end |
#ra ⇒ Object
Returns the value of attribute ra.
1534 1535 1536 |
# File 'lib/resolv.rb', line 1534 def ra @ra end |
#rcode ⇒ Object
Returns the value of attribute rcode.
1534 1535 1536 |
# File 'lib/resolv.rb', line 1534 def rcode @rcode end |
#rd ⇒ Object
Returns the value of attribute rd.
1534 1535 1536 |
# File 'lib/resolv.rb', line 1534 def rd @rd end |
#tc ⇒ Object
Returns the value of attribute tc.
1534 1535 1536 |
# File 'lib/resolv.rb', line 1534 def tc @tc end |
Instance Method Details
#==(other) ⇒ Object
1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 |
# File 'lib/resolv.rb', line 1537 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_equal?(other.question) && @answer == other.answer && == other. && @additional == other.additional end |
#add_additional(name, ttl, data) ⇒ Object
1594 1595 1596 |
# File 'lib/resolv.rb', line 1594 def add_additional(name, ttl, data) @additional << [Name.create(name), ttl, data] end |
#add_answer(name, ttl, data) ⇒ Object
1574 1575 1576 |
# File 'lib/resolv.rb', line 1574 def add_answer(name, ttl, data) @answer << [Name.create(name), ttl, data] end |
#add_authority(name, ttl, data) ⇒ Object
1584 1585 1586 |
# File 'lib/resolv.rb', line 1584 def (name, ttl, data) << [Name.create(name), ttl, data] end |
#add_question(name, typeclass) ⇒ Object
1564 1565 1566 |
# File 'lib/resolv.rb', line 1564 def add_question(name, typeclass) @question << [Name.create(name), typeclass] end |
#each_additional ⇒ Object
1598 1599 1600 1601 1602 |
# File 'lib/resolv.rb', line 1598 def each_additional @additional.each {|name, ttl, data| yield name, ttl, data } end |
#each_answer ⇒ Object
1578 1579 1580 1581 1582 |
# File 'lib/resolv.rb', line 1578 def each_answer @answer.each {|name, ttl, data| yield name, ttl, data } end |
#each_authority ⇒ Object
1588 1589 1590 1591 1592 |
# File 'lib/resolv.rb', line 1588 def .each {|name, ttl, data| yield name, ttl, data } end |
#each_question ⇒ Object
1568 1569 1570 1571 1572 |
# File 'lib/resolv.rb', line 1568 def each_question @question.each {|name, typeclass| yield name, typeclass } end |
#each_resource ⇒ Object
1604 1605 1606 1607 1608 |
# File 'lib/resolv.rb', line 1604 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
1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 |
# File 'lib/resolv.rb', line 1610 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 |