jdk/test/java/net/Inet6Address/B6206527.java
changeset 44671 d1d011d4654d
parent 5506 202f599c92aa
child 45186 387a39577f09
--- a/jdk/test/java/net/Inet6Address/B6206527.java	Fri Apr 14 00:05:54 2017 -0700
+++ b/jdk/test/java/net/Inet6Address/B6206527.java	Fri Apr 14 10:47:08 2017 +0100
@@ -25,10 +25,14 @@
  * @test 1.1 05/01/05
  * @bug 6206527
  * @summary "cannot assign address" when binding ServerSocket on Suse 9
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.NetworkConfiguration
+ * @run main B6206527
  */
 
 import java.net.*;
 import java.util.*;
+import jdk.testlibrary.NetworkConfiguration;
 
 public class B6206527 {
 
@@ -53,21 +57,12 @@
         ss.bind(new InetSocketAddress(addr, 0));
     }
 
-    public static Inet6Address getLocalAddr () throws Exception {
-        Enumeration e = NetworkInterface.getNetworkInterfaces();
-        while (e.hasMoreElements()) {
-            NetworkInterface ifc = (NetworkInterface) e.nextElement();
-            Enumeration addrs = ifc.getInetAddresses();
-            while (addrs.hasMoreElements()) {
-                InetAddress a = (InetAddress)addrs.nextElement();
-                if (a instanceof Inet6Address) {
-                    Inet6Address ia6 = (Inet6Address) a;
-                    if (ia6.isLinkLocalAddress()) {
-                        return ia6;
-                    }
-                }
-            }
-        }
-        return null;
+    public static Inet6Address getLocalAddr() throws Exception {
+        Optional<Inet6Address> oaddr = NetworkConfiguration.probe()
+                .ip6Addresses()
+                .filter(a -> a.isLinkLocalAddress())
+                .findFirst();
+
+        return oaddr.orElseGet(() -> null);
     }
 }