提交 de8b59ab 编写于 作者: C chegar

6628569: api/java_net/MulticastSocket/descriptions.html#setTTL fails is ipv6 configured

Summary: failover to IPv6 socket if IPv4 fails
Reviewed-by: michaelm
上级 3421a727
...@@ -1117,9 +1117,33 @@ static short getFlags(JNIEnv *env, jstring name) { ...@@ -1117,9 +1117,33 @@ static short getFlags(JNIEnv *env, jstring name) {
if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) >= 0) { if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) >= 0) {
ret = if2.ifr_flags; ret = if2.ifr_flags;
} else { } else {
#if defined(__solaris__) && defined(AF_INET6)
/* Try with an IPv6 socket in case the interface has only IPv6 addresses assigned to it */
struct lifreq lifr;
close(sock);
sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0);
if (sock < 0) {
(*env)->ReleaseStringUTFChars(env, name, name_utf);
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"Socket creation failed");
return -1;
}
memset((caddr_t)&lifr, 0, sizeof(lifr));
strcpy((caddr_t)&(lifr.lifr_name), name_utf);
if (ioctl(sock, SIOCGLIFFLAGS, (char *)&lifr) >= 0) {
ret = lifr.lifr_flags;
} else {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"IOCTL failed");
}
#else
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"IOCTL failed"); "IOCTL failed");
ret = -1; #endif
} }
close(sock); close(sock);
/* release the UTF string and interface list */ /* release the UTF string and interface list */
...@@ -1484,8 +1508,23 @@ JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0(JNIEnv *env, jclas ...@@ -1484,8 +1508,23 @@ JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0(JNIEnv *env, jclas
if (ioctl(sock, SIOCGLIFMTU, (caddr_t)&lifr) >= 0) { if (ioctl(sock, SIOCGLIFMTU, (caddr_t)&lifr) >= 0) {
ret = lifr.lifr_mtu; ret = lifr.lifr_mtu;
} else { } else {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", /* Try wIth an IPv6 socket in case the interface has only IPv6 addresses assigned to it */
"IOCTL failed"); close(sock);
sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0);
if (sock < 0) {
(*env)->ReleaseStringUTFChars(env, name, name_utf);
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"Socket creation failed");
return -1;
}
if (ioctl(sock, SIOCGLIFMTU, (caddr_t)&lifr) >= 0) {
ret = lifr.lifr_mtu;
} else {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"IOCTL failed");
}
} }
#endif #endif
close(sock); close(sock);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册