# HG changeset patch # User chegar # Date 1493970770 -3600 # Fri May 05 08:52:50 2017 +0100 # Node ID bfda62a61ea870254598ae74a8386886988f4a15 # Parent 1fd0df22cdbab4c539ce141f878f1ea5c329f167 7155591: test/java/net/MulticastSocket/SetOutgoingIf.java fails on macOS Reviewed-by: diff --git a/test/java/net/MulticastSocket/SetOutgoingIf.java b/test/java/net/MulticastSocket/SetOutgoingIf.java --- a/test/java/net/MulticastSocket/SetOutgoingIf.java +++ b/test/java/net/MulticastSocket/SetOutgoingIf.java @@ -1,5 +1,5 @@ /* - * 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 @@ -25,10 +25,14 @@ * @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; @@ -41,17 +45,7 @@ } private static boolean hasIPv6() throws Exception { - List nics = Collections.list( - NetworkInterface.getNetworkInterfaces()); - for (NetworkInterface nic : nics) { - List 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 { @@ -65,31 +59,29 @@ return; } + NetworkConfiguration nc = NetworkConfiguration.probe(); + // We need 2 or more network interfaces to run the test // List netIfs = new ArrayList(); 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; + // determine what (if any) type of addresses are assigned + List ipv4Addrs = nc.ip4Addresses(nic).collect(toList()); + List ipv6Addrs = nc.ip6Addresses(nic).collect(toList()); + if (!ipv4Addrs.isEmpty()) + netIf.ipv4Address(true); + if (!ipv6Addrs.isEmpty()) + netIf.ipv6Address(true); - System.out.println(" addr " + addr); - if (addr instanceof Inet4Address) { - netIf.ipv4Address(true); - } else if (addr instanceof Inet6Address) { - netIf.ipv6Address(true); - } - } if (netIf.ipv4Address() || netIf.ipv6Address()) { netIf.index(index++); netIfs.add(netIf); - debug("Using: " + nic); + debug("Using: " + nic + "\n " + ipv4Addrs + ipv6Addrs); } } }