# HG changeset patch # User xiaofeya # Date 1524032861 25200 # Node ID 33dcb9c42f55e3c791ec3d2be3e81c9584b10e83 # Parent 4bb2a92c13ea7b7e1f19bfb29a9afaa07a2af7c2 8194260: Point-to-point interface should be excluded from java/net/ipv6tests/* Reviewed-by: chegar, vtewari diff -r 4bb2a92c13ea -r 33dcb9c42f55 test/jdk/java/net/ipv6tests/ScopeTests.java --- a/test/jdk/java/net/ipv6tests/ScopeTests.java Wed Apr 18 03:29:24 2018 +0000 +++ b/test/jdk/java/net/ipv6tests/ScopeTests.java Tue Apr 17 23:27:41 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,10 @@ * @test * @bug 4868820 * @summary IPv6 support for Windows XP and 2003 server + * @library /test/lib + * @build jdk.test.lib.NetworkConfiguration + * jdk.test.lib.Platform + * @run main ScopeTests */ import java.net.*; diff -r 4bb2a92c13ea -r 33dcb9c42f55 test/jdk/java/net/ipv6tests/TcpTest.java --- a/test/jdk/java/net/ipv6tests/TcpTest.java Wed Apr 18 03:29:24 2018 +0000 +++ b/test/jdk/java/net/ipv6tests/TcpTest.java Tue Apr 17 23:27:41 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,9 @@ * @bug 4868820 * @key intermittent * @summary IPv6 support for Windows XP and 2003 server + * @library /test/lib + * @build jdk.test.lib.NetworkConfiguration + * jdk.test.lib.Platform * @run main TcpTest -d */ diff -r 4bb2a92c13ea -r 33dcb9c42f55 test/jdk/java/net/ipv6tests/Tests.java --- a/test/jdk/java/net/ipv6tests/Tests.java Wed Apr 18 03:29:24 2018 +0000 +++ b/test/jdk/java/net/ipv6tests/Tests.java Tue Apr 17 23:27:41 2018 -0700 @@ -21,9 +21,19 @@ * questions. */ -import java.net.*; -import java.io.*; -import java.util.*; +import jdk.test.lib.NetworkConfiguration; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.Inet4Address; +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketAddress; public class Tests { @@ -174,126 +184,26 @@ } } - static int numberInterfaces () { - try { - Enumeration ifs = NetworkInterface.getNetworkInterfaces(); - int nifs=0; - while (ifs.hasMoreElements()) { - nifs++; - ifs.nextElement(); - } - return nifs; - } catch (SocketException e) { - return 0; - } - } - - public static Enumeration ipv4Addresses() { - return new AddrEnum (Inet4Address.class); - } - public static Inet4Address getFirstLocalIPv4Address () { - Enumeration e = ipv4Addresses(); - if (!e.hasMoreElements()) { - return null; - } - return (Inet4Address)e.nextElement(); + return getNetworkConfig().ip4Addresses() + .filter(a -> !a.isLoopbackAddress()) + .findFirst() + .orElse(null); } public static Inet6Address getFirstLocalIPv6Address () { - Enumeration e = ipv6Addresses(); - if (!e.hasMoreElements()) { - return null; - } - return (Inet6Address)e.nextElement(); - } - - public static Enumeration ipv6Addresses() { - return new AddrEnum (Inet6Address.class); + return getNetworkConfig().ip6Addresses() + .filter(a -> !a.isLoopbackAddress()) + .findFirst() + .orElse(null); } - /* enumerates the Inet4Addresses or Inet6Addresses on the system */ - - private static class AddrEnum implements Enumeration { - - Enumeration ifs; - NetworkInterface currIf = null; - InetAddress nextAddr=null; - Enumeration addrs=null; - Class filter; - - static final byte[] fe80_loopback = new byte [] { - (byte)0xfe,(byte)0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,1 - }; - - AddrEnum (Class filter) { - this.filter = filter; - try { - ifs = NetworkInterface.getNetworkInterfaces(); - } catch (SocketException e) {} - } - - public boolean hasMoreElements () { - if (nextAddr == null) { - nextAddr = getNext(); - } - return (nextAddr != null); - } - - public Object nextElement () { - if (!hasMoreElements()) { - throw new NoSuchElementException ("no more addresses"); - } - Object next = nextAddr; - nextAddr = null; - return next; - } - - private InetAddress getNext() { - while (true) { - if (currIf == null) { - currIf = getNextIf(); - if (currIf == null) { - return null; - } - addrs = currIf.getInetAddresses(); - } - while (addrs.hasMoreElements()) { - InetAddress addr = (InetAddress) addrs.nextElement(); - if (filter.isInstance (addr) && !addr.isLoopbackAddress() - && !addr.isAnyLocalAddress()) { - if (Arrays.equals (addr.getAddress(), fe80_loopback)) { - continue; - } - return addr; - } - } - currIf = null; - } - } - - private NetworkInterface getNextIf () { - if (ifs != null) { - while (ifs.hasMoreElements()) { - NetworkInterface nic = (NetworkInterface)ifs.nextElement(); - // Skip (Windows)Teredo Tunneling Pseudo-Interface - if (isWindows) { - String dName = nic.getDisplayName(); - if (dName != null && dName.contains("Teredo")) - continue; - } else if (isMacOS && nic.getName().contains("awdl")) { - continue; - } - try { - if (nic.isUp() && !nic.isLoopback()) - return nic; - } catch (SocketException e) { - // ignore - } - } - } - - return null; + private static NetworkConfiguration getNetworkConfig() { + try { + return NetworkConfiguration.probe(); + } catch (IOException e) { + System.out.println("Failed to probe NetworkConfiguration"); + throw new RuntimeException(e); } } diff -r 4bb2a92c13ea -r 33dcb9c42f55 test/jdk/java/net/ipv6tests/UdpTest.java --- a/test/jdk/java/net/ipv6tests/UdpTest.java Wed Apr 18 03:29:24 2018 +0000 +++ b/test/jdk/java/net/ipv6tests/UdpTest.java Tue Apr 17 23:27:41 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,10 +25,19 @@ * @test * @bug 4868820 * @summary IPv6 support for Windows XP and 2003 server + * @library /test/lib + * @build jdk.test.lib.NetworkConfiguration + * jdk.test.lib.Platform + * @run main UdpTest */ -import java.net.*; -import java.io.*; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.Inet4Address; +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.PortUnreachableException; +import java.net.SocketTimeoutException; public class UdpTest extends Tests { static DatagramSocket c3, s1, s2, s3;