8179559: Solaris MulticastSocket issues

Reviewed-by: chegar
This commit is contained in:
Michael McMahon 2017-05-08 14:04:27 +01:00
parent c582d3ffba
commit c5c52df157
4 changed files with 103 additions and 3 deletions
jdk
src/java.base/unix/native/libnet
test/java/net

@ -361,7 +361,11 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
((struct sockaddr_in6*)addrP->addr)->sin6_addr);
jbyte caddr[16];
int i;
unsigned int scopeid;
getInet6Address_ipaddress(env, iaObj, (char *)caddr);
scopeid = (unsigned int)getInet6Address_scopeid(env, iaObj);
if (scopeid != 0 && scopeid != ((struct sockaddr_in6*)addrP->addr)->sin6_scope_id)
break;
i = 0;
while (i < 16) {
if (caddr[i] != bytes[i]) {

@ -25,9 +25,14 @@
* @test
* @bug 4686717
* @summary Test MulticastSocket.setLoopbackMode
* @library /lib/testlibrary
* @build jdk.testlibrary.NetworkConfiguration
* @run main/othervm SetLoopbackMode
*/
import java.net.*;
import java.io.IOException;
import java.util.Enumeration;
import jdk.testlibrary.NetworkConfiguration;
public class SetLoopbackMode {
@ -85,8 +90,13 @@ public class SetLoopbackMode {
return PASSED;
}
private static boolean canUseIPv6(NetworkConfiguration nc) {
return nc.ip6MulticastInterfaces().toArray().length > 0;
}
public static void main (String args[]) throws Exception {
int failures = 0;
NetworkConfiguration nc = NetworkConfiguration.probe();
MulticastSocket mc = new MulticastSocket();
InetAddress grp = InetAddress.getByName("224.80.80.80");
@ -97,11 +107,12 @@ public class SetLoopbackMode {
* to workaround Linux IPv6 bug whereby !IPV6_MULTICAST_LOOP
* doesn't prevent loopback of IPv4 multicast packets.
*/
InetAddress lb = InetAddress.getByName("::1");
if (NetworkInterface.getByInetAddress(lb) != null) {
if (canUseIPv6(nc)) {
grp = InetAddress.getByName("ff01::1");
}
//mc.setNetworkInterface(NetworkInterface.getByInetAddress(lb));
System.out.println("\nTest will use multicast group: " + grp);
mc.joinGroup(grp);

@ -35,6 +35,10 @@ public class Test {
static int count = 0;
static int failures = 0;
static boolean isSolaris = System.getProperty("os.name")
.toLowerCase()
.startsWith("sunos");
void doTest(String address) throws Exception {
boolean failed = false;
@ -123,6 +127,14 @@ public class Test {
}
}
static boolean isValidIpv6Address(InetAddress addr) {
if (! (addr instanceof Inet6Address))
return false;
if (!isSolaris)
return true;
return !(addr.isAnyLocalAddress() || addr.isLoopbackAddress());
}
void allTests() throws Exception {
/*
@ -146,7 +158,7 @@ public class Test {
while (addrs.hasMoreElements()) {
InetAddress ia = (InetAddress)addrs.nextElement();
if (ia instanceof Inet6Address) {
if (isValidIpv6Address(ia)) {
has_ipv6 = true;
if (ia.isLinkLocalAddress()) has_linklocaladdress = true;
if (ia.isSiteLocalAddress()) has_siteaddress = true;

@ -0,0 +1,73 @@
/*
* Copyright (c) 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.
*
* 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 8179559
*/
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
public class NetworkInterfaceRetrievalTests {
public static void main(String[] args) throws Exception {
int checkFailureCount = 0;
try {
Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces();
while (en.hasMoreElements()) {
NetworkInterface ni = en.nextElement();
Enumeration<InetAddress> addrs = ni.getInetAddresses();
System.out.println("############ Checking network interface + "
+ ni + " #############");
while (addrs.hasMoreElements()) {
InetAddress addr = addrs.nextElement();
System.out.println("************ Checking address + "
+ addr + " *************");
NetworkInterface addrNetIf = NetworkInterface
.getByInetAddress(addr);
if (addrNetIf.equals(ni)) {
System.out.println("Retreived net if " + addrNetIf
+ " equal to owning net if " + ni);
} else {
System.out.println("Retreived net if " + addrNetIf
+ "NOT equal to owning net if " + ni
+ "***********");
checkFailureCount++;
}
}
}
} catch (Exception ex) {
}
if (checkFailureCount > 0) {
throw new RuntimeException(
"NetworkInterface lookup by address didn't match owner network interface");
}
}
}