< prev index next >
test/java/net/MulticastSocket/SetOutgoingIf.java
Print this page
rev 17065 : 7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS
Reviewed-by:
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2017, 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.
@@ -23,14 +23,18 @@
/*
* @test
* @bug 4742177
* @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
+ * @library /lib/testlibrary
+ * @build jdk.testlibrary.NetworkConfiguration
+ * @run main SetOutgoingIf
*/
import java.net.*;
import java.util.*;
-
+import jdk.testlibrary.NetworkConfiguration;
+import static java.util.stream.Collectors.toList;
public class SetOutgoingIf {
private static int PORT = 9001;
private static String osname;
@@ -39,21 +43,11 @@
osname = System.getProperty("os.name");
return osname.contains("Windows");
}
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;
+ return NetworkConfiguration.probe().ip6Addresses().findAny().isPresent();
}
public static void main(String[] args) throws Exception {
if (isWindows()) {
System.out.println("The test only run on non-Windows OS. Bye.");
@@ -63,35 +57,33 @@
if (!hasIPv6()) {
System.out.println("No IPv6 available. Bye.");
return;
}
+ NetworkConfiguration nc = NetworkConfiguration.probe();
+
// We need 2 or more network interfaces to run the test
//
List<NetIf> netIfs = new ArrayList<NetIf>();
int index = 1;
- for (NetworkInterface nic : Collections.list(NetworkInterface.getNetworkInterfaces())) {
- // we should use only network interfaces with multicast support which are in "up" state
- if (!nic.isLoopback() && nic.supportsMulticast() && nic.isUp()) {
+ for (NetworkInterface nic : nc.interfaces().collect(toList())) {
+ // only use network interfaces with multicast support
+ if (!nic.isLoopback() && nic.supportsMulticast()) {
NetIf netIf = NetIf.create(nic);
- // now determine what (if any) type of addresses are assigned to this interface
- for (InetAddress addr : Collections.list(nic.getInetAddresses())) {
- if (addr.isAnyLocalAddress())
- continue;
-
- System.out.println(" addr " + addr);
- if (addr instanceof Inet4Address) {
+ // determine what (if any) type of addresses are assigned
+ List<Inet4Address> ipv4Addrs = nc.ip4Addresses(nic).collect(toList());
+ List<Inet6Address> ipv6Addrs = nc.ip6Addresses(nic).collect(toList());
+ if (!ipv4Addrs.isEmpty())
netIf.ipv4Address(true);
- } else if (addr instanceof Inet6Address) {
+ if (!ipv6Addrs.isEmpty())
netIf.ipv6Address(true);
- }
- }
+
if (netIf.ipv4Address() || netIf.ipv6Address()) {
netIf.index(index++);
netIfs.add(netIf);
- debug("Using: " + nic);
+ debug("Using: " + nic + "\n " + ipv4Addrs + ipv6Addrs);
}
}
}
if (netIfs.size() <= 1) {
System.out.println("Need 2 or more network interfaces to run. Bye.");
< prev index next >