Skip to content

Commit

Permalink
Support a :use_ipv6 option to Resolv#initialize
Browse files Browse the repository at this point in the history
When set, supports returning IPv6 results even if there is no
public IPv6 address for the system.

Implements Ruby Feature #14922
  • Loading branch information
jeremyevans committed Nov 24, 2023
1 parent 5e2d487 commit 09d141d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def self.each_name(address, &proc)
##
# 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

##
Expand Down Expand Up @@ -408,6 +408,11 @@ def each_address(name)
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
Expand Down Expand Up @@ -1006,6 +1011,7 @@ def lazy_initialize
@mutex.synchronize {
unless @initialized
@nameserver_port = []
@use_ipv6 = nil
@search = nil
@ndots = 1
case @config_info
Expand All @@ -1030,6 +1036,9 @@ def lazy_initialize
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

Expand Down Expand Up @@ -1085,6 +1094,10 @@ def nameserver_port
@nameserver_port
end

def use_ipv6?
@use_ipv6
end

def generate_candidates(name)
candidates = nil
name = Name.create(name)
Expand Down

0 comments on commit 09d141d

Please sign in to comment.