зеркало из https://github.com/github/ruby.git
* lib/resolv.rb: don't complete domains for absolute FQNs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2185 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
9651a9db92
Коммит
230034b7ab
|
@ -1,3 +1,7 @@
|
||||||
|
Tue Mar 12 17:12:06 2002 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
|
* lib/resolv.rb: don't complete domains for absolute FQNs.
|
||||||
|
|
||||||
Mon Mar 11 23:08:48 2002 Tanaka Akira <akr@m17n.org>
|
Mon Mar 11 23:08:48 2002 Tanaka Akira <akr@m17n.org>
|
||||||
|
|
||||||
* lib/tsort.rb: new file.
|
* lib/tsort.rb: new file.
|
||||||
|
|
|
@ -8,7 +8,7 @@ It is possible to lookup various resources of DNS using DNS module directly.
|
||||||
|
|
||||||
== example
|
== example
|
||||||
Resolv.getaddress("www.ruby-lang.org")
|
Resolv.getaddress("www.ruby-lang.org")
|
||||||
Resolv.getname("210.251.121.214").to_s
|
Resolv.getname("210.251.121.214")
|
||||||
Resolv::DNS.new.getresources("www.ruby-lang.org", Resolv::DNS::Resource::IN::A).collect {|r| r.address}
|
Resolv::DNS.new.getresources("www.ruby-lang.org", Resolv::DNS::Resource::IN::A).collect {|r| r.address}
|
||||||
Resolv::DNS.new.getresources("ruby-lang.org", Resolv::DNS::Resource::IN::MX).collect {|r| [r.exchange.to_s, r.preference]}
|
Resolv::DNS.new.getresources("ruby-lang.org", Resolv::DNS::Resource::IN::MX).collect {|r| [r.exchange.to_s, r.preference]}
|
||||||
|
|
||||||
|
@ -168,8 +168,9 @@ DNS stub resolver.
|
||||||
regular expression for IPv6 address.
|
regular expression for IPv6 address.
|
||||||
|
|
||||||
== Bugs
|
== Bugs
|
||||||
NIS is not supported.
|
* NIS is not supported.
|
||||||
/etc/nsswitch.conf is not supported.
|
* /etc/nsswitch.conf is not supported.
|
||||||
|
* IPv6 is not supported.
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
@ -690,9 +691,9 @@ class Resolv
|
||||||
when 'nameserver'
|
when 'nameserver'
|
||||||
@nameserver += args
|
@nameserver += args
|
||||||
when 'domain'
|
when 'domain'
|
||||||
@search = [args[0]]
|
@search = [Label.split(args[0])]
|
||||||
when 'search'
|
when 'search'
|
||||||
@search = args
|
@search = args.map {|arg| Label.split(arg)}
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -703,9 +704,9 @@ class Resolv
|
||||||
unless @search
|
unless @search
|
||||||
hostname = Socket.gethostname
|
hostname = Socket.gethostname
|
||||||
if /\./ =~ hostname
|
if /\./ =~ hostname
|
||||||
@search = [$']
|
@search = [Label.split($')]
|
||||||
else
|
else
|
||||||
@search = ['']
|
@search = [[]]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@initialized = true
|
@initialized = true
|
||||||
|
@ -724,20 +725,17 @@ class Resolv
|
||||||
|
|
||||||
def generate_candidates(name)
|
def generate_candidates(name)
|
||||||
candidates = nil
|
candidates = nil
|
||||||
name = name.to_s if Name === name
|
name = Name.create(name)
|
||||||
if /\.\z/ =~ name
|
if name.absolute?
|
||||||
candidates = [name]
|
candidates = [name]
|
||||||
elsif @ndots <= name.tr('^.', '').length
|
else
|
||||||
candidates = [name, *@search.collect {|domain| name + '.' + domain}]
|
if @ndots <= name.length - 1
|
||||||
else
|
candidates = [Name.new(name.to_a)]
|
||||||
candidates = [*@search.collect {|domain| name + '.' + domain}]
|
else
|
||||||
end
|
candidates = []
|
||||||
candidates.collect! {|c|
|
end
|
||||||
c = c.dup
|
candidates.concat(@search.map {|domain| Name.new(name.to_a + domain)})
|
||||||
c.gsub!(/\.\.+/, '.')
|
end
|
||||||
c.chomp!('.')
|
|
||||||
c
|
|
||||||
}
|
|
||||||
return candidates
|
return candidates
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -859,26 +857,28 @@ class Resolv
|
||||||
when Name
|
when Name
|
||||||
return arg
|
return arg
|
||||||
when String
|
when String
|
||||||
return Name.new(Label.split(arg))
|
return Name.new(Label.split(arg), /\.\z/ =~ arg ? true : false)
|
||||||
else
|
else
|
||||||
raise ArgumentError.new("cannot interprete as DNS name: #{arg.inspect}")
|
raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(labels)
|
def initialize(labels, absolute=true)
|
||||||
@labels = labels
|
@labels = labels
|
||||||
|
@absolute = absolute
|
||||||
|
end
|
||||||
|
|
||||||
|
def absolute?
|
||||||
|
return @absolute
|
||||||
end
|
end
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
return @labels == other.to_a
|
return @labels == other.to_a && @absolute == other.absolute?
|
||||||
end
|
|
||||||
|
|
||||||
def eql?(other)
|
|
||||||
return self == other
|
|
||||||
end
|
end
|
||||||
|
alias eql? ==
|
||||||
|
|
||||||
def hash
|
def hash
|
||||||
return @labels.hash
|
return @labels.hash ^ @absolute.hash
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_a
|
def to_a
|
||||||
|
@ -1532,8 +1532,8 @@ class Resolv
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_name
|
def to_name
|
||||||
return DNS::Name.new(
|
return DNS::Name.create(
|
||||||
@address.unpack("CCCC").reverse + ['in-addr', 'arpa'])
|
'%d.%d.%d.%d.in-addr.arpa.' % @address.unpack('CCCC').reverse)
|
||||||
end
|
end
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
|
@ -1644,6 +1644,7 @@ class Resolv
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_name
|
def to_name
|
||||||
|
# ip6.arpa should be searched too. [RFC3152]
|
||||||
return DNS::Name.new(
|
return DNS::Name.new(
|
||||||
@address.unpack("H32")[0].split(//).reverse + ['ip6', 'int'])
|
@address.unpack("H32")[0].split(//).reverse + ['ip6', 'int'])
|
||||||
end
|
end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче