diff options
author | Robert Schuster <theBohemian@gmx.net> | 2006-10-25 00:45:41 +0000 |
---|---|---|
committer | Robert Schuster <theBohemian@gmx.net> | 2006-10-25 00:45:41 +0000 |
commit | f0f853595a72032793c070bd3b63f234465a999e (patch) | |
tree | 2b323cb1b039bc90e67167353c5e5be9bff0807e | |
parent | c885b93b58ddda402c067ae7f617091cb6e2df15 (diff) | |
download | classpath-f0f853595a72032793c070bd3b63f234465a999e.tar.gz |
2006-10-25 Robert Schuster <robertschuster@fsfe.org>
* java/net/MulticastSocket.java:
(setNetworkInterface): Rewritten.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | java/net/MulticastSocket.java | 42 |
2 files changed, 40 insertions, 7 deletions
@@ -1,5 +1,10 @@ 2006-10-25 Robert Schuster <robertschuster@fsfe.org> + * java/net/MulticastSocket.java: + (setNetworkInterface): Rewritten. + +2006-10-25 Robert Schuster <robertschuster@fsfe.org> + * native/jni/java-net/javanet.h: Added declaration for _javanet_create_inetaddress. * native/jni/java-net/javanet.c: diff --git a/java/net/MulticastSocket.java b/java/net/MulticastSocket.java index 389b6908e..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); } |