Class Dnsruby::Message
In: lib/Dnsruby/message.rb
Parent: Object

Defines a DNS packet.

RFC 1035 Section 4.1, RFC 2136 Section 2, RFC 2845

Sections

Message objects have five sections:

  • The header section, a Dnsruby::Header object.
        msg.header=Header.new(...)
        header = msg.header
    
  • The question section, an array of Dnsruby::Question objects.
        msg.add_question(Question.new(domain, type, klass))
        msg.each_question do |question|  ....   end
    
  • The answer section, an array of Dnsruby::RR objects.
        msg.add_answer(RR.create({:name    => "a2.example.com",
                     :type    => "A", :address => "10.0.0.2"}))
        msg.each_answer {|answer| ... }
    
  • The authority section, an array of Dnsruby::RR objects.
        msg.add_authority(rr)
        msg.each_authority {|rr| ... }
    
  • The additional section, an array of Dnsruby::RR objects.
        msg.add_additional(rr)
        msg.each_additional {|rr| ... }
    

In addition, each_resource iterates the answer, additional and authority sections :

      msg.each_resource {|rr| ... }

Packet format encoding

      Dnsruby::Message#encode
      Dnsruby::Message::decode(data)

Methods

External Aliases

question -> zone
  In dynamic update packets, the question section is known as zone and specifies the zone to be updated.
answer -> pre
  In dynamic update packets, the answer section is known as pre or prerequisite and specifies the RRs or RRsets which must or must not preexist.
add_answer -> add_pre
pre -> prerequisite
  In dynamic update packets, the answer section is known as pre or prerequisite and specifies the RRs or RRsets which must or must not preexist.
add_pre -> add_prerequisite
authority -> update
  In dynamic update packets, the authority section is known as update and specifies the RRs or RRsets to be added or delted.
add_authority -> add_update

Attributes

additional  [R]  The additional section, an array of Dnsruby::RR objects.
answer  [R]  The answer section, an array of Dnsruby::RR objects.
answerfrom  [RW]  If this Message is a response from a server, then answerfrom contains the address of the server
answersize  [RW]  If this Message is a response from a server, then answersize contains the size of the response
authority  [R]  The authority section, an array of Dnsruby::RR objects.
header  [RW]  The header section, a Dnsruby::Header object.
querytsig  [R] 
question  [R]  The question section, an array of Dnsruby::Question objects.
tsigerror  [R] 
tsigkey  [RW] 
tsigstart  [RW] 
tsigstate  [RW] 

Public Class methods

Decode the encoded message

Create a new Message. Takes optional name, type and class

type defaults to A, and klass defaults to IN

   Dnsruby::Message.new("example.com") # defaults to A, IN
   Dnsruby::Message.new("example.com", 'AAAA')
   Dnsruby::Message.new("example.com", Dnsruby::Types.PTR, "HS")

Public Instance methods

Add a new Question to the Message. Takes either a Question, or a name, and an optional type and class.

msg.add_question(Question.new("example.com", ‘MX’)) msg.add_question("example.com") # defaults to Types.A, Classes.IN msg.add_question("example.com", Types.LOC)

add_zone(question, type=Types.A, klass=Classes.IN)

Alias for add_question

each_pre()

Alias for each_answer

each_prerequisite()

Alias for each_pre

each_update()

Alias for each_authority

each_zone()

Alias for each_question

Return the encoded form of the message

Was this message signed by a TSIG?

If this message was signed by a TSIG, was the TSIG verified?

Returns the TSIG record from the ADDITIONAL section, if one is present.

[Validate]