changeset 5063:99cc5c9ef200

7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup() Reviewed-by: chegar, alanb
author khazra
date Wed, 15 Feb 2012 15:49:38 +0000
parents 9bae15c55008
children b9a3fba363ec 5a9df5a77384
files src/solaris/native/java/net/PlainDatagramSocketImpl.c src/solaris/native/java/net/net_util_md.c
diffstat 2 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/native/java/net/PlainDatagramSocketImpl.c	Wed Feb 15 19:25:56 2012 +0400
+++ b/src/solaris/native/java/net/PlainDatagramSocketImpl.c	Wed Feb 15 15:49:38 2012 +0000
@@ -84,6 +84,7 @@
 #endif
 
 extern void setDefaultScopeID(JNIEnv *env, struct sockaddr *him);
+extern int getDefaultScopeID(JNIEnv *env);
 
 /*
  * Returns a java.lang.Integer based on 'i'
@@ -2418,7 +2419,11 @@
                 }
             }
 #endif
-
+#ifdef MACOSX
+            if (family == AF_INET6 && index == 0) {
+                index = getDefaultScopeID(env);
+            }
+#endif
             mname6.ipv6mr_interface = index;
         } else {
             jint idx = (*env)->GetIntField(env, niObj, ni_indexID);
--- a/src/solaris/native/java/net/net_util_md.c	Wed Feb 15 19:25:56 2012 +0400
+++ b/src/solaris/native/java/net/net_util_md.c	Wed Feb 15 15:49:38 2012 +0000
@@ -109,6 +109,24 @@
 #endif
 }
 
+int getDefaultScopeID(JNIEnv *env) {
+    static jclass ni_class = NULL;
+    static jfieldID ni_defaultIndexID;
+    if (ni_class == NULL) {
+        jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
+        CHECK_NULL(c);
+        c = (*env)->NewGlobalRef(env, c);
+        CHECK_NULL(c);
+        ni_defaultIndexID = (*env)->GetStaticFieldID(
+            env, c, "defaultIndex", "I");
+        ni_class = c;
+    }
+    int defaultIndex = 0;
+    defaultIndex = (*env)->GetStaticIntField(env, ni_class,
+                                                 ni_defaultIndexID);
+    return defaultIndex;
+}
+
 #ifdef __solaris__
 static int init_tcp_max_buf, init_udp_max_buf;
 static int tcp_max_buf;