Class: Dnsruby::Question

Inherits:
Object
  • Object
show all
Defined in:
lib/Dnsruby/message.rb

Overview

A Dnsruby::Question object represents a record in the question section of a DNS packet.

RFC 1035 Section 4.1.2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Question

Creates a question object from the domain, type, and class passed as arguments.

If a String is passed in, a Name, IPv4 or IPv6 object is created.

If an IPv4 or IPv6 object is used then the type is set to PTR.



833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
# File 'lib/Dnsruby/message.rb', line 833

def initialize(*args)
  if (args.length > 0) 
    @qtype = Types.A
    if (args.length > 1) 
      @qtype = Types.new(args[1])
      @qclass = Classes.IN
      if (args.length > 2) 
        @qclass = Classes.new(args[2])
      end
    end
  else
    raise ArgumentError.new("Must pass at least a name!")
  end
  # If the name looks like an IP address then do an appropriate
  # PTR query.
  @qname=args[0]
  case @qname
  when IPv4::Regex
    @qname = IPv4.create(@qname).to_name
    @qtype = Types.PTR
  when IPv6::Regex
    @qname = IPv6.create(@qname).to_name
    @qtype = Types.PTR
  when Name
  when IPv6
    @qtype = Types.PTR
  when IPv4
    @qtype = Types.PTR
  else
    @qname = Name.create(@qname)
  end
end

Instance Attribute Details

#qclassObject Also known as: zclass

The Question class



825
826
827
# File 'lib/Dnsruby/message.rb', line 825

def qclass
  @qclass
end

#qnameObject Also known as: zname

The Question name



821
822
823
# File 'lib/Dnsruby/message.rb', line 821

def qname
  @qname
end

#qtypeObject Also known as: ztype

The Question type



823
824
825
# File 'lib/Dnsruby/message.rb', line 823

def qtype
  @qtype
end

Instance Method Details

#to_sObject

Returns a string representation of the question record.



893
894
895
# File 'lib/Dnsruby/message.rb', line 893

def to_s
  return "#{@qname}.\t#{@qclass.string}\t#{@qtype.string}";
end