diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-10-29 22:49:21 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-10-29 22:49:21 +0000 |
commit | e36d2a50b5a1a677c7ecaf926e73a5dac386c1ef (patch) | |
tree | 9649a7997f35624c829eccad8c84c84e9c8e3fb9 /java/net/MulticastSocket.java | |
parent | be24db70d4ff66302f560e12913f5b71acf3c12c (diff) | |
download | classpath-e36d2a50b5a1a677c7ecaf926e73a5dac386c1ef.tar.gz |
2006-10-29 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD --> generics for 2006/10/04-2006/10/29.
Diffstat (limited to 'java/net/MulticastSocket.java')
-rw-r--r-- | java/net/MulticastSocket.java | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/java/net/MulticastSocket.java b/java/net/MulticastSocket.java index 03bdf1e77..2841192db 100644 --- a/java/net/MulticastSocket.java +++ b/java/net/MulticastSocket.java @@ -202,13 +202,41 @@ public class MulticastSocket extends DatagramSocket { if (isClosed()) throw new SocketException("socket is closed"); - - Enumeration e = netIf.getInetAddresses(); - - if (! e.hasMoreElements()) - throw new SocketException("no network devices found"); - - InetAddress address = (InetAddress) e.nextElement(); + + InetAddress address; + if (netIf != null) + out: + { + Enumeration e = netIf.getInetAddresses(); + if (getLocalAddress() instanceof Inet4Address) + { + // Search for a IPv4 address. + while (e.hasMoreElements()) + { + address = (InetAddress) e.nextElement(); + if (address instanceof Inet4Address) + break out; + } + throw new SocketException("interface " + netIf.getName() + " has no IPv6 address"); + } + else if (getLocalAddress() instanceof Inet6Address) + { + // Search for a IPv6 address. + while (e.hasMoreElements()) + { + address = (InetAddress) e.nextElement(); + if (address instanceof Inet6Address) + break out; + } + throw new SocketException("interface " + netIf.getName() + " has no IPv6 address"); + } + else + throw new SocketException("interface " + netIf.getName() + " has no suitable IP address"); + } + else + address = InetAddress.ANY_IF; + + getImpl().setOption(SocketOptions.IP_MULTICAST_IF, address); } @@ -230,6 +258,10 @@ public class MulticastSocket extends DatagramSocket InetAddress address = (InetAddress) getImpl().getOption(SocketOptions.IP_MULTICAST_IF); + + if (address.isAnyLocalAddress()) + return NetworkInterface.createAnyInterface(); + NetworkInterface netIf = NetworkInterface.getByInetAddress(address); return netIf; |