[ruby/resolv] Support a :use_ipv6 option to Resolv#initialize

When set, supports returning IPv6 results even if there is no
public IPv6 address for the system.

Implements Ruby Feature #14922

https://github.com/ruby/resolv/commit/09d141de38
This commit is contained in:
Jeremy Evans 2019-08-26 20:30:59 -07:00
Родитель 1b7376423d
Коммит 87c3deacf4
1 изменённых файлов: 15 добавлений и 2 удалений

Просмотреть файл

@ -84,8 +84,8 @@ class Resolv
##
# Creates a new Resolv using +resolvers+.
def initialize(resolvers=[Hosts.new, DNS.new])
@resolvers = resolvers
def initialize(resolvers=nil, use_ipv6: nil)
@resolvers = resolvers || [Hosts.new, DNS.new(DNS::Config.default_config_hash.merge(use_ipv6: use_ipv6))]
end
##
@ -410,6 +410,11 @@ class Resolv
end
def use_ipv6? # :nodoc:
use_ipv6 = @config.use_ipv6?
unless use_ipv6.nil?
return use_ipv6
end
begin
list = Socket.ip_address_list
rescue NotImplementedError
@ -1008,6 +1013,7 @@ class Resolv
@mutex.synchronize {
unless @initialized
@nameserver_port = []
@use_ipv6 = nil
@search = nil
@ndots = 1
case @config_info
@ -1032,6 +1038,9 @@ class Resolv
if config_hash.include? :nameserver_port
@nameserver_port = config_hash[:nameserver_port].map {|ns, port| [ns, (port || Port)] }
end
if config_hash.include? :use_ipv6
@use_ipv6 = config_hash[:use_ipv6]
end
@search = config_hash[:search] if config_hash.include? :search
@ndots = config_hash[:ndots] if config_hash.include? :ndots
@raise_timeout_errors = config_hash[:raise_timeout_errors]
@ -1088,6 +1097,10 @@ class Resolv
@nameserver_port
end
def use_ipv6?
@use_ipv6
end
def generate_candidates(name)
candidates = nil
name = Name.create(name)