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

ruby-changes:45498

From: nagachika <ko1@a...>
Date: Wed, 8 Feb 2017 02:29:01 +0900 (JST)
Subject: [ruby-changes:45498] nagachika:r57571 (ruby_2_3): merge revision(s) 55781, 55783: [Backport #12604]

nagachika	2017-02-08 02:28:57 +0900 (Wed, 08 Feb 2017)

  New Revision: 57571

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57571

  Log:
    merge revision(s) 55781,55783: [Backport #12604]
    
    * ext/win32/resolv/resolv.c (get_dns_server_list): [Win32] get DNS
      servers only for connected network devices by GetNetworkParams
      API.  [Bug #12604]

  Added directories:
    branches/ruby_2_3/ext/win32/resolv/
  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/ChangeLog
    branches/ruby_2_3/ext/win32/lib/win32/resolv.rb
    branches/ruby_2_3/ext/win32/resolv/resolv.c
    branches/ruby_2_3/version.h
Index: ruby_2_3/ChangeLog
===================================================================
--- ruby_2_3/ChangeLog	(revision 57570)
+++ ruby_2_3/ChangeLog	(revision 57571)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1
+Wed Feb  8 02:20:16 2017  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/win32/resolv/resolv.c (get_dns_server_list): [Win32] get DNS
+	  servers only for connected network devices by GetNetworkParams
+	  API.  [Bug #12604]
+
 Wed Feb  8 02:17:02 2017  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/forwardable.rb (Forwardable._delegator_method): extract
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 57570)
+++ ruby_2_3/version.h	(revision 57571)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.3"
 #define RUBY_RELEASE_DATE "2017-02-08"
-#define RUBY_PATCHLEVEL 243
+#define RUBY_PATCHLEVEL 244
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 2
Index: ruby_2_3/ext/win32/lib/win32/resolv.rb
===================================================================
--- ruby_2_3/ext/win32/lib/win32/resolv.rb	(revision 57570)
+++ ruby_2_3/ext/win32/lib/win32/resolv.rb	(revision 57571)
@@ -33,6 +33,12 @@ module Win32 https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ext/win32/lib/win32/resolv.rb#L33
       end
       [ search, nameserver ]
     end
+end
+
+begin
+  require 'win32/resolv.so'
+rescue LoadError
+end
 
 module Kernel32
   extend Importer
@@ -42,6 +48,7 @@ getv = Kernel32.extern "int GetVersionEx https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ext/win32/lib/win32/resolv.rb#L48
 info = [ 148, 0, 0, 0, 0 ].pack('V5') + "\0" * 128
 getv.call(info)
 if info.unpack('V5')[4] == 2  # VER_PLATFORM_WIN32_NT
+module Win32
 #====================================================================
 # Windows NT
 #====================================================================
@@ -58,7 +65,7 @@ if info.unpack('V5')[4] == 2  # VER_PLAT https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ext/win32/lib/win32/resolv.rb#L65
 
       def get_info
         search = nil
-        nameserver = []
+        nameserver = get_dns_server_list
         Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT) do |reg|
           begin
             slist = reg.read_s('SearchList')
@@ -85,20 +92,15 @@ if info.unpack('V5')[4] == 2  # VER_PLAT https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ext/win32/lib/win32/resolv.rb#L92
           reg.open('Interfaces') do |h|
             h.each_key do |iface,|
               h.open(iface) do |regif|
-                begin
-                  [ 'NameServer', 'DhcpNameServer' ].each do |key|
-                    begin
-                      ns = regif.read_s(key)
-                    rescue
-                    else
-                      unless ns.empty?
-                        nameserver.concat(ns.split(/[,\s]\s*/))
-                        break
-                      end
-                    end
+                next unless ns = %w[NameServer DhcpNameServer].find do |key|
+                  begin
+                    ns = regif.read_s(key)
+                  rescue Registry::Error
+                  else
+                    break ns.split(/[,\s]\s*/) unless ns.empty?
                   end
-                rescue Registry::Error
                 end
+                next if (nameserver & ns).empty?
 
                 if add_search
                   begin
Index: ruby_2_3/ext/win32/resolv/resolv.c
===================================================================
--- ruby_2_3/ext/win32/resolv/resolv.c	(revision 0)
+++ ruby_2_3/ext/win32/resolv/resolv.c	(revision 57571)
@@ -0,0 +1,71 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ext/win32/resolv/resolv.c#L1
+#include <ruby.h>
+#include <ruby/encoding.h>
+#include <iphlpapi.h>
+
+static VALUE
+w32error_init(VALUE self, VALUE code)
+{
+    VALUE str = rb_str_new_cstr(rb_w32_strerror(NUM2INT(code)));
+    rb_ivar_set(self, rb_intern("@code"), code);
+    return rb_call_super(1, &str);
+}
+
+static VALUE
+w32error_make_error(DWORD e)
+{
+    VALUE code = ULONG2NUM(e);
+    return rb_class_new_instance(1, &code, rb_path2class("Win32::Error"));
+}
+
+static void
+w32error_raise(DWORD e)
+{
+    rb_exc_raise(w32error_make_error(e));
+}
+
+static VALUE
+get_dns_server_list(VALUE self)
+{
+    FIXED_INFO *fixedinfo = NULL;
+    ULONG buflen = 0;
+    DWORD ret;
+    VALUE buf, nameservers = Qnil;
+
+    ret = GetNetworkParams(NULL, &buflen);
+    if (ret != NO_ERROR && ret != ERROR_BUFFER_OVERFLOW) {
+	w32error_raise(ret);
+    }
+    fixedinfo = ALLOCV(buf, buflen);
+    ret = GetNetworkParams(fixedinfo, &buflen);
+    if (ret == NO_ERROR) {
+	const IP_ADDR_STRING *ipaddr = &fixedinfo->DnsServerList;
+	nameservers = rb_ary_new();
+	do {
+	    const char *s = ipaddr->IpAddress.String;
+	    if (!*s) continue;
+	    if (strcmp(s, "0.0.0.0") == 0) continue;
+	    rb_ary_push(nameservers, rb_str_new_cstr(s));
+	} while ((ipaddr = ipaddr->Next) != NULL);
+    }
+    ALLOCV_END(buf);
+    if (ret != NO_ERROR) w32error_raise(ret);
+
+    return nameservers;
+}
+
+void
+InitVM_resolv(void)
+{
+    VALUE mWin32 = rb_define_module("Win32");
+    VALUE resolv = rb_define_module_under(mWin32, "Resolv");
+    VALUE singl = rb_singleton_class(resolv);
+    VALUE eclass = rb_define_class_under(mWin32, "Error", rb_eStandardError);
+    rb_define_method(eclass, "initialize", w32error_init, 1);
+    rb_define_private_method(singl, "get_dns_server_list", get_dns_server_list, 0);
+}
+
+void
+Init_resolv(void)
+{
+    InitVM(resolv);
+}

Property changes on: ruby_2_3/ext/win32/resolv/resolv.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ruby_2_3/ext/win32/resolv/extconf.rb
===================================================================
--- ruby_2_3/ext/win32/resolv/extconf.rb	(revision 0)
+++ ruby_2_3/ext/win32/resolv/extconf.rb	(revision 57571)
@@ -0,0 +1 @@
+create_makefile('win32/resolv')

Property changes on: ruby_2_3/ext/win32/resolv/extconf.rb
___________________________________________________________________
Added: svn:eol-style
   + LF


Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r55781,55783


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

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