class Dnsruby::Question

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(qname, qtype = :not_provided, qclass = :not_provided) 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/question.rb, line 21
def initialize(qname, qtype = :not_provided, qclass = :not_provided)

  raise ArgumentError.new('qname must not be nil') if qname.nil?

  @qtype  = (qtype  == :not_provided) ? Types::A    : Types.new(qtype)
  @qclass = (qclass == :not_provided) ? Classes::IN : Classes.new(qclass)
  set_qname(qname, qtype == :not_provided)
end

Public Instance Methods

==(other) click to toggle source
# File lib/dnsruby/message/question.rb, line 65
def ==(other)
  other.is_a?(Question) &&
      self.qname  == other.qname  &&
      self.qtype  == other.qtype  &&
      self.qclass == Classes.new(other.qclass)
end
qclass=(qclass) click to toggle source
# File lib/dnsruby/message/question.rb, line 34
def qclass=(qclass)
  @qclass = Classes.new(qclass)
end
qname=(qname) click to toggle source
# File lib/dnsruby/message/question.rb, line 61
def qname=(qname)
  set_qname(qname, true)
end
qtype=(qtype) click to toggle source
# File lib/dnsruby/message/question.rb, line 30
def qtype=(qtype)
  @qtype = Types.new(qtype)
end
set_qname(qname, write_PTR_to_qtype_if_ip = true) click to toggle source
# File lib/dnsruby/message/question.rb, line 38
def set_qname(qname, write_PTR_to_qtype_if_ip = true)
  is_ipv4_addr_string = qname.is_a?(String) && IPv4::Regex.match(qname)
  is_ipv6_addr_string = qname.is_a?(String) && IPv6::Regex.match(qname)
  is_ip_addr_string = is_ipv4_addr_string || is_ipv6_addr_string

  is_ip_addr = [IPv4, IPv6].any? { |klass| qname.is_a?(klass) }

  if is_ipv4_addr_string
    @qname = IPv4.create(qname).to_name
  elsif is_ipv6_addr_string
    @qname = IPv6.create(qname).to_name
  else
    @qname = Name.create(qname)
  end

  #  If the name looks like an IP address then do an appropriate
  #  PTR query, unless the user specified the qtype
  if write_PTR_to_qtype_if_ip && (is_ip_addr || is_ip_addr_string)
    @qtype = Types.PTR
  end
  @qname.absolute = true
end
to_s() click to toggle source

Returns a string representation of the question record.

# File lib/dnsruby/message/question.rb, line 73
def to_s
  "#{@qname}.\t#{@qclass.string}\t#{@qtype.string}"
end