From ac3a2185ab872a1a7d77d9723eb87672711cf86e Mon Sep 17 00:00:00 2001 From: khazra Date: Tue, 24 Apr 2012 14:59:45 -0700 Subject: [PATCH] 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 --- .../native/java/net/PlainDatagramSocketImpl.c | 7 ++++++- src/solaris/native/java/net/net_util_md.c | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/solaris/native/java/net/PlainDatagramSocketImpl.c b/src/solaris/native/java/net/PlainDatagramSocketImpl.c index cbdacdf6b..382ec4c83 100644 --- a/src/solaris/native/java/net/PlainDatagramSocketImpl.c +++ b/src/solaris/native/java/net/PlainDatagramSocketImpl.c @@ -84,6 +84,7 @@ static jfieldID pdsi_ttlID; #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 @@ static void mcast_join_leave(JNIEnv *env, jobject this, } } #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); diff --git a/src/solaris/native/java/net/net_util_md.c b/src/solaris/native/java/net/net_util_md.c index f7e6d6a02..ccbe4b15a 100644 --- a/src/solaris/native/java/net/net_util_md.c +++ b/src/solaris/native/java/net/net_util_md.c @@ -109,6 +109,24 @@ void setDefaultScopeID(JNIEnv *env, struct sockaddr *him) #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; -- GitLab