7144274: [macosx] Default IPv6 multicast interface is not being set when calling MulticastSocket.joinGroup()
Summary: Get default interface for Mac OS X when interface is not set
Reviewed-by: chegar
--- a/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c Tue Apr 24 10:37:01 2012 -0700
+++ b/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c Tue Apr 24 14:59:45 2012 -0700
@@ -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/jdk/src/solaris/native/java/net/net_util_md.c Tue Apr 24 10:37:01 2012 -0700
+++ b/jdk/src/solaris/native/java/net/net_util_md.c Tue Apr 24 14:59:45 2012 -0700
@@ -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;