Created
January 26, 2022 21:43
-
-
Save headius/a78601ac43de2607a4428315a0c4a988 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- lib/resolv.rb 2022-01-26 15:27:26.000000000 -0600 | |
+++ ../jruby/lib/ruby/stdlib/resolv.rb 2021-10-27 14:50:07.000000000 -0500 | |
@@ -29,20 +29,24 @@ | |
# p ress.map { |r| [r.exchange.to_s, r.preference] } | |
# end | |
# | |
# | |
# == Bugs | |
# | |
# * NIS is not supported. | |
# * /etc/nsswitch.conf is not supported. | |
class Resolv | |
+ ## | |
+ # Tests whether we're running on Windows | |
+ | |
+ WINDOWS = /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM || ::RbConfig::CONFIG['host_os'] =~ /mswin/ | |
## | |
# Looks up the first IP address for +name+. | |
def self.getaddress(name) | |
DefaultResolver.getaddress(name) | |
end | |
## | |
# Looks up all IP address for +name+. | |
@@ -159,21 +163,21 @@ | |
## | |
# Indicates a timeout resolving a name or address. | |
class ResolvTimeout < Timeout::Error; end | |
## | |
# Resolv::Hosts is a hostname resolver that uses the system hosts file. | |
class Hosts | |
- if /mswin|mingw|cygwin/ =~ RUBY_PLATFORM and | |
+ if WINDOWS and | |
begin | |
require 'win32/resolv' | |
DefaultFileName = Win32::Resolv.get_hosts_path || IO::NULL | |
rescue LoadError | |
end | |
end | |
DefaultFileName ||= '/etc/hosts' | |
## | |
# Creates a new Resolv::Hosts, using +filename+ for its data source. | |
@@ -756,42 +760,42 @@ | |
sock.do_not_reverse_lookup = true | |
DNS.bind_random_port(sock, bind_host) | |
} | |
} | |
self | |
end | |
def recv_reply(readable_socks) | |
lazy_initialize | |
reply, from = readable_socks[0].recvfrom(UDPSize) | |
- return reply, [from[3],from[1]] | |
+ return reply, [IPAddr.new(from[3]),from[1]] | |
end | |
def sender(msg, data, host, port=Port) | |
host = Addrinfo.ip(host).ip_address | |
lazy_initialize | |
sock = @socks_hash[host.index(':') ? "::" : "0.0.0.0"] | |
return nil if !sock | |
- service = [host, port] | |
- id = DNS.allocate_request_id(host, port) | |
+ service = [IPAddr.new(host), port] | |
+ id = DNS.allocate_request_id(service[0].to_s, port) | |
request = msg.encode | |
request[0,2] = [id].pack('n') | |
return @senders[[service, id]] = | |
Sender.new(request, data, sock, host, port) | |
end | |
def close | |
@mutex.synchronize { | |
if @initialized | |
super | |
@senders.each_key {|service, id| | |
- DNS.free_request_id(service[0], service[1], id) | |
+ DNS.free_request_id(service[0].to_s, service[1], id) | |
} | |
@initialized = false | |
end | |
} | |
end | |
class Sender < Requester::Sender # :nodoc: | |
def initialize(msg, data, sock, host, port) | |
super(msg, data, sock) | |
@host = host | |
@@ -982,21 +986,21 @@ | |
end | |
} | |
} | |
return { :nameserver => nameserver, :search => search, :ndots => ndots } | |
end | |
def Config.default_config_hash(filename="/etc/resolv.conf") | |
if File.exist? filename | |
config_hash = Config.parse_resolv_conf(filename) | |
else | |
- if /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM | |
+ if WINDOWS | |
require 'win32/resolv' | |
search, nameserver = Win32::Resolv.get_resolv_info | |
config_hash = {} | |
config_hash[:nameserver] = nameserver if nameserver | |
config_hash[:search] = [search].flatten if search | |
end | |
end | |
config_hash || {} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment