class Dnsruby::Question

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

RFC 1035 Section 4.1.2

Attributes

qclass[R]

The Question class

qname[R]

The Question name

qtype[R]

The Question type

type[R]

The Question type

zclass[R]

The Question class

zname[R]

The Question name

ztype[R]

The Question type

Public Class Methods

new(*args) click to toggle source

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.

# File lib/Dnsruby/message.rb, line 1124
def initialize(*args)
  @qtype = Types::A
  @qclass = Classes::IN
  type_given = false
  if (args.length > 0)
    if (args.length > 1)
      @qtype = Types.new(args[1])
      type_given = true
      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, unless the user specified the qtype
  @qname=args[0]
  if (!type_given)
    case @qname.to_s
    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
  else
    case @qtype
    when Types.PTR
      case @qname.to_s
      when IPv4::Regex
        @qname = IPv4.create(@qname).to_name
      when IPv6::Regex
        @qname = IPv6.create(@qname).to_name
      when IPv6
      when IPv4
      else
        @qname = Name.create(@qname)
      end
    else
      @qname = Name.create(@qname)
    end
  end
end

Public Instance Methods

qclass=(qclass) click to toggle source
# File lib/Dnsruby/message.rb, line 1181
def qclass=(qclass)
  @qclass = Classes.new(qclass)
end
qname=(qname) click to toggle source
# File lib/Dnsruby/message.rb, line 1185
def qname=(qname)
  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
qtype=(qtype) click to toggle source
# File lib/Dnsruby/message.rb, line 1177
def qtype=(qtype)
  @qtype = Types.new(qtype)
end
to_s() click to toggle source

Returns a string representation of the question record.

# File lib/Dnsruby/message.rb, line 1204
def to_s
  return "#{@qname}.\t#{@qclass.string}\t#{@qtype.string}";
end