--- old/test/java/net/Inet6Address/B6206527.java 2017-04-13 16:57:32.000000000 +0100 +++ new/test/java/net/Inet6Address/B6206527.java 2017-04-13 16:57:32.000000000 +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 oaddr = NetworkConfiguration.probe() + .ip6Addresses() + .filter(a -> a.isLinkLocalAddress()) + .findFirst(); + + return oaddr.orElseGet(() -> null); } }