jdk/src/share/classes/java/net/MulticastSocket.java
changeset 12047 320a714614e9
parent 10596 39b3a979e600
child 14342 8435a30053c1
--- a/jdk/src/share/classes/java/net/MulticastSocket.java	Tue Mar 06 10:25:45 2012 +0800
+++ b/jdk/src/share/classes/java/net/MulticastSocket.java	Tue Mar 06 20:34:38 2012 +0000
@@ -81,6 +81,13 @@
  */
 public
 class MulticastSocket extends DatagramSocket {
+
+    /**
+     * Used on some platforms to record if an outgoing interface
+     * has been set for this socket.
+     */
+    private boolean interfaceSet;
+
     /**
      * Create a multicast socket.
      *
@@ -303,6 +310,16 @@
             throw new SocketException("Not a multicast address");
         }
 
+        /**
+         * required for some platforms where it's not possible to join
+         * a group without setting the interface first.
+         */
+        NetworkInterface defaultInterface = NetworkInterface.getDefault();
+
+        if (!interfaceSet && defaultInterface != null) {
+            setNetworkInterface(defaultInterface);
+        }
+
         getImpl().join(mcastaddr);
     }
 
@@ -453,6 +470,7 @@
         synchronized (infLock) {
             getImpl().setOption(SocketOptions.IP_MULTICAST_IF, inf);
             infAddress = inf;
+            interfaceSet = true;
         }
     }
 
@@ -535,6 +553,7 @@
         synchronized (infLock) {
             getImpl().setOption(SocketOptions.IP_MULTICAST_IF2, netIf);
             infAddress = null;
+            interfaceSet = true;
         }
     }