< prev index next >

src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c

Print this page

        

*** 77,86 **** --- 77,90 ---- static jfieldID pdsi_localPortID; static jfieldID pdsi_connected; static jfieldID pdsi_connectedAddress; static jfieldID pdsi_connectedPort; + extern void setDefaultScopeID(JNIEnv *env, struct sockaddr *him); + extern int getDefaultScopeID(JNIEnv *env); + + /* * Returns a java.lang.Integer based on 'i' */ static jobject createInteger(JNIEnv *env, int i) { static jclass i_class;
*** 194,203 **** --- 198,208 ---- /* bind */ if (NET_InetAddressToSockaddr(env, iaObj, localport, &sa, &len, JNI_TRUE) != 0) { return; } + setDefaultScopeID(env, &sa.sa); if (NET_Bind(fd, &sa, len) < 0) { if (errno == EADDRINUSE || errno == EADDRNOTAVAIL || errno == EPERM || errno == EACCES) { NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "BindException",
*** 259,268 **** --- 264,275 ---- if (NET_InetAddressToSockaddr(env, address, port, &rmtaddr, &len, JNI_TRUE) != 0) { return; } + setDefaultScopeID(env, &rmtaddr.sa); + if (NET_Connect(fd, &rmtaddr.sa, len) == -1) { NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException", "Connect failed"); } }
*** 325,339 **** #endif } /* * Class: java_net_PlainDatagramSocketImpl ! * Method: send0 * Signature: (Ljava/net/DatagramPacket;)V */ JNIEXPORT void JNICALL ! Java_java_net_PlainDatagramSocketImpl_send0(JNIEnv *env, jobject this, jobject packet) { char BUF[MAX_BUFFER_LEN]; char *fullPacket = NULL; int ret, mallocedPacket = JNI_FALSE; --- 332,346 ---- #endif } /* * Class: java_net_PlainDatagramSocketImpl ! * Method: send * Signature: (Ljava/net/DatagramPacket;)V */ JNIEXPORT void JNICALL ! Java_java_net_PlainDatagramSocketImpl_send(JNIEnv *env, jobject this, jobject packet) { char BUF[MAX_BUFFER_LEN]; char *fullPacket = NULL; int ret, mallocedPacket = JNI_FALSE;
*** 384,393 **** --- 391,401 ---- &len, JNI_TRUE) != 0) { return; } rmtaddrP = &rmtaddr.sa; } + setDefaultScopeID(env, &rmtaddr.sa); if (packetBufferLen > MAX_BUFFER_LEN) { /* When JNI-ifying the JDK's IO routines, we turned * reads and writes of byte arrays of size greater * than 2048 bytes into several operations of size 2048.
*** 2135,2144 **** --- 2143,2172 ---- if (getsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, (char*)&index, &len) < 0) { NET_ThrowCurrent(env, "getsockopt IPV6_MULTICAST_IF failed"); return; } + + #ifdef __linux__ + /* + * On 2.4.8+ if we join a group with the interface set to 0 + * then the kernel records the interface it decides. This causes + * subsequent leave groups to fail as there is no match. Thus we + * pick the interface if there is a matching route. + */ + if (index == 0) { + int rt_index = getDefaultIPv6Interface(&(mname6.ipv6mr_multiaddr)); + if (rt_index > 0) { + index = rt_index; + } + } + #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); mname6.ipv6mr_interface = idx; }
< prev index next >