< prev index next >

test/java/net/Socket/LinkLocal.java

Print this page

        

@@ -24,13 +24,19 @@
 /*
  * @test
  * @bug 4469866
  * @summary Connecting to a link-local IPv6 address should not
  *          causes a SocketException to be thrown.
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.NetworkConfiguration
+ * @run main LinkLocal
  */
+import jdk.testlibrary.NetworkConfiguration;
+
 import java.net.*;
-import java.util.Enumeration;
+import java.util.List;
+import java.util.stream.Collectors;
 
 public class LinkLocal {
 
     static int testCount = 0;
     static int failed = 0;

@@ -132,28 +138,19 @@
          * If no argument is provided then enumerate the
          * local addresses and run the test on each link-local
          * IPv6 address.
          */
         if (args.length == 0) {
-            Enumeration nifs = NetworkInterface.getNetworkInterfaces();
-            while (nifs.hasMoreElements()) {
-                NetworkInterface ni = (NetworkInterface)nifs.nextElement();
-                if (!ni.isUp())
-                    continue;
-
-                Enumeration addrs = ni.getInetAddresses();
-                while (addrs.hasMoreElements()) {
-                    InetAddress addr = (InetAddress)addrs.nextElement();
-
-                    if (addr instanceof Inet6Address &&
-                        addr.isLinkLocalAddress()) {
+            List<Inet6Address> addrs = NetworkConfiguration.probe()
+                    .ip6Addresses()
+                    .filter(Inet6Address::isLinkLocalAddress)
+                    .collect(Collectors.toList());
 
+            for (Inet6Address addr : addrs) {
                         TestAddress(addr);
                     }
                 }
-            }
-        }
 
         /*
          * Print results
          */
         if (testCount == 0) {
< prev index next >