mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-14 18:03:44 +00:00
8224014: Don't run test/jdk/java/net/NetworkInterface/IPv4Only.java in IPv6 only environment
Reviewed-by: chegar, dfuchs
This commit is contained in:
parent
21d398288d
commit
905330d4ea
@ -23,6 +23,7 @@
|
||||
|
||||
/* @test
|
||||
* @bug 6964714
|
||||
* @library /test/lib
|
||||
* @run main/othervm -Djava.net.preferIPv4Stack=true IPv4Only
|
||||
* @summary Test the networkinterface listing with java.net.preferIPv4Stack=true.
|
||||
*/
|
||||
@ -30,19 +31,36 @@
|
||||
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
import jdk.test.lib.net.IPSupport;
|
||||
|
||||
public class IPv4Only {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
|
||||
while (nifs.hasMoreElements()) {
|
||||
NetworkInterface nif = nifs.nextElement();
|
||||
Enumeration<InetAddress> addrs = nif.getInetAddresses();
|
||||
while (addrs.hasMoreElements()) {
|
||||
InetAddress hostAddr = addrs.nextElement();
|
||||
if ( hostAddr instanceof Inet6Address ){
|
||||
throw new RuntimeException( "NetworkInterfaceV6List failed - found v6 address " + hostAddr.getHostAddress() );
|
||||
}
|
||||
if (IPSupport.hasIPv4()) {
|
||||
System.out.println("Testing IPv4");
|
||||
Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
|
||||
while (nifs.hasMoreElements()) {
|
||||
NetworkInterface nif = nifs.nextElement();
|
||||
Enumeration<InetAddress> addrs = nif.getInetAddresses();
|
||||
while (addrs.hasMoreElements()) {
|
||||
InetAddress hostAddr = addrs.nextElement();
|
||||
if ( hostAddr instanceof Inet6Address ){
|
||||
throw new RuntimeException( "NetworkInterfaceV6List failed - found v6 address " + hostAddr.getHostAddress() );
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
NetworkInterface.getNetworkInterfaces();
|
||||
throw new RuntimeException("NetworkInterface.getNetworkInterfaces() should throw SocketException");
|
||||
} catch (SocketException expected) {
|
||||
System.out.println("caught expected exception: " + expected);
|
||||
}
|
||||
|
||||
try {
|
||||
NetworkInterface.networkInterfaces();
|
||||
throw new RuntimeException("NetworkInterface.networkInterfaces() should throw SocketException");
|
||||
} catch (SocketException expected) {
|
||||
System.out.println("caught expected exception: " + expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user