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.



1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
# File 'lib/Dnsruby/message.rb', line 1099

def initialize(*args)
  @qtype = Types.A
  @qclass = Classes.IN
  if (args.length > 0)
    if (args.length > 1)
      @qtype = Types.new(args[1])
      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



1091
1092
1093
# File 'lib/Dnsruby/message.rb', line 1091

def qclass
  @qclass
end

#qnameObject Also known as: zname

The Question name



1087
1088
1089
# File 'lib/Dnsruby/message.rb', line 1087

def qname
  @qname
end

#qtypeObject Also known as: ztype, type

The Question type



1089
1090
1091
# File 'lib/Dnsruby/message.rb', line 1089

def qtype
  @qtype
end

Instance Method Details

#to_sObject

Returns a string representation of the question record.



1159
1160
1161
# File 'lib/Dnsruby/message.rb', line 1159

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