summaryrefslogtreecommitdiff
path: root/java-compat
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2017-01-23 15:39:06 +0100
committerBenoit Foucher <benoit@zeroc.com>2017-01-23 15:39:06 +0100
commit91bdb2c1b221a5ddcb6d9ec28e41ee1beffd5508 (patch)
tree021d4d7f93712e5ea29542f88470401a4955ba27 /java-compat
parentFixed ICE-7517 - Objective-C build failure (diff)
downloadice-91bdb2c1b221a5ddcb6d9ec28e41ee1beffd5508.tar.bz2
ice-91bdb2c1b221a5ddcb6d9ec28e41ee1beffd5508.tar.xz
ice-91bdb2c1b221a5ddcb6d9ec28e41ee1beffd5508.zip
Fixed multicast to also listen on link-locap IPv6 addressees
Diffstat (limited to 'java-compat')
-rw-r--r--java-compat/src/Ice/src/main/java/IceInternal/Network.java82
-rw-r--r--java-compat/src/Ice/src/main/java/IceInternal/UdpTransceiver.java12
2 files changed, 66 insertions, 28 deletions
diff --git a/java-compat/src/Ice/src/main/java/IceInternal/Network.java b/java-compat/src/Ice/src/main/java/IceInternal/Network.java
index 7ee1da0cf58..9a96429a68c 100644
--- a/java-compat/src/Ice/src/main/java/IceInternal/Network.java
+++ b/java-compat/src/Ice/src/main/java/IceInternal/Network.java
@@ -297,14 +297,15 @@ public final class Network
{
try
{
- java.util.List<String> interfaces = getHostsForEndpointExpand(intf, getProtocolSupport(group), true);
- if(interfaces.isEmpty())
+ java.util.Set<java.net.NetworkInterface> interfaces = new java.util.HashSet<>();
+ for(String address : getInterfacesForMulticast(intf, group))
{
- interfaces.add(intf);
- }
- for(String intf2 : interfaces)
- {
- fd.join(group.getAddress(), getInterface(intf2));
+ java.net.NetworkInterface intf2 = getInterface(address);
+ if(!interfaces.contains(intf2))
+ {
+ interfaces.add(intf2);
+ fd.join(group.getAddress(), intf2);
+ }
}
}
catch(Exception ex)
@@ -1021,24 +1022,8 @@ public final class Network
public static java.util.ArrayList<String>
getHostsForEndpointExpand(String host, int protocolSupport, boolean includeLoopback)
{
- boolean wildcard = (host == null || host.length() == 0);
- if(!wildcard)
- {
- try
- {
- wildcard = java.net.InetAddress.getByName(host).isAnyLocalAddress();
- }
- catch(java.net.UnknownHostException ex)
- {
- }
- catch(java.lang.SecurityException ex)
- {
- throw new Ice.SocketException(ex);
- }
- }
-
java.util.ArrayList<String> hosts = new java.util.ArrayList<String>();
- if(wildcard)
+ if(isWildcard(host))
{
java.util.ArrayList<java.net.InetAddress> addrs = getLocalAddresses(protocolSupport);
for(java.net.InetAddress addr : addrs)
@@ -1069,6 +1054,34 @@ public final class Network
return hosts;
}
+ public static java.util.ArrayList<String>
+ getInterfacesForMulticast(String intf, java.net.InetSocketAddress mcastAddr)
+ {
+ int protocolSupport = getProtocolSupport(mcastAddr);
+ java.util.ArrayList<String> interfaces = new java.util.ArrayList<>();
+ if(isWildcard(intf))
+ {
+ java.util.ArrayList<java.net.InetAddress> addrs = getLocalAddresses(protocolSupport);
+ for(java.net.InetAddress addr : addrs)
+ {
+ interfaces.add(addr.getHostAddress());
+ }
+ if(protocolSupport != EnableIPv6)
+ {
+ interfaces.add("127.0.0.1");
+ }
+ if(protocolSupport != EnableIPv4)
+ {
+ interfaces.add("0:0:0:0:0:0:0:1");
+ }
+ }
+ if(interfaces.isEmpty())
+ {
+ interfaces.add(intf);
+ }
+ return interfaces;
+ }
+
public static void
setTcpBufSize(java.nio.channels.SocketChannel socket, ProtocolInstance instance)
{
@@ -1402,6 +1415,27 @@ public final class Network
return addr;
}
+ private static boolean
+ isWildcard(String host)
+ {
+ if(host == null || host.length() == 0)
+ {
+ return true;
+ }
+ try
+ {
+ return java.net.InetAddress.getByName(host).isAnyLocalAddress();
+ }
+ catch(java.net.UnknownHostException ex)
+ {
+ }
+ catch(java.lang.SecurityException ex)
+ {
+ throw new Ice.SocketException(ex);
+ }
+ return false;
+ }
+
static class IPAddressComparator implements java.util.Comparator<java.net.InetSocketAddress>
{
IPAddressComparator(boolean ipv6)
diff --git a/java-compat/src/Ice/src/main/java/IceInternal/UdpTransceiver.java b/java-compat/src/Ice/src/main/java/IceInternal/UdpTransceiver.java
index fe6f67d295e..f6fceb03c6a 100644
--- a/java-compat/src/Ice/src/main/java/IceInternal/UdpTransceiver.java
+++ b/java-compat/src/Ice/src/main/java/IceInternal/UdpTransceiver.java
@@ -282,11 +282,15 @@ final class UdpTransceiver implements Transceiver
public String toDetailedString()
{
StringBuilder s = new StringBuilder(toString());
- String addr = _mcastAddr != null ? _mcastInterface : _addr.getAddress().getHostAddress();
- java.util.List<String> intfs = Network.getHostsForEndpointExpand(addr, _instance.protocolSupport(), true);
- if(_mcastAddr != null && intfs.isEmpty())
+ java.util.List<String> intfs;
+ if(_mcastAddr == null)
{
- intfs.add(_mcastInterface);
+ intfs = Network.getHostsForEndpointExpand(_addr.getAddress().getHostAddress(), _instance.protocolSupport(),
+ true);
+ }
+ else
+ {
+ intfs = Network.getInterfacesForMulticast(_mcastInterface, _mcastAddr);
}
if(!intfs.isEmpty())
{