Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7006496

Use modern Windows API to retrieve OS DNS servers

XMLWordPrintable

    • b08
    • x86
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.6.0_22"
      Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
      Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7600]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Notebook with a wired and a wireless network card, both configured using DHCP. The wireless network card is disabled using its hardware switch, thus only the wired network is active.
      Relevant output of ipconfig:
      Wireless LAN adapter Wireless Network Connection:

         Media State . . . . . . . . . . . : Media disconnected
         Connection-specific DNS Suffix . :
         Description . . . . . . . . . . . : Intel(R) WiFi Link 5100 AGN
         Physical Address. . . . . . . . . : 00-xx-xx-xx-xx-48
         DHCP Enabled. . . . . . . . . . . : Yes
         Autoconfiguration Enabled . . . . : Yes

      Ethernet adapter Local Area Connection:

         Connection-specific DNS Suffix . : mydomain.ch
         Description . . . . . . . . . . . : Intel(R) 82567LM Gigabit Network Connection
         Physical Address. . . . . . . . . : 00-xx-xx-xx-xx-20
         DHCP Enabled. . . . . . . . . . . : Yes
         Autoconfiguration Enabled . . . . : Yes
         Link-local IPv6 Address . . . . . : fe80::f88d:bxx8:8xx2:9xx7%11(Preferred)
         IPv4 Address. . . . . . . . . . . : 10.212.136.24(Preferred)
         Subnet Mask . . . . . . . . . . . : 255.255.255.0
         Lease Obtained. . . . . . . . . . : Montag, 13. Dezember 2010 09:26:55
         Lease Expires . . . . . . . . . . : Montag, 13. Dezember 2010 23:16:57
         Default Gateway . . . . . . . . . : 10.212.136.1
         DHCP Server . . . . . . . . . . . : 10.51.2.32
         DHCPv6 IAID . . . . . . . . . . . : 234890596
         DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-12-xx-xx-xx-xx-xx-xx-xx-xx-20
         DNS Servers . . . . . . . . . . . : 10.51.2.32
                                             10.51.2.33
         NetBIOS over Tcpip. . . . . . . . : Enabled

      A DESCRIPTION OF THE PROBLEM :
      The call to new sun.net.dns.ResolverConfigurationImpl().nameservers(), which is used by various libraries, returns and additional nameserver. Specifically it returns the value last assigned by DHCP to the currently disabled wireless adapter (read from the registry value HKLM\SYSTEM\CurrentControlSet\services\TcpIp\Parameters\DhcpNameServer).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - Take a computer using two network cards
      - Get both connected and assigned an IP Address and DNS servers via DHCP (the DNS Servers of the disconnected card MUST NOT be reachable via the address of the still connected card)
      - Disconnect one of the two connections

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      10.51.2.32
      10.51.2.33

      (as per the output of IPConfig)
      ACTUAL -
      192.168.61.1
      10.51.2.32
      10.51.2.33


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class DNS {
      public static void main(String[] args) {
      for(Object s : sun.net.dns.ResolverConfiguration.open().nameservers()){
      System.out.println(s);
      }
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None. But resolve in JVM by implementing the lookup using the IPHlpApi and method GetAdaptersAddresses, checking its results for OperStatus==IfOperStatusUp and the field FirstDnsServerAddress (see http://msdn.microsoft.com/en-us/library/aa365915%28VS.85%29.aspx).

            aefimov Aleksej Efimov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: