diff options
author | Matthew Newhook <matthew@zeroc.com> | 2009-01-06 17:00:51 -0330 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2009-01-06 17:00:51 -0330 |
commit | a76b06fe3cd958cd12b0e8b0fa3f9feb5222c944 (patch) | |
tree | 312fed943d329b15bec549fee0d066389e240bc8 /java/src/IceInternal/Network.java | |
parent | Bug 3622 - updated version to 3.3.1 (diff) | |
download | ice-a76b06fe3cd958cd12b0e8b0fa3f9feb5222c944.tar.bz2 ice-a76b06fe3cd958cd12b0e8b0fa3f9feb5222c944.tar.xz ice-a76b06fe3cd958cd12b0e8b0fa3f9feb5222c944.zip |
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=3628
Diffstat (limited to 'java/src/IceInternal/Network.java')
-rw-r--r-- | java/src/IceInternal/Network.java | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/java/src/IceInternal/Network.java b/java/src/IceInternal/Network.java index e7130b41bd4..dc5dbb2b6a9 100644 --- a/java/src/IceInternal/Network.java +++ b/java/src/IceInternal/Network.java @@ -811,9 +811,7 @@ public final class Network // } - if(addr == null || - (addr instanceof java.net.Inet4Address && protocol == EnableIPv6) || - (addr instanceof java.net.Inet6Address && protocol == EnableIPv4)) + if(isValidAddr(addr, protocol)) { // // Iterate over the network interfaces and pick an IP @@ -824,9 +822,7 @@ public final class Network while(addr == null && iter.hasNext()) { java.net.InetAddress a = iter.next(); - if(protocol == EnableBoth || - (protocol == EnableIPv4 && a instanceof java.net.Inet4Address) || - (protocol == EnableIPv6 && a instanceof java.net.Inet6Address)) + if(protocol == EnableBoth || isValidAddr(a, protocol)) { addr = a; } @@ -861,9 +857,7 @@ public final class Network for(int i = 0; i < addrs.length; ++i) { - if(protocol == EnableBoth || - (protocol == EnableIPv4 && addrs[i] instanceof java.net.Inet4Address) || - (protocol == EnableIPv6 && addrs[i] instanceof java.net.Inet6Address)) + if(protocol == EnableBoth || isValidAddr(addrs[i], protocol)) { addresses.add(new java.net.InetSocketAddress(addrs[i], port)); } @@ -912,9 +906,7 @@ public final class Network java.net.InetAddress addr = addrs.nextElement(); if(!addr.isLoopbackAddress()) { - if(protocol == EnableBoth || - (protocol == EnableIPv4 && addr instanceof java.net.Inet4Address) || - (protocol == EnableIPv6 && addr instanceof java.net.Inet6Address)) + if(protocol == EnableBoth || isValidAddr(addr, protocol)) { result.add(addr); } @@ -1189,6 +1181,20 @@ public final class Network ex.getMessage().indexOf("A system call received an interrupt") >= 0; // AIX JDK 1.4.2 } + private static boolean + isValidAddr(java.net.InetAddress addr, int protocol) + { + byte[] bytes = null; + if(addr != null) + { + bytes = addr.getAddress(); + } + return bytes != null && + ((bytes.length == 16 && protocol == EnableIPv6) || + (bytes.length == 4 && protocol == EnableIPv4)); + } + + private static java.net.InetSocketAddress getAddressImpl(String host, int port, int protocol, boolean server) { @@ -1213,9 +1219,7 @@ public final class Network for(int i = 0; i < addrs.length; ++i) { - if(protocol == EnableBoth || - (protocol == EnableIPv4 && addrs[i] instanceof java.net.Inet4Address) || - (protocol == EnableIPv6 && addrs[i] instanceof java.net.Inet6Address)) + if(protocol == EnableBoth || isValidAddr(addrs[i], protocol)) { return new java.net.InetSocketAddress(addrs[i], port); } |