[前][次][番号順一覧][スレッド一覧]

ruby-changes:32802

From: akr <ko1@a...>
Date: Sat, 8 Feb 2014 00:03:59 +0900 (JST)
Subject: [ruby-changes:32802] akr:r44880 (trunk): * lib/resolv.rb: Ignore name servers which cause EAFNOSUPPORT on

akr	2014-02-08 00:03:34 +0900 (Sat, 08 Feb 2014)

  New Revision: 44880

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44880

  Log:
    * lib/resolv.rb: Ignore name servers which cause EAFNOSUPPORT on
      socket creation.
      Reported by Bjoern Rennhak.  [ruby-core:60442] [Bug #9477]

  Modified files:
    trunk/ChangeLog
    trunk/lib/resolv.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44879)
+++ ChangeLog	(revision 44880)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Feb  7 23:37:49 2014  Tanaka Akira  <akr@f...>
+
+	* lib/resolv.rb: Ignore name servers which cause EAFNOSUPPORT on
+	  socket creation.
+	  Reported by Bjoern Rennhak.  [ruby-core:60442] [Bug #9477]
+
 Fri Feb  7 21:58:48 2014  Zachary Scott  <e@z...>
 
 	* lib/open-uri.rb: [DOC] use lower case version of core classes, same
Index: lib/resolv.rb
===================================================================
--- lib/resolv.rb	(revision 44879)
+++ lib/resolv.rb	(revision 44880)
@@ -522,8 +522,9 @@ class Resolv https://github.com/ruby/ruby/blob/trunk/lib/resolv.rb#L522
           msg.rd = 1
           msg.add_question(candidate, typeclass)
           unless sender = senders[[candidate, nameserver, port]]
-            sender = senders[[candidate, nameserver, port]] =
-              requester.sender(msg, candidate, nameserver, port)
+            sender = requester.sender(msg, candidate, nameserver, port)
+            next if !sender
+            senders[[candidate, nameserver, port]] = sender
           end
           reply, reply_name = requester.request(sender, tout)
           case reply.rcode
@@ -741,7 +742,11 @@ class Resolv https://github.com/ruby/ruby/blob/trunk/lib/resolv.rb#L742
               af = Socket::AF_INET
             end
             next if @socks_hash[bind_host]
-            sock = UDPSocket.new(af)
+            begin
+              sock = UDPSocket.new(af)
+            rescue Errno::EAFNOSUPPORT
+              next # The kernel doesn't support the address family.
+            end
             sock.do_not_reverse_lookup = true
             sock.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::F_SETFD
             DNS.bind_random_port(sock, bind_host)
@@ -756,11 +761,12 @@ class Resolv https://github.com/ruby/ruby/blob/trunk/lib/resolv.rb#L761
         end
 
         def sender(msg, data, host, port=Port)
+          sock = @socks_hash[host.index(':') ? "::" : "0.0.0.0"]
+          return nil if !sock
           service = [host, port]
           id = DNS.allocate_request_id(host, port)
           request = msg.encode
           request[0,2] = [id].pack('n')
-          sock = @socks_hash[host.index(':') ? "::" : "0.0.0.0"]
           return @senders[[service, id]] =
             Sender.new(request, data, sock, host, port)
         end
@@ -781,6 +787,7 @@ class Resolv https://github.com/ruby/ruby/blob/trunk/lib/resolv.rb#L787
           attr_reader :data
 
           def send
+            raise "@sock is nil." if @sock.nil?
             @sock.send(@msg, 0, @host, @port)
           end
         end
@@ -824,6 +831,7 @@ class Resolv https://github.com/ruby/ruby/blob/trunk/lib/resolv.rb#L831
 
         class Sender < Requester::Sender # :nodoc:
           def send
+            raise "@sock is nil." if @sock.nil?
             @sock.send(@msg, 0)
           end
           attr_reader :data

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]