Class Net::DNS::Question
In: lib/net/dns/question.rb
Parent: Object

Name

Net::DNS::Question - DNS packet question class

Synopsis

  require 'net/dns/question'

Description

This class represent the Question portion of a DNS packet. The number of question entries is stored in the qdCount variable of an Header object.

A new object can be created passing the name of the query and the type of answer desired, plus an optional argument containing the class:

  question = Net::DNS::Question.new("google.com.", Net::DNS::A)
     #=> "google.com.                   A       IN"

Alternatevly, a new object is created when processing a binary packet, as when an answer is received. To obtain the binary data from a question object you can use the method Question#data:

  question.data
     #=> "\006google\003com\000\000\001\000\001"

A lot of methods were written to keep a compatibility layer with the Perl version of the library, as long as methods name which are more or less the same.

Methods

comp_data   data   inspect   new   parse   to_s  

Included Modules

Names

Classes and Modules

Class Net::DNS::Question::Error
Class Net::DNS::Question::NameInvalid

Attributes

qClass  [R]  class part of a Question entry
qName  [R]  name part of a Question entry
qType  [R]  type part of a Question entry

Public Class methods

If not specified, type and cls arguments defaults to Net::DNS::A and Net::DNS::IN respectively.

Return a new Net::DNS::Question object created by parsing binary data, such as an answer from the nameserver.

  question = Net::DNS::Question.parse(data)
  puts "Queried for #{question.qName} type #{question.qType.to_s}"
    #=> Queried for example.com type A

Public Instance methods

Return the binary data of the objects, plus an offset and an Hash with references to compressed names. For use in Net::DNS::Packet compressed packet creation.

Outputs binary data from a Question object

  question.data
     #=> "\006google\003com\000\000\001\000\001"

Returns a printable version of question with nice formatting.

  q = Net::DNS::Question.new("google.com.", Net::DNS::A)
  q.inspect # => "google.com.                  IN      A       "

Returns a string representation of question. It is the same as inspect.

  q = Net::DNS::Question.new("google.com.", Net::DNS::A)
  q.inspect # => "google.com.                  IN      A       "

[Validate]