lib/rubysl/resolv/resolv.rb in rubysl-resolv-2.1.0 vs lib/rubysl/resolv/resolv.rb in rubysl-resolv-2.1.1

- old
+ new

@@ -1,7 +1,6 @@ require 'socket' -require 'fcntl' require 'timeout' require 'thread' begin require 'securerandom' @@ -157,11 +156,11 @@ class ResolvError < StandardError; end ## # Indicates a timeout resolving a name or address. - class ResolvTimeout < TimeoutError; end + class ResolvTimeout < Timeout::Error; end ## # Resolv::Hosts is a hostname resolver that uses the system hosts file. class Hosts @@ -669,12 +668,12 @@ def request(sender, tout) start = Time.now timelimit = start + tout begin sender.send - rescue Errno::EHOSTUNREACH - # multi-homed IPv6 may generate this + rescue Errno::EHOSTUNREACH, # multi-homed IPv6 may generate this + Errno::ENETUNREACH raise ResolvTimeout end while true before_select = Time.now timeout = timelimit - before_select @@ -1065,10 +1064,14 @@ candidates = [Name.new(name.to_a)] else candidates = [] end candidates.concat(@search.map {|domain| Name.new(name.to_a + domain)}) + fname = Name.create("#{name}.") + if !candidates.include?(fname) + candidates << fname + end end return candidates end InitialTimeout = 5 @@ -1165,24 +1168,26 @@ end class Str # :nodoc: def initialize(string) @string = string - @downcase = string.downcase + # case insensivity of DNS labels doesn't apply non-ASCII characters. [RFC 4343] + # This assumes @string is given in ASCII compatible encoding. + @downcase = string.b.downcase end attr_reader :string, :downcase def to_s return @string end def inspect - return "#<#{self.class} #{self.to_s}>" + return "#<#{self.class} #{self}>" end def ==(other) - return @downcase == other.downcase + return self.class == other.class && @downcase == other.downcase end def eql?(other) return self == other end @@ -1214,16 +1219,24 @@ raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}") end end def initialize(labels, absolute=true) # :nodoc: + labels = labels.map {|label| + case label + when String then Label::Str.new(label) + when Label::Str then label + else + raise ArgumentError, "unexpected label: #{label.inspect}" + end + } @labels = labels @absolute = absolute end def inspect # :nodoc: - "#<#{self.class}: #{self.to_s}#{@absolute ? '.' : ''}>" + "#<#{self.class}: #{self}#{@absolute ? '.' : ''}>" end ## # True if this name is absolute. @@ -1231,11 +1244,12 @@ return @absolute end def ==(other) # :nodoc: return false unless Name === other - return @labels.join == other.to_a.join && @absolute == other.absolute? + return false unless @absolute == other.absolute? + return @labels == other.to_a end alias eql? == # :nodoc: ## @@ -1660,14 +1674,14 @@ def ==(other) # :nodoc: return false unless self.class == other.class s_ivars = self.instance_variables s_ivars.sort! - s_ivars.delete "@ttl" + s_ivars.delete :@ttl o_ivars = other.instance_variables o_ivars.sort! - o_ivars.delete "@ttl" + o_ivars.delete :@ttl return s_ivars == o_ivars && s_ivars.collect {|name| self.instance_variable_get name} == o_ivars.collect {|name| other.instance_variable_get name} end @@ -1676,11 +1690,11 @@ end def hash # :nodoc: h = 0 vars = self.instance_variables - vars.delete "@ttl" + vars.delete :@ttl vars.each {|name| h ^= self.instance_variable_get(name).hash } return h end @@ -2345,11 +2359,11 @@ def to_s # :nodoc: return sprintf("%d.%d.%d.%d", *@address.unpack("CCCC")) end def inspect # :nodoc: - return "#<#{self.class} #{self.to_s}>" + return "#<#{self.class} #{self}>" end ## # Turns this IPv4 address into a Resolv::DNS::Name. @@ -2488,11 +2502,11 @@ end return address end def inspect # :nodoc: - return "#<#{self.class} #{self.to_s}>" + return "#<#{self.class} #{self}>" end ## # Turns this IPv6 address into a Resolv::DNS::Name. #-- @@ -2638,11 +2652,11 @@ s = @scalar.unpack("H2").join.to_s return ((s[0].to_i)*(10**(s[1].to_i-2))).to_s << "m" end def inspect # :nodoc: - return "#<#{self.class} #{self.to_s}>" + return "#<#{self.class} #{self}>" end def ==(other) # :nodoc: return @scalar == other.scalar end @@ -2727,11 +2741,11 @@ end return degs << " " << mins << " " << secs << "." << fracsecs << " " << hemi end def inspect # :nodoc: - return "#<#{self.class} #{self.to_s}>" + return "#<#{self.class} #{self}>" end def ==(other) # :nodoc: return @coordinates == other.coordinates end @@ -2789,10 +2803,10 @@ a = @altitude.unpack("N").join.to_i return ((a.to_f/1e2)-1e5).to_s + "m" end def inspect # :nodoc: - return "#<#{self.class} #{self.to_s}>" + return "#<#{self.class} #{self}>" end def ==(other) # :nodoc: return @altitude == other.altitude end