mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 02:54:35 +02:00
8220673: Add test library support for determining platform IP support
Reviewed-by: dfuchs, chegar
This commit is contained in:
parent
c709e1cbf0
commit
0bb6328356
57 changed files with 461 additions and 75 deletions
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
* @library /test/lib
|
||||||
* @modules java.management java.base/java.io:+open java.base/java.net:+open
|
* @modules java.management java.base/java.io:+open java.base/java.net:+open
|
||||||
* @run main/othervm UnreferencedDatagramSockets
|
* @run main/othervm UnreferencedDatagramSockets
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true UnreferencedDatagramSockets
|
* @run main/othervm -Djava.net.preferIPv4Stack=true UnreferencedDatagramSockets
|
||||||
|
@ -51,6 +52,8 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import com.sun.management.UnixOperatingSystemMXBean;
|
import com.sun.management.UnixOperatingSystemMXBean;
|
||||||
|
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class UnreferencedDatagramSockets {
|
public class UnreferencedDatagramSockets {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,6 +106,7 @@ public class UnreferencedDatagramSockets {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
// Create and close a DatagramSocket to warm up the FD count for side effects.
|
// Create and close a DatagramSocket to warm up the FD count for side effects.
|
||||||
try (DatagramSocket s = new DatagramSocket(0)) {
|
try (DatagramSocket s = new DatagramSocket(0)) {
|
||||||
|
|
40
test/jdk/java/net/IPSupport/MinimumPermissions.java
Normal file
40
test/jdk/java/net/IPSupport/MinimumPermissions.java
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019, 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 8220673
|
||||||
|
* @library /test/lib
|
||||||
|
* @build jdk.test.lib.net.IPSupport
|
||||||
|
* @summary Ensure IPSupport works under a security manager.
|
||||||
|
* @run main/othervm/policy=MinimumPermissions.policy MinimumPermissions
|
||||||
|
*/
|
||||||
|
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
|
public class MinimumPermissions {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
28
test/jdk/java/net/IPSupport/MinimumPermissions.policy
Normal file
28
test/jdk/java/net/IPSupport/MinimumPermissions.policy
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
//
|
||||||
|
// Copyright (c) 2019, 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
|
||||||
|
// under the terms of the GNU General Public License version 2 only, as
|
||||||
|
// published by the Free Software Foundation.
|
||||||
|
//
|
||||||
|
// This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
// version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
// accompanied this code).
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License version
|
||||||
|
// 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
//
|
||||||
|
// Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
// or visit www.oracle.com if you need additional information or have any
|
||||||
|
// questions.
|
||||||
|
//
|
||||||
|
|
||||||
|
grant codeBase "file:${test.classes}/../../../../test/lib/-" {
|
||||||
|
permission java.net.SocketPermission "localhost:0", "listen,resolve";
|
||||||
|
permission java.util.PropertyPermission "java.net.preferIPv4Stack", "read";
|
||||||
|
};
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 7163874 8133015
|
* @bug 7163874 8133015
|
||||||
|
* @library /test/lib
|
||||||
* @summary InetAddress.isReachable is returning false
|
* @summary InetAddress.isReachable is returning false
|
||||||
* for InetAdress 0.0.0.0 and ::0
|
* for InetAdress 0.0.0.0 and ::0
|
||||||
* @run main PingThis
|
* @run main PingThis
|
||||||
|
@ -40,41 +41,26 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class PingThis {
|
public class PingThis {
|
||||||
private static boolean hasIPv6() throws Exception {
|
|
||||||
List<NetworkInterface> nics = Collections.list(NetworkInterface
|
|
||||||
.getNetworkInterfaces());
|
|
||||||
for (NetworkInterface nic : nics) {
|
|
||||||
List<InetAddress> addrs = Collections.list(nic.getInetAddresses());
|
|
||||||
for (InetAddress addr : addrs) {
|
|
||||||
if (addr instanceof Inet6Address)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
if (System.getProperty("os.name").startsWith("Windows")) {
|
if (System.getProperty("os.name").startsWith("Windows")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
boolean preferIPv4Stack = "true".equals(System
|
|
||||||
.getProperty("java.net.preferIPv4Stack"));
|
|
||||||
List<String> addrs = new ArrayList<String>();
|
List<String> addrs = new ArrayList<String>();
|
||||||
InetAddress inetAddress = null;
|
|
||||||
|
|
||||||
addrs.add("0.0.0.0");
|
if (IPSupport.hasIPv4()) {
|
||||||
if (!preferIPv4Stack) {
|
addrs.add("0.0.0.0");
|
||||||
if (hasIPv6()) {
|
}
|
||||||
addrs.add("::0");
|
if (IPSupport.hasIPv6()) {
|
||||||
}
|
addrs.add("::0");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String addr : addrs) {
|
for (String addr : addrs) {
|
||||||
inetAddress = InetAddress.getByName(addr);
|
InetAddress inetAddress = InetAddress.getByName(addr);
|
||||||
System.out.println("The target ip is "
|
System.out.println("The target ip is "
|
||||||
+ inetAddress.getHostAddress());
|
+ inetAddress.getHostAddress());
|
||||||
boolean isReachable = inetAddress.isReachable(3000);
|
boolean isReachable = inetAddress.isReachable(3000);
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 8016521
|
* @bug 8016521
|
||||||
|
* @library /test/lib
|
||||||
* @summary InetAddress should not always re-order addresses returned from name
|
* @summary InetAddress should not always re-order addresses returned from name
|
||||||
* service
|
* service
|
||||||
* @run main/othervm -Djava.net.preferIPv6Addresses=false PreferIPv6AddressesTest
|
* @run main/othervm -Djava.net.preferIPv6Addresses=false PreferIPv6AddressesTest
|
||||||
|
@ -38,6 +39,7 @@ import java.nio.channels.DatagramChannel;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
import static java.lang.System.out;
|
import static java.lang.System.out;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class PreferIPv6AddressesTest {
|
public class PreferIPv6AddressesTest {
|
||||||
|
|
||||||
|
@ -50,7 +52,6 @@ public class PreferIPv6AddressesTest {
|
||||||
System.getProperty("java.net.preferIPv6Addresses", "false");
|
System.getProperty("java.net.preferIPv6Addresses", "false");
|
||||||
|
|
||||||
public static void main(String args[]) throws IOException {
|
public static void main(String args[]) throws IOException {
|
||||||
|
|
||||||
InetAddress addrs[];
|
InetAddress addrs[];
|
||||||
try {
|
try {
|
||||||
addrs = InetAddress.getAllByName(HOST_NAME);
|
addrs = InetAddress.getAllByName(HOST_NAME);
|
||||||
|
@ -66,7 +67,7 @@ public class PreferIPv6AddressesTest {
|
||||||
.filter(x -> addrs[x] instanceof Inet6Address)
|
.filter(x -> addrs[x] instanceof Inet6Address)
|
||||||
.findFirst().orElse(-1);
|
.findFirst().orElse(-1);
|
||||||
|
|
||||||
out.println("IPv6 supported: " + IPv6Supported());
|
out.println("IPv6 supported: " + IPSupport.hasIPv6());
|
||||||
out.println("Addresses: " + Arrays.asList(addrs));
|
out.println("Addresses: " + Arrays.asList(addrs));
|
||||||
|
|
||||||
if (preferIPV6Address.equalsIgnoreCase("true") && firstIPv6Address != -1) {
|
if (preferIPV6Address.equalsIgnoreCase("true") && firstIPv6Address != -1) {
|
||||||
|
@ -81,10 +82,10 @@ public class PreferIPv6AddressesTest {
|
||||||
assertAllv6Addresses(addrs, off, addrs.length);
|
assertAllv6Addresses(addrs, off, addrs.length);
|
||||||
assertLoopbackAddress(Inet4Address.class);
|
assertLoopbackAddress(Inet4Address.class);
|
||||||
assertAnyLocalAddress(Inet4Address.class);
|
assertAnyLocalAddress(Inet4Address.class);
|
||||||
} else if (preferIPV6Address.equalsIgnoreCase("system") && IPv6Supported()) {
|
} else if (preferIPV6Address.equalsIgnoreCase("system") && IPSupport.hasIPv6()) {
|
||||||
assertLoopbackAddress(Inet6Address.class);
|
assertLoopbackAddress(Inet6Address.class);
|
||||||
assertAnyLocalAddress(Inet6Address.class);
|
assertAnyLocalAddress(Inet6Address.class);
|
||||||
} else if (preferIPV6Address.equalsIgnoreCase("system") && !IPv6Supported()) {
|
} else if (preferIPV6Address.equalsIgnoreCase("system") && !IPSupport.hasIPv6()) {
|
||||||
assertLoopbackAddress(Inet4Address.class);
|
assertLoopbackAddress(Inet4Address.class);
|
||||||
assertAnyLocalAddress(Inet4Address.class);
|
assertAnyLocalAddress(Inet4Address.class);
|
||||||
}
|
}
|
||||||
|
@ -120,13 +121,4 @@ public class PreferIPv6AddressesTest {
|
||||||
throw new RuntimeException("Expected " + expectedType
|
throw new RuntimeException("Expected " + expectedType
|
||||||
+ ", got " + anyAddr.getClass());
|
+ ", got " + anyAddr.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean IPv6Supported() throws IOException {
|
|
||||||
try {
|
|
||||||
DatagramChannel.open(StandardProtocolFamily.INET6);
|
|
||||||
return true;
|
|
||||||
} catch (UnsupportedOperationException x) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 4531817 8026245
|
* @bug 4531817 8026245
|
||||||
|
* @library /test/lib
|
||||||
* @summary Inet[46]Address.localHost need doPrivileged
|
* @summary Inet[46]Address.localHost need doPrivileged
|
||||||
* @run main/othervm GetLocalHostWithSM
|
* @run main/othervm GetLocalHostWithSM
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true GetLocalHostWithSM
|
* @run main/othervm -Djava.net.preferIPv4Stack=true GetLocalHostWithSM
|
||||||
|
@ -38,9 +39,12 @@ import java.security.Principal;
|
||||||
import java.security.PrivilegedExceptionAction;
|
import java.security.PrivilegedExceptionAction;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class GetLocalHostWithSM {
|
public class GetLocalHostWithSM {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
// try setting the local hostname
|
// try setting the local hostname
|
||||||
InetAddress localHost = InetAddress.getLocalHost();
|
InetAddress localHost = InetAddress.getLocalHost();
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.net.MulticastSocket;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
|
|
||||||
import jdk.test.lib.NetworkConfiguration;
|
import jdk.test.lib.NetworkConfiguration;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
@ -42,6 +43,7 @@ import jdk.test.lib.NetworkConfiguration;
|
||||||
public class JoinLeave {
|
public class JoinLeave {
|
||||||
|
|
||||||
public static void main(String args[]) throws IOException {
|
public static void main(String args[]) throws IOException {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
InetAddress ip4Group = InetAddress.getByName("224.80.80.80");
|
InetAddress ip4Group = InetAddress.getByName("224.80.80.80");
|
||||||
InetAddress ip6Group = InetAddress.getByName("ff02::a");
|
InetAddress ip6Group = InetAddress.getByName("ff02::a");
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,12 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4742177
|
* @bug 4742177
|
||||||
|
* @library /test/lib
|
||||||
* @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
|
* @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
|
||||||
*/
|
*/
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class NoLoopbackPackets {
|
public class NoLoopbackPackets {
|
||||||
private static String osname;
|
private static String osname;
|
||||||
|
@ -38,34 +40,12 @@ public class NoLoopbackPackets {
|
||||||
return osname.contains("Windows");
|
return osname.contains("Windows");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasIPv6() throws Exception {
|
|
||||||
List<NetworkInterface> nics = Collections.list(
|
|
||||||
NetworkInterface.getNetworkInterfaces());
|
|
||||||
for (NetworkInterface nic : nics) {
|
|
||||||
if (!nic.isLoopback()) {
|
|
||||||
List<InetAddress> addrs = Collections.list(nic.getInetAddresses());
|
|
||||||
for (InetAddress addr : addrs) {
|
|
||||||
if (addr instanceof Inet6Address) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
if (isWindows()) {
|
if (isWindows()) {
|
||||||
System.out.println("The test only run on non-Windows OS. Bye.");
|
System.out.println("The test only run on non-Windows OS. Bye.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasIPv6()) {
|
|
||||||
System.out.println("No IPv6 available. Bye.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MulticastSocket msock = null;
|
MulticastSocket msock = null;
|
||||||
List<SocketAddress> failedGroups = new ArrayList<SocketAddress>();
|
List<SocketAddress> failedGroups = new ArrayList<SocketAddress>();
|
||||||
Sender sender = null;
|
Sender sender = null;
|
||||||
|
@ -77,9 +57,16 @@ public class NoLoopbackPackets {
|
||||||
// 224.1.1.1, ::ffff:224.1.1.2, and ff02::1:1
|
// 224.1.1.1, ::ffff:224.1.1.2, and ff02::1:1
|
||||||
//
|
//
|
||||||
List<SocketAddress> groups = new ArrayList<SocketAddress>();
|
List<SocketAddress> groups = new ArrayList<SocketAddress>();
|
||||||
groups.add(new InetSocketAddress(InetAddress.getByName("224.1.1.1"), port));
|
if (IPSupport.hasIPv4()) {
|
||||||
groups.add(new InetSocketAddress(InetAddress.getByName("::ffff:224.1.1.2"), port));
|
groups.add(new InetSocketAddress(InetAddress.getByName("224.1.1.1"), port));
|
||||||
groups.add(new InetSocketAddress(InetAddress.getByName("ff02::1:1"), port));
|
}
|
||||||
|
if (IPSupport.hasIPv6()) {
|
||||||
|
groups.add(new InetSocketAddress(InetAddress.getByName("::ffff:224.1.1.2"), port));
|
||||||
|
groups.add(new InetSocketAddress(InetAddress.getByName("ff02::1:1"), port));
|
||||||
|
}
|
||||||
|
if (groups.isEmpty()) {
|
||||||
|
System.err.println("Nothing to test: there are no network interfaces");
|
||||||
|
}
|
||||||
|
|
||||||
sender = new Sender(groups);
|
sender = new Sender(groups);
|
||||||
new Thread(sender).start();
|
new Thread(sender).start();
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 8014499
|
* @bug 8014499
|
||||||
|
* @library /test/lib
|
||||||
* @summary Test for interference when two sockets are bound to the same
|
* @summary Test for interference when two sockets are bound to the same
|
||||||
* port but joined to different multicast groups
|
* port but joined to different multicast groups
|
||||||
* @run main Promiscuous
|
* @run main Promiscuous
|
||||||
|
@ -32,6 +33,7 @@
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import static java.lang.System.out;
|
import static java.lang.System.out;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class Promiscuous {
|
public class Promiscuous {
|
||||||
|
|
||||||
|
@ -113,6 +115,8 @@ public class Promiscuous {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws IOException {
|
public static void main(String args[]) throws IOException {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
String os = System.getProperty("os.name");
|
String os = System.getProperty("os.name");
|
||||||
|
|
||||||
// Requires IP_MULTICAST_ALL on Linux (new since 2.6.31) so skip
|
// Requires IP_MULTICAST_ALL on Linux (new since 2.6.31) so skip
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.net.MulticastSocket;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
|
|
||||||
import jdk.test.lib.NetworkConfiguration;
|
import jdk.test.lib.NetworkConfiguration;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
@ -41,6 +42,7 @@ import jdk.test.lib.NetworkConfiguration;
|
||||||
public class SetGetNetworkInterfaceTest {
|
public class SetGetNetworkInterfaceTest {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
NetworkConfiguration nc = NetworkConfiguration.probe();
|
NetworkConfiguration nc = NetworkConfiguration.probe();
|
||||||
try (MulticastSocket ms = new MulticastSocket()) {
|
try (MulticastSocket ms = new MulticastSocket()) {
|
||||||
nc.multicastInterfaces(true).forEach(nif -> setGetNetworkInterface(ms, nif));
|
nc.multicastInterfaces(true).forEach(nif -> setGetNetworkInterface(ms, nif));
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.net.MulticastSocket;
|
||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
|
|
||||||
import jdk.test.lib.NetworkConfiguration;
|
import jdk.test.lib.NetworkConfiguration;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
@ -158,6 +159,8 @@ public class Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
Test t = new Test();
|
Test t = new Test();
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
* @library /test/lib
|
||||||
* @modules java.management java.base/java.io:+open java.base/java.net:+open
|
* @modules java.management java.base/java.io:+open java.base/java.net:+open
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true UnreferencedMulticastSockets
|
* @run main/othervm -Djava.net.preferIPv4Stack=true UnreferencedMulticastSockets
|
||||||
* @run main/othervm UnreferencedMulticastSockets
|
* @run main/othervm UnreferencedMulticastSockets
|
||||||
|
@ -50,6 +51,8 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
import com.sun.management.UnixOperatingSystemMXBean;
|
import com.sun.management.UnixOperatingSystemMXBean;
|
||||||
|
|
||||||
public class UnreferencedMulticastSockets {
|
public class UnreferencedMulticastSockets {
|
||||||
|
@ -104,6 +107,7 @@ public class UnreferencedMulticastSockets {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
// Create and close a MulticastSocket to warm up the FD count for side effects.
|
// Create and close a MulticastSocket to warm up the FD count for side effects.
|
||||||
try (MulticastSocket s = new MulticastSocket(0)) {
|
try (MulticastSocket s = new MulticastSocket(0)) {
|
||||||
|
|
|
@ -24,12 +24,13 @@
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 8081678 8131155
|
* @bug 8081678 8131155
|
||||||
* @summary Tests for stream returning methods
|
* @summary Tests for stream returning methods
|
||||||
* @library /lib/testlibrary/bootlib
|
* @library /lib/testlibrary/bootlib /test/lib
|
||||||
* @build java.base/java.util.stream.OpTestCase
|
* @build java.base/java.util.stream.OpTestCase
|
||||||
* @run testng/othervm NetworkInterfaceStreamTest
|
* @run testng/othervm NetworkInterfaceStreamTest
|
||||||
* @run testng/othervm -Djava.net.preferIPv4Stack=true NetworkInterfaceStreamTest
|
* @run testng/othervm -Djava.net.preferIPv4Stack=true NetworkInterfaceStreamTest
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
@ -43,10 +44,17 @@ import java.util.stream.OpTestCase;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import java.util.stream.TestData;
|
import java.util.stream.TestData;
|
||||||
|
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class NetworkInterfaceStreamTest extends OpTestCase {
|
public class NetworkInterfaceStreamTest extends OpTestCase {
|
||||||
|
|
||||||
private final static boolean IS_WINDOWS = System.getProperty("os.name").startsWith("Windows");
|
private final static boolean IS_WINDOWS = System.getProperty("os.name").startsWith("Windows");
|
||||||
|
|
||||||
|
@BeforeTest
|
||||||
|
void setup() {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNetworkInterfaces() throws SocketException {
|
public void testNetworkInterfaces() throws SocketException {
|
||||||
Supplier<Stream<NetworkInterface>> ss = () -> {
|
Supplier<Stream<NetworkInterface>> ss = () -> {
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 4405354 6594296 8058216
|
* @bug 4405354 6594296 8058216
|
||||||
|
* @library /test/lib
|
||||||
* @run main Test
|
* @run main Test
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true Test
|
* @run main/othervm -Djava.net.preferIPv4Stack=true Test
|
||||||
* @summary Basic tests for NetworkInterface
|
* @summary Basic tests for NetworkInterface
|
||||||
|
@ -30,11 +31,13 @@
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class Test {
|
public class Test {
|
||||||
static final boolean isWindows = System.getProperty("os.name").startsWith("Windows");
|
static final boolean isWindows = System.getProperty("os.name").startsWith("Windows");
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
Enumeration nifs = NetworkInterface.getNetworkInterfaces();
|
Enumeration nifs = NetworkInterface.getNetworkInterfaces();
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8067105
|
* @bug 8067105
|
||||||
|
* @library /test/lib
|
||||||
* @summary Socket returned by ServerSocket.accept() is inherited by child process on Windows
|
* @summary Socket returned by ServerSocket.accept() is inherited by child process on Windows
|
||||||
* @author Chris Hegarty
|
* @author Chris Hegarty
|
||||||
*/
|
*/
|
||||||
|
@ -36,6 +37,7 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class AcceptInheritHandle {
|
public class AcceptInheritHandle {
|
||||||
|
|
||||||
|
@ -81,7 +83,9 @@ public class AcceptInheritHandle {
|
||||||
|
|
||||||
static void testJavaNetServerSocket() throws Exception {
|
static void testJavaNetServerSocket() throws Exception {
|
||||||
test(ServerSocketProducer.JAVA_NET);
|
test(ServerSocketProducer.JAVA_NET);
|
||||||
test(ServerSocketProducer.JAVA_NET, "-Djava.net.preferIPv4Stack=true");
|
if (IPSupport.hasIPv4()) {
|
||||||
|
test(ServerSocketProducer.JAVA_NET, "-Djava.net.preferIPv4Stack=true");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
static void testNioServerSocketChannel() throws Exception {
|
static void testNioServerSocketChannel() throws Exception {
|
||||||
test(ServerSocketProducer.NIO_CHANNELS);
|
test(ServerSocketProducer.NIO_CHANNELS);
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
* @library /test/lib
|
||||||
* @modules java.management java.base/java.io:+open java.base/java.net:+open
|
* @modules java.management java.base/java.io:+open java.base/java.net:+open
|
||||||
* @run main/othervm UnreferencedSockets
|
* @run main/othervm UnreferencedSockets
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true UnreferencedSockets
|
* @run main/othervm -Djava.net.preferIPv4Stack=true UnreferencedSockets
|
||||||
|
@ -51,6 +52,8 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import com.sun.management.UnixOperatingSystemMXBean;
|
import com.sun.management.UnixOperatingSystemMXBean;
|
||||||
|
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class UnreferencedSockets {
|
public class UnreferencedSockets {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,6 +110,7 @@ public class UnreferencedSockets {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
// Create and close a ServerSocket to warm up the FD count for side effects.
|
// Create and close a ServerSocket to warm up the FD count for side effects.
|
||||||
try (ServerSocket s = new ServerSocket(0)) {
|
try (ServerSocket s = new ServerSocket(0)) {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4507501
|
* @bug 4507501
|
||||||
|
* @library /test/lib
|
||||||
* @summary Test various methods that should throw IAE when passed improper
|
* @summary Test various methods that should throw IAE when passed improper
|
||||||
* SocketAddress
|
* SocketAddress
|
||||||
* @run main AddressTest
|
* @run main AddressTest
|
||||||
|
@ -31,6 +32,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class AddressTest {
|
public class AddressTest {
|
||||||
class MySocketAddress extends SocketAddress {
|
class MySocketAddress extends SocketAddress {
|
||||||
|
@ -153,6 +155,7 @@ public class AddressTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
new AddressTest();
|
new AddressTest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 6210227
|
* @bug 6210227
|
||||||
|
* @library /test/lib
|
||||||
* @summary REGRESSION: Socket.getLocalAddress() returns address of 0.0.0.0 on outbound TCP
|
* @summary REGRESSION: Socket.getLocalAddress() returns address of 0.0.0.0 on outbound TCP
|
||||||
* @run main B6210227
|
* @run main B6210227
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true B6210227
|
* @run main/othervm -Djava.net.preferIPv4Stack=true B6210227
|
||||||
|
@ -31,10 +32,13 @@
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class B6210227 {
|
public class B6210227 {
|
||||||
public static void main(String[] args) throws Exception
|
public static void main(String[] args) throws Exception
|
||||||
{
|
{
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
ServerSocket ss = new ServerSocket(0);
|
ServerSocket ss = new ServerSocket(0);
|
||||||
int port = ss.getLocalPort();
|
int port = ss.getLocalPort();
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4091859 8189366
|
* @bug 4091859 8189366
|
||||||
|
* @library /test/lib
|
||||||
* @summary Test Socket.available()
|
* @summary Test Socket.available()
|
||||||
* @run main CloseAvailable
|
* @run main CloseAvailable
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true CloseAvailable
|
* @run main/othervm -Djava.net.preferIPv4Stack=true CloseAvailable
|
||||||
|
@ -31,11 +32,14 @@
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
|
|
||||||
public class CloseAvailable {
|
public class CloseAvailable {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
testClose();
|
testClose();
|
||||||
|
|
||||||
testEOF(true);
|
testEOF(true);
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4176738
|
* @bug 4176738
|
||||||
|
* @library /test/lib
|
||||||
* @summary Make sure a deadlock situation
|
* @summary Make sure a deadlock situation
|
||||||
* would not occur
|
* would not occur
|
||||||
* @run main DeadlockTest
|
* @run main DeadlockTest
|
||||||
|
@ -32,9 +33,12 @@
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class DeadlockTest {
|
public class DeadlockTest {
|
||||||
public static void main(String [] argv) throws Exception {
|
public static void main(String [] argv) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
ServerSocket ss = new ServerSocket(0);
|
ServerSocket ss = new ServerSocket(0);
|
||||||
Socket clientSocket = new Socket();
|
Socket clientSocket = new Socket();
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4106601 8026245 8071424
|
* @bug 4106601 8026245 8071424
|
||||||
|
* @library /test/lib
|
||||||
* @run main/othervm GetLocalAddress
|
* @run main/othervm GetLocalAddress
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true GetLocalAddress
|
* @run main/othervm -Djava.net.preferIPv4Stack=true GetLocalAddress
|
||||||
* @run main/othervm -Djava.net.preferIPv6Addresses=true GetLocalAddress
|
* @run main/othervm -Djava.net.preferIPv6Addresses=true GetLocalAddress
|
||||||
|
@ -32,6 +33,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class GetLocalAddress implements Runnable {
|
public class GetLocalAddress implements Runnable {
|
||||||
static ServerSocket ss;
|
static ServerSocket ss;
|
||||||
|
@ -39,6 +41,8 @@ public class GetLocalAddress implements Runnable {
|
||||||
static int port;
|
static int port;
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
testBindNull();
|
testBindNull();
|
||||||
|
|
||||||
boolean error = true;
|
boolean error = true;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 6370908 8220663
|
* @bug 6370908 8220663
|
||||||
|
* @library /test/lib
|
||||||
* @summary Add support for HTTP_CONNECT proxy in Socket class
|
* @summary Add support for HTTP_CONNECT proxy in Socket class
|
||||||
* @modules java.base/sun.net.www
|
* @modules java.base/sun.net.www
|
||||||
* @run main HttpProxy
|
* @run main HttpProxy
|
||||||
|
@ -44,6 +45,7 @@ import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
import sun.net.www.MessageHeader;
|
import sun.net.www.MessageHeader;
|
||||||
|
|
||||||
public class HttpProxy {
|
public class HttpProxy {
|
||||||
|
@ -52,6 +54,8 @@ public class HttpProxy {
|
||||||
static final int SO_TIMEOUT = 15000;
|
static final int SO_TIMEOUT = 15000;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
String host;
|
String host;
|
||||||
int port;
|
int port;
|
||||||
ConnectProxyTunnelServer proxy = null;
|
ConnectProxyTunnelServer proxy = null;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 6598160
|
* @bug 6598160
|
||||||
|
* @library /test/lib
|
||||||
* @summary Windows IPv6 Socket implementation doesn't set the handle to not inherit
|
* @summary Windows IPv6 Socket implementation doesn't set the handle to not inherit
|
||||||
* @author Chris Hegarty
|
* @author Chris Hegarty
|
||||||
* @run main InheritHandle
|
* @run main InheritHandle
|
||||||
|
@ -33,6 +34,7 @@ import java.net.BindException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test is only really applicable to Windows machines that are running IPv6, but
|
* This test is only really applicable to Windows machines that are running IPv6, but
|
||||||
|
@ -45,6 +47,8 @@ public class InheritHandle
|
||||||
"bin" + File.separator + "java";
|
"bin" + File.separator + "java";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
doWait();
|
doWait();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4508149
|
* @bug 4508149
|
||||||
|
* @library /test/lib
|
||||||
* @summary Setting ServerSocket.setSoTimeout shouldn't cause
|
* @summary Setting ServerSocket.setSoTimeout shouldn't cause
|
||||||
* the timeout to be inherited by accepted connections
|
* the timeout to be inherited by accepted connections
|
||||||
* @run main InheritTimeout
|
* @run main InheritTimeout
|
||||||
|
@ -32,6 +33,7 @@
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class InheritTimeout {
|
public class InheritTimeout {
|
||||||
|
|
||||||
|
@ -92,6 +94,7 @@ public class InheritTimeout {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
new InheritTimeout();
|
new InheritTimeout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 4796166
|
* @bug 4796166
|
||||||
|
* @library /test/lib
|
||||||
* @summary Linger interval delays usage of released file descriptor
|
* @summary Linger interval delays usage of released file descriptor
|
||||||
* @run main LingerTest
|
* @run main LingerTest
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true LingerTest
|
* @run main/othervm -Djava.net.preferIPv4Stack=true LingerTest
|
||||||
|
@ -31,6 +32,7 @@
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class LingerTest {
|
public class LingerTest {
|
||||||
|
|
||||||
|
@ -105,6 +107,8 @@ public class LingerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
InetAddress loopback = InetAddress.getLoopbackAddress();
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
ServerSocket ss = new ServerSocket(0, 50, loopback);
|
ServerSocket ss = new ServerSocket(0, 50, loopback);
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4469866
|
* @bug 4469866
|
||||||
|
* @library /test/lib
|
||||||
* @summary Connecting to a link-local IPv6 address should not
|
* @summary Connecting to a link-local IPv6 address should not
|
||||||
* causes a SocketException to be thrown.
|
* causes a SocketException to be thrown.
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
|
@ -33,12 +34,13 @@
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true LinkLocal
|
* @run main/othervm -Djava.net.preferIPv4Stack=true LinkLocal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import jdk.test.lib.NetworkConfiguration;
|
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import jdk.test.lib.NetworkConfiguration;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class LinkLocal {
|
public class LinkLocal {
|
||||||
|
|
||||||
static int testCount = 0;
|
static int testCount = 0;
|
||||||
|
@ -120,6 +122,7 @@ public class LinkLocal {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If an argument is provided ensure that it's
|
* If an argument is provided ensure that it's
|
||||||
|
|
|
@ -24,12 +24,15 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4097826
|
* @bug 4097826
|
||||||
|
* @library /test/lib
|
||||||
* @summary SOCKS support inadequate
|
* @summary SOCKS support inadequate
|
||||||
* @run main/timeout=40/othervm -DsocksProxyHost=nonexistant ProxyCons
|
* @run main/timeout=40/othervm -DsocksProxyHost=nonexistant ProxyCons
|
||||||
* @run main/timeout=40/othervm -DsocksProxyHost=nonexistant -Djava.net.preferIPv4Stack=true ProxyCons
|
* @run main/timeout=40/othervm -DsocksProxyHost=nonexistant -Djava.net.preferIPv4Stack=true ProxyCons
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class ProxyCons {
|
public class ProxyCons {
|
||||||
class Server extends Thread {
|
class Server extends Thread {
|
||||||
ServerSocket server;
|
ServerSocket server;
|
||||||
|
@ -77,6 +80,8 @@ public class ProxyCons {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
ProxyCons c = new ProxyCons();
|
ProxyCons c = new ProxyCons();
|
||||||
c.test();
|
c.test();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,16 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* @test
|
||||||
* @bug 4468997
|
* @bug 4468997
|
||||||
|
* @library /test/lib
|
||||||
* @summary SO_LINGER is ignored on Windows with Winsock 2
|
* @summary SO_LINGER is ignored on Windows with Winsock 2
|
||||||
* @run main RST
|
* @run main RST
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true RST
|
* @run main/othervm -Djava.net.preferIPv4Stack=true RST
|
||||||
*/
|
*/
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class RST implements Runnable {
|
public class RST implements Runnable {
|
||||||
|
|
||||||
|
@ -77,6 +80,8 @@ public class RST implements Runnable {
|
||||||
|
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
new RST();
|
new RST();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 4169831
|
* @bug 4169831
|
||||||
|
* @library /test/lib
|
||||||
* @summary test timeout on a socket read
|
* @summary test timeout on a socket read
|
||||||
* @run main/timeout=15 ReadTimeout
|
* @run main/timeout=15 ReadTimeout
|
||||||
* @run main/othervm/timeout=15 -Djava.net.preferIPv4Stack=true ReadTimeout
|
* @run main/othervm/timeout=15 -Djava.net.preferIPv4Stack=true ReadTimeout
|
||||||
|
@ -31,9 +32,12 @@
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class ReadTimeout {
|
public class ReadTimeout {
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
InetAddress sin = null;
|
InetAddress sin = null;
|
||||||
Socket soc = null,soc1 = null;
|
Socket soc = null,soc1 = null;
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8201510
|
* @bug 8201510
|
||||||
|
* @library /test/lib
|
||||||
* @summary Make sure IPv6 addresses are rejected when the System option
|
* @summary Make sure IPv6 addresses are rejected when the System option
|
||||||
* java.net.preferIPv4Stack is set to true
|
* java.net.preferIPv4Stack is set to true
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true RejectIPv6
|
* @run main/othervm -Djava.net.preferIPv4Stack=true RejectIPv6
|
||||||
|
@ -33,10 +34,13 @@ import java.net.InetSocketAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class RejectIPv6 {
|
public class RejectIPv6 {
|
||||||
|
|
||||||
public static void main(String [] argv) throws Throwable {
|
public static void main(String [] argv) throws Throwable {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
ServerSocket serverSocket = new ServerSocket(0);
|
ServerSocket serverSocket = new ServerSocket(0);
|
||||||
serverSocket.setSoTimeout(1000);
|
serverSocket.setSoTimeout(1000);
|
||||||
int serverPort = serverSocket.getLocalPort();
|
int serverPort = serverSocket.getLocalPort();
|
||||||
|
|
|
@ -24,17 +24,21 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4151834
|
* @bug 4151834
|
||||||
|
* @library /test/lib
|
||||||
* @summary Test Socket.setSoLinger
|
* @summary Test Socket.setSoLinger
|
||||||
* @run main SetSoLinger
|
* @run main SetSoLinger
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true SetSoLinger
|
* @run main/othervm -Djava.net.preferIPv4Stack=true SetSoLinger
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class SetSoLinger {
|
public class SetSoLinger {
|
||||||
static final int LINGER = 65546;
|
static final int LINGER = 65546;
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
int value;
|
int value;
|
||||||
InetAddress addr = InetAddress.getLocalHost();
|
InetAddress addr = InetAddress.getLocalHost();
|
||||||
ServerSocket ss = new ServerSocket(0);
|
ServerSocket ss = new ServerSocket(0);
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 7014860
|
* @bug 7014860
|
||||||
|
* @library /test/lib
|
||||||
* @summary Socket.getInputStream().available() not clear for
|
* @summary Socket.getInputStream().available() not clear for
|
||||||
* case that connection is shutdown for reading
|
* case that connection is shutdown for reading
|
||||||
* @run main ShutdownInput
|
* @run main ShutdownInput
|
||||||
|
@ -38,11 +39,14 @@ import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class ShutdownInput {
|
public class ShutdownInput {
|
||||||
static boolean failed = false;
|
static boolean failed = false;
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
InetAddress iaddr = InetAddress.getLocalHost();
|
InetAddress iaddr = InetAddress.getLocalHost();
|
||||||
|
|
||||||
try ( ServerSocket ss = new ServerSocket(0);
|
try ( ServerSocket ss = new ServerSocket(0);
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 6223635
|
* @bug 6223635
|
||||||
|
* @library /test/lib
|
||||||
* @summary Code hangs at connect call even when Timeout is specified
|
* @summary Code hangs at connect call even when Timeout is specified
|
||||||
* @run main SocksConnectTimeout
|
* @run main SocksConnectTimeout
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true SocksConnectTimeout
|
* @run main/othervm -Djava.net.preferIPv4Stack=true SocksConnectTimeout
|
||||||
|
@ -39,6 +40,7 @@ import java.io.IOException;
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.util.concurrent.Phaser;
|
import java.util.concurrent.Phaser;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class SocksConnectTimeout {
|
public class SocksConnectTimeout {
|
||||||
static ServerSocket serverSocket;
|
static ServerSocket serverSocket;
|
||||||
|
@ -48,6 +50,8 @@ public class SocksConnectTimeout {
|
||||||
static int failed, passed;
|
static int failed, passed;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
serverSocket = new ServerSocket(0);
|
serverSocket = new ServerSocket(0);
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 6505016
|
* @bug 6505016
|
||||||
|
* @library /test/lib
|
||||||
* @summary Socket spec should clarify what getInetAddress/getPort/etc return
|
* @summary Socket spec should clarify what getInetAddress/getPort/etc return
|
||||||
* after the Socket is closed
|
* after the Socket is closed
|
||||||
* @run main TestAfterClose
|
* @run main TestAfterClose
|
||||||
|
@ -32,12 +33,15 @@
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class TestAfterClose
|
public class TestAfterClose
|
||||||
{
|
{
|
||||||
static int failCount;
|
static int failCount;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InetAddress loopback = InetAddress.getLoopbackAddress();
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
||||||
ServerSocket ss = new ServerSocket(0, 0, loopback);
|
ServerSocket ss = new ServerSocket(0, 0, loopback);
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4408755
|
* @bug 4408755
|
||||||
|
* @library /test/lib
|
||||||
* @summary This tests whether it's possible to get some informations
|
* @summary This tests whether it's possible to get some informations
|
||||||
* out of a closed socket. This is for backward compatibility
|
* out of a closed socket. This is for backward compatibility
|
||||||
* purposes.
|
* purposes.
|
||||||
|
@ -31,10 +32,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class TestClose {
|
public class TestClose {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
ServerSocket ss;
|
ServerSocket ss;
|
||||||
Socket s;
|
Socket s;
|
||||||
InetAddress ad1, ad2;
|
InetAddress ad1, ad2;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 6404388
|
* @bug 6404388
|
||||||
|
* @library /test/lib
|
||||||
* @summary VISTA: Socket setTcpNoDelay & setKeepAlive working incorrectly
|
* @summary VISTA: Socket setTcpNoDelay & setKeepAlive working incorrectly
|
||||||
* @run main TestTcpNoDelay
|
* @run main TestTcpNoDelay
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true TestTcpNoDelay
|
* @run main/othervm -Djava.net.preferIPv4Stack=true TestTcpNoDelay
|
||||||
|
@ -31,10 +32,13 @@
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class TestTcpNoDelay
|
public class TestTcpNoDelay
|
||||||
{
|
{
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Socket socket = new Socket();
|
Socket socket = new Socket();
|
||||||
boolean on = socket.getTcpNoDelay();
|
boolean on = socket.getTcpNoDelay();
|
||||||
|
|
|
@ -24,15 +24,19 @@
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 4163126
|
* @bug 4163126
|
||||||
|
* @library /test/lib
|
||||||
* @summary test to see if timeout hangs
|
* @summary test to see if timeout hangs
|
||||||
* @run main/timeout=15 Timeout
|
* @run main/timeout=15 Timeout
|
||||||
* @run main/othervm/timeout=15 -Djava.net.preferIPv4Stack=true Timeout
|
* @run main/othervm/timeout=15 -Djava.net.preferIPv4Stack=true Timeout
|
||||||
*/
|
*/
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class Timeout {
|
public class Timeout {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
ServerSocket sock = new ServerSocket(0);
|
ServerSocket sock = new ServerSocket(0);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4511783
|
* @bug 4511783
|
||||||
|
* @library /test/lib
|
||||||
* @summary Test that setTrafficClass/getTraffiClass don't
|
* @summary Test that setTrafficClass/getTraffiClass don't
|
||||||
* throw an exception
|
* throw an exception
|
||||||
* @run main TrafficClass
|
* @run main TrafficClass
|
||||||
|
@ -32,6 +33,7 @@
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
import java.nio.channels.*;
|
import java.nio.channels.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class TrafficClass {
|
public class TrafficClass {
|
||||||
|
|
||||||
|
@ -61,6 +63,7 @@ public class TrafficClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
DatagramSocket ds = new DatagramSocket();
|
DatagramSocket ds = new DatagramSocket();
|
||||||
testDatagramSocket(ds);
|
testDatagramSocket(ds);
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4092038
|
* @bug 4092038
|
||||||
|
* @library /test/lib
|
||||||
* @summary TCP Urgent data support
|
* @summary TCP Urgent data support
|
||||||
* @run main UrgentDataTest
|
* @run main UrgentDataTest
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true UrgentDataTest
|
* @run main/othervm -Djava.net.preferIPv4Stack=true UrgentDataTest
|
||||||
|
@ -31,6 +32,7 @@
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class UrgentDataTest {
|
public class UrgentDataTest {
|
||||||
|
|
||||||
|
@ -51,6 +53,8 @@ public class UrgentDataTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main (String args[]) {
|
public static void main (String args[]) {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
UrgentDataTest test = new UrgentDataTest ();
|
UrgentDataTest test = new UrgentDataTest ();
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
|
|
|
@ -24,11 +24,13 @@
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
import static java.util.concurrent.CompletableFuture.*;
|
import static java.util.concurrent.CompletableFuture.*;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4344135
|
* @bug 4344135
|
||||||
|
* @library /test/lib
|
||||||
* @summary Check that {Socket,ServerSocket,DatagramSocket}.close will
|
* @summary Check that {Socket,ServerSocket,DatagramSocket}.close will
|
||||||
* cause any thread blocked on the socket to throw a SocketException.
|
* cause any thread blocked on the socket to throw a SocketException.
|
||||||
* @run main AsyncClose
|
* @run main AsyncClose
|
||||||
|
@ -38,6 +40,7 @@ import static java.util.concurrent.CompletableFuture.*;
|
||||||
public class AsyncClose {
|
public class AsyncClose {
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
AsyncCloseTest tests[] = {
|
AsyncCloseTest tests[] = {
|
||||||
new Socket_getInputStream_read(),
|
new Socket_getInputStream_read(),
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4511404
|
* @bug 4511404
|
||||||
|
* @library /test/lib
|
||||||
* @summary Check that a broken pipe error doesn't throw an exception
|
* @summary Check that a broken pipe error doesn't throw an exception
|
||||||
* indicating the socket is closed.
|
* indicating the socket is closed.
|
||||||
* @run main BrokenPipe
|
* @run main BrokenPipe
|
||||||
|
@ -31,6 +32,7 @@
|
||||||
*/
|
*/
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class BrokenPipe {
|
public class BrokenPipe {
|
||||||
|
|
||||||
|
@ -53,6 +55,8 @@ public class BrokenPipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
ServerSocket ss = new ServerSocket(0);
|
ServerSocket ss = new ServerSocket(0);
|
||||||
Socket client = new Socket(InetAddress.getLocalHost(),
|
Socket client = new Socket(InetAddress.getLocalHost(),
|
||||||
ss.getLocalPort());
|
ss.getLocalPort());
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4476378
|
* @bug 4476378
|
||||||
|
* @library /test/lib
|
||||||
* @summary Check the specific behaviour of the setReuseAddress(boolean)
|
* @summary Check the specific behaviour of the setReuseAddress(boolean)
|
||||||
* method.
|
* method.
|
||||||
* @run main Basic
|
* @run main Basic
|
||||||
|
@ -36,6 +37,7 @@
|
||||||
* -Djava.net.preferIPv4Stack=true Basic
|
* -Djava.net.preferIPv4Stack=true Basic
|
||||||
*/
|
*/
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class Basic {
|
public class Basic {
|
||||||
|
|
||||||
|
@ -226,6 +228,7 @@ public class Basic {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
new Basic();
|
new Basic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4476378
|
* @bug 4476378
|
||||||
|
* @library /test/lib
|
||||||
* @summary Check that SO_REUSEADDR allows a server to restart
|
* @summary Check that SO_REUSEADDR allows a server to restart
|
||||||
* after a crash.
|
* after a crash.
|
||||||
* @run main Restart
|
* @run main Restart
|
||||||
|
@ -36,6 +37,7 @@
|
||||||
* -Djava.net.preferIPv4Stack=true Restart
|
* -Djava.net.preferIPv4Stack=true Restart
|
||||||
*/
|
*/
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class Restart {
|
public class Restart {
|
||||||
|
|
||||||
|
@ -47,6 +49,8 @@ public class Restart {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
ServerSocket ss = new ServerSocket(0);
|
ServerSocket ss = new ServerSocket(0);
|
||||||
Socket s1 = null, s2 = null;
|
Socket s1 = null, s2 = null;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4681556
|
* @bug 4681556
|
||||||
|
* @library /test/lib
|
||||||
* @summary Wrong text if a read is performed on a socket after it
|
* @summary Wrong text if a read is performed on a socket after it
|
||||||
* has been closed
|
* has been closed
|
||||||
* @run main SocketClosedException
|
* @run main SocketClosedException
|
||||||
|
@ -32,6 +33,7 @@
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class SocketClosedException {
|
public class SocketClosedException {
|
||||||
static void doServerSide() throws Exception {
|
static void doServerSide() throws Exception {
|
||||||
|
@ -61,6 +63,7 @@ public class SocketClosedException {
|
||||||
static Exception serverException = null;
|
static Exception serverException = null;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
serverSocket = new ServerSocket(0);
|
serverSocket = new ServerSocket(0);
|
||||||
startServer();
|
startServer();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 4158021
|
* @bug 4158021
|
||||||
|
* @library /test/lib
|
||||||
* @summary cannot distinguish Thread.interrupt and Socket.setSoTimeout exceptions
|
* @summary cannot distinguish Thread.interrupt and Socket.setSoTimeout exceptions
|
||||||
* @run main SocketTimeout
|
* @run main SocketTimeout
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true SocketTimeout
|
* @run main/othervm -Djava.net.preferIPv4Stack=true SocketTimeout
|
||||||
|
@ -31,11 +32,13 @@
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class SocketTimeout {
|
public class SocketTimeout {
|
||||||
static final int TIMEOUT = 1000;
|
static final int TIMEOUT = 1000;
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
InetAddress sin = InetAddress.getLocalHost();
|
InetAddress sin = InetAddress.getLocalHost();
|
||||||
Socket soc = null,soc1 = null;
|
Socket soc = null,soc1 = null;
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8148609
|
* @bug 8148609
|
||||||
|
* @library /test/lib
|
||||||
* @summary Assert that the set of socket options are immutable
|
* @summary Assert that the set of socket options are immutable
|
||||||
* @run testng/othervm ImmutableOptions
|
* @run testng/othervm ImmutableOptions
|
||||||
* @run testng/othervm -Djava.net.preferIPv4Stack=true ImmutableOptions
|
* @run testng/othervm -Djava.net.preferIPv4Stack=true ImmutableOptions
|
||||||
|
@ -34,6 +35,8 @@ import java.io.OutputStream;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -41,6 +44,7 @@ public class ImmutableOptions {
|
||||||
|
|
||||||
@BeforeTest
|
@BeforeTest
|
||||||
void setupServerSocketFactory() throws IOException {
|
void setupServerSocketFactory() throws IOException {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
ServerSocket.setSocketFactory(new ServerSocketImplFactory());
|
ServerSocket.setSocketFactory(new ServerSocketImplFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
|
* @library /test/lib
|
||||||
* @bug 8170920
|
* @bug 8170920
|
||||||
* @run main MinimumRcvBufferSize
|
* @run main MinimumRcvBufferSize
|
||||||
* @run main/othervm -Djava.net.preferIPv4Stack=true MinimumRcvBufferSize
|
* @run main/othervm -Djava.net.preferIPv4Stack=true MinimumRcvBufferSize
|
||||||
|
@ -30,10 +31,13 @@
|
||||||
|
|
||||||
import java.nio.channels.*;
|
import java.nio.channels.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class MinimumRcvBufferSize {
|
public class MinimumRcvBufferSize {
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
boolean error = false;
|
boolean error = false;
|
||||||
ServerSocketChannel channel = ServerSocketChannel.open();
|
ServerSocketChannel channel = ServerSocketChannel.open();
|
||||||
int before = channel.getOption(StandardSocketOptions.SO_RCVBUF);
|
int before = channel.getOption(StandardSocketOptions.SO_RCVBUF);
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8036979 8072384 8044773
|
* @bug 8036979 8072384 8044773
|
||||||
|
* @library /test/lib
|
||||||
* @requires !vm.graal.enabled
|
* @requires !vm.graal.enabled
|
||||||
* @run main/othervm -Xcheck:jni OptionsTest
|
* @run main/othervm -Xcheck:jni OptionsTest
|
||||||
* @run main/othervm -Xcheck:jni -Djava.net.preferIPv4Stack=true OptionsTest
|
* @run main/othervm -Xcheck:jni -Djava.net.preferIPv4Stack=true OptionsTest
|
||||||
|
@ -33,6 +34,7 @@
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class OptionsTest {
|
public class OptionsTest {
|
||||||
|
|
||||||
|
@ -278,6 +280,7 @@ public class OptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
doSocketTests();
|
doSocketTests();
|
||||||
doServerSocketTests();
|
doServerSocketTests();
|
||||||
doDgSocketTests();
|
doDgSocketTests();
|
||||||
|
|
|
@ -25,10 +25,12 @@ import java.io.IOException;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import static java.lang.System.out;
|
import static java.lang.System.out;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8143923
|
* @bug 8143923
|
||||||
|
* @library /test/lib
|
||||||
* @summary java.net socket supportedOptions set depends on call order
|
* @summary java.net socket supportedOptions set depends on call order
|
||||||
* @run main/othervm SupportedOptionsSet first
|
* @run main/othervm SupportedOptionsSet first
|
||||||
* @run main/othervm SupportedOptionsSet second
|
* @run main/othervm SupportedOptionsSet second
|
||||||
|
@ -42,6 +44,8 @@ import static java.lang.System.out;
|
||||||
public class SupportedOptionsSet {
|
public class SupportedOptionsSet {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
if (args[0].equals("first"))
|
if (args[0].equals("first"))
|
||||||
first();
|
first();
|
||||||
else if (args[0].equals("second"))
|
else if (args[0].equals("second"))
|
||||||
|
|
|
@ -27,9 +27,12 @@ import java.net.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 8143554 8044773
|
* @bug 8143554 8044773
|
||||||
|
* @library /test/lib
|
||||||
* @summary Test checks that UnsupportedOperationException for unsupported
|
* @summary Test checks that UnsupportedOperationException for unsupported
|
||||||
* SOCKET_OPTIONS is thrown by both getOption() and setOption() methods.
|
* SOCKET_OPTIONS is thrown by both getOption() and setOption() methods.
|
||||||
* @requires !vm.graal.enabled
|
* @requires !vm.graal.enabled
|
||||||
|
@ -69,6 +72,8 @@ public class UnsupportedOptionsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
Socket s = new Socket();
|
Socket s = new Socket();
|
||||||
ServerSocket ss = new ServerSocket();
|
ServerSocket ss = new ServerSocket();
|
||||||
DatagramSocket ds = new DatagramSocket();
|
DatagramSocket ds = new DatagramSocket();
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 7161881
|
* @bug 7161881
|
||||||
|
* @library /test/lib
|
||||||
* @run main/othervm -Djava.net.preferIPv6Addresses=true BindNull
|
* @run main/othervm -Djava.net.preferIPv6Addresses=true BindNull
|
||||||
* @summary Make sure the bind method uses an ipv4 address for the null case
|
* @summary Make sure the bind method uses an ipv4 address for the null case
|
||||||
* when the DatagramChannel is connected to an IPv4 socket and
|
* when the DatagramChannel is connected to an IPv4 socket and
|
||||||
|
@ -32,19 +33,22 @@
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.nio.channels.*;
|
import java.nio.channels.*;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class BindNull {
|
public class BindNull {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
try (DatagramChannel dc = DatagramChannel.open()) {
|
try (DatagramChannel dc = DatagramChannel.open()) {
|
||||||
dc.bind(null);
|
dc.bind(null);
|
||||||
}
|
}
|
||||||
try (DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET)) {
|
if (IPSupport.hasIPv4()) {
|
||||||
dc.bind(null);
|
try (DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET)) {
|
||||||
|
dc.bind(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try (DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET6)) {
|
if (IPSupport.hasIPv6()) {
|
||||||
dc.bind(null);
|
try (DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET6)) {
|
||||||
} catch (UnsupportedOperationException uoe) {
|
dc.bind(null);
|
||||||
// IPv6 not available
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 7132924
|
* @bug 7132924
|
||||||
|
* @library /test/lib
|
||||||
* @key intermittent
|
* @key intermittent
|
||||||
* @summary Test DatagramChannel.disconnect when DatagramChannel is connected to an IPv4 socket
|
* @summary Test DatagramChannel.disconnect when DatagramChannel is connected to an IPv4 socket
|
||||||
* @run main Disconnect
|
* @run main Disconnect
|
||||||
|
@ -33,19 +34,32 @@ import java.net.*;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
import java.nio.channels.*;
|
import java.nio.channels.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class Disconnect {
|
public class Disconnect {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
// test with default protocol family
|
// test with default protocol family
|
||||||
try (DatagramChannel dc = DatagramChannel.open()) {
|
try (DatagramChannel dc = DatagramChannel.open()) {
|
||||||
test(dc);
|
test(dc);
|
||||||
test(dc);
|
test(dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// test with IPv4 only
|
if (IPSupport.hasIPv4()) {
|
||||||
try (DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET)) {
|
// test with IPv4 only
|
||||||
test(dc);
|
try (DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET)) {
|
||||||
test(dc);
|
test(dc);
|
||||||
|
test(dc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IPSupport.hasIPv6()) {
|
||||||
|
// test with IPv6 only
|
||||||
|
try (DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET6)) {
|
||||||
|
test(dc);
|
||||||
|
test(dc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ import java.io.IOException;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import jdk.test.lib.NetworkConfiguration;
|
import jdk.test.lib.NetworkConfiguration;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class MulticastSendReceiveTests {
|
public class MulticastSendReceiveTests {
|
||||||
|
|
||||||
|
@ -239,6 +240,8 @@ public class MulticastSendReceiveTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
NetworkConfiguration config = NetworkConfiguration.probe();
|
NetworkConfiguration config = NetworkConfiguration.probe();
|
||||||
|
|
||||||
// multicast groups used for the test
|
// multicast groups used for the test
|
||||||
|
|
|
@ -43,6 +43,7 @@ import java.io.IOException;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import jdk.test.lib.NetworkConfiguration;
|
import jdk.test.lib.NetworkConfiguration;
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class Promiscuous {
|
public class Promiscuous {
|
||||||
|
|
||||||
|
@ -192,6 +193,8 @@ public class Promiscuous {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
String os = System.getProperty("os.name");
|
String os = System.getProperty("os.name");
|
||||||
|
|
||||||
// Requires IP_MULTICAST_ALL on Linux (new since 2.6.31) so skip
|
// Requires IP_MULTICAST_ALL on Linux (new since 2.6.31) so skip
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
|
* @library /test/lib
|
||||||
* @bug 6435300
|
* @bug 6435300
|
||||||
* @summary Check using IPv6 address does not crash the VM
|
* @summary Check using IPv6 address does not crash the VM
|
||||||
* @run main/othervm UseDGWithIPv6
|
* @run main/othervm UseDGWithIPv6
|
||||||
|
@ -35,6 +36,8 @@ import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.DatagramChannel;
|
import java.nio.channels.DatagramChannel;
|
||||||
import java.nio.channels.UnsupportedAddressTypeException;
|
import java.nio.channels.UnsupportedAddressTypeException;
|
||||||
|
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class UseDGWithIPv6 {
|
public class UseDGWithIPv6 {
|
||||||
static String[] targets = {
|
static String[] targets = {
|
||||||
"3ffe:e00:811:b::21:5",
|
"3ffe:e00:811:b::21:5",
|
||||||
|
@ -45,6 +48,8 @@ public class UseDGWithIPv6 {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException
|
public static void main(String[] args) throws IOException
|
||||||
{
|
{
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
ByteBuffer data = ByteBuffer.wrap("TESTING DATA".getBytes());
|
ByteBuffer data = ByteBuffer.wrap("TESTING DATA".getBytes());
|
||||||
DatagramChannel dgChannel = DatagramChannel.open();
|
DatagramChannel dgChannel = DatagramChannel.open();
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
* @library /test/lib
|
||||||
* @requires (os.family == "linux" | os.family == "mac" | os.family == "windows")
|
* @requires (os.family == "linux" | os.family == "mac" | os.family == "windows")
|
||||||
* @bug 8209152
|
* @bug 8209152
|
||||||
* @run main PrintSupportedOptions
|
* @run main PrintSupportedOptions
|
||||||
|
@ -33,6 +34,8 @@ import java.io.IOException;
|
||||||
import java.net.SocketOption;
|
import java.net.SocketOption;
|
||||||
import java.nio.channels.*;
|
import java.nio.channels.*;
|
||||||
|
|
||||||
|
import jdk.test.lib.net.IPSupport;
|
||||||
|
|
||||||
public class PrintSupportedOptions {
|
public class PrintSupportedOptions {
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
|
@ -41,6 +44,8 @@ public class PrintSupportedOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
IPSupport.skipIfCurrentConfigurationIsInvalid();
|
||||||
|
|
||||||
test(() -> SocketChannel.open());
|
test(() -> SocketChannel.open());
|
||||||
test(() -> ServerSocketChannel.open());
|
test(() -> ServerSocketChannel.open());
|
||||||
test(() -> DatagramChannel.open());
|
test(() -> DatagramChannel.open());
|
||||||
|
|
147
test/lib/jdk/test/lib/net/IPSupport.java
Normal file
147
test/lib/jdk/test/lib/net/IPSupport.java
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019, 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package jdk.test.lib.net;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.io.UncheckedIOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.ServerSocket;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.security.AccessController;
|
||||||
|
import java.security.PrivilegedActionException;
|
||||||
|
import java.security.PrivilegedExceptionAction;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import jtreg.SkippedException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines Internet Protocol version support at the TCP socket level.
|
||||||
|
*/
|
||||||
|
public class IPSupport {
|
||||||
|
|
||||||
|
private static final boolean hasIPv4;
|
||||||
|
private static final boolean hasIPv6;
|
||||||
|
private static final boolean preferIPv4Stack;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
InetAddress loopbackIPv4 = InetAddress.getByAddress(
|
||||||
|
new byte[] {0x7F, 0x00, 0x00, 0x01});
|
||||||
|
|
||||||
|
InetAddress loopbackIPv6 = InetAddress.getByAddress(
|
||||||
|
new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01});
|
||||||
|
|
||||||
|
hasIPv4 = runPrivilegedAction(() -> hasAddress(loopbackIPv4));
|
||||||
|
hasIPv6 = runPrivilegedAction(() -> hasAddress(loopbackIPv6));
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
preferIPv4Stack = runPrivilegedAction(() -> Boolean.parseBoolean(
|
||||||
|
System.getProperty("java.net.preferIPv4Stack")));
|
||||||
|
if (!preferIPv4Stack && !hasIPv4 && !hasIPv6) {
|
||||||
|
throw new AssertionError("IPv4 and IPv6 both not available and java.net.preferIPv4Stack is not true");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasAddress(InetAddress address) {
|
||||||
|
try (Socket socket = new Socket()) {
|
||||||
|
socket.bind(new InetSocketAddress(address, 0));
|
||||||
|
return true;
|
||||||
|
} catch (SocketException se) {
|
||||||
|
return false;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new UncheckedIOException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> T runPrivilegedAction(Callable<T> callable) {
|
||||||
|
try {
|
||||||
|
PrivilegedExceptionAction<T> pa = () -> callable.call();
|
||||||
|
return AccessController.doPrivileged(pa);
|
||||||
|
} catch (PrivilegedActionException pae) {
|
||||||
|
throw new UncheckedIOException((IOException) pae.getCause());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IPSupport() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not IPv4 is supported.
|
||||||
|
*/
|
||||||
|
public static final boolean hasIPv4() {
|
||||||
|
return hasIPv4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not IPv6 is supported.
|
||||||
|
*/
|
||||||
|
public static final boolean hasIPv6() {
|
||||||
|
return hasIPv6;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the "java.net.preferIPv4Stack" system property is set.
|
||||||
|
*/
|
||||||
|
public static final boolean preferIPv4Stack() {
|
||||||
|
return preferIPv4Stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the current networking configuration is valid or not.
|
||||||
|
*
|
||||||
|
* If preferIPv4Stack is true but there is no IPv4 support, the configuration is invalid.
|
||||||
|
*/
|
||||||
|
public static final boolean currentConfigurationIsValid() {
|
||||||
|
return hasIPv4() || hasIPv6();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throws a jtreg.SkippedException if the current networking configuration is invalid.
|
||||||
|
*/
|
||||||
|
public static void skipIfCurrentConfigurationIsInvalid() throws SkippedException {
|
||||||
|
if (!currentConfigurationIsValid()) {
|
||||||
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
|
PrintStream ps = new PrintStream(os);
|
||||||
|
ps.println("Invalid networking configuration");
|
||||||
|
printPlatformSupport(ps);
|
||||||
|
throw new SkippedException(os.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the platform supported configurations.
|
||||||
|
*/
|
||||||
|
public static void printPlatformSupport(PrintStream out) {
|
||||||
|
out.println("IPSupport - IPv4: " + hasIPv4());
|
||||||
|
out.println("IPSupport - IPv6: " + hasIPv6());
|
||||||
|
out.println("preferIPv4Stack: " + preferIPv4Stack());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue