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)

Additional information

security_level records the current DNSSEC status of this Message. answerfrom records the server which this Message was received from. cached records whether this response came from the cache.

Methods

Classes and Modules

Class Dnsruby::Message::Section
Class Dnsruby::Message::SecurityLevel

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
answerip  [RW]  If this Message is a response from a server, then answerfrom contains the IP 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.
cached  [RW]  If the Message was returned from the cache, the cached flag will be set true. It will be false otherwise.
do_caching  [RW]  do_caching is set by default. If you do not wish dnsruby to inspect the cache before sending the query, nor cache the result of the query, then set do_caching to false.
do_validation  [RW]  do_validation is set by default. If you do not wish dnsruby to validate this message (on a Resolver with @dnssec==true), then set do_validation to false. This option does not affect caching, or the header options
header  [RW]  The header section, a Dnsruby::Header object.
question  [R]  The question section, an array of Dnsruby::Question objects.
security_error  [RW]  If there was a problem verifying this message with DNSSEC, then securiy_error will hold a description of the problem. It defaults to ""
security_level  [RW]  If dnssec is set on, then each message will have the security level set To find the precise error (if any), call Dnsruby::Dnssec::validate(msg) - the resultant exception will define the error.
send_raw  [RW]  Set send_raw if you wish to send and receive the response to this Message with no additional processing. In other words, if set, then Dnsruby will not touch the Header of the outgoing Message. This option does not affect caching or dnssec validation

This option should not normally be set.

tsigerror  [RW]  If this message has been verified using a TSIG RR then tsigerror contains the error code returned by the TSIG verification. The error will be an RCode
tsigstart  [RW] 
tsigstate  [RW]  Can be
  • :Unsigned - the default state
  • :Signed - the outgoing message has been signed
  • :Verified - the incoming message has been verified by TSIG
  • :Intermediate - the incoming message is an intermediate envelope in a TCP session

in which only every 100th envelope must be signed

  • :Failed - the incoming response failed verification

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

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

Yields each section (question, answer, authority, additional)

each_update()

Alias for each_authority

each_zone()

Alias for each_question

Return the encoded form of the message

 If there is a TSIG record present and the record has not been signed
 then sign it

Return the first rrset of the specified attributes in the message

Return the rrsets of the specified type in the message

Return a hash, with the section as key, and the RRSets in that section as the data : {section => section_rrs}

Sets the TSIG to sign this message with. Can either be a Dnsruby::RR::TSIG object, or it can be a (name, key) tuple, or it can be a hash which takes Dnsruby::RR::TSIG attributes (e.g. name, key, fudge, etc.)

Was this message signed by a TSIG?

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

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

[Validate]