6628569: api/java_net/MulticastSocket/descriptions.html#setTTL fails is ipv6 configured
Summary: failover to IPv6 socket if IPv4 fails
Reviewed-by: michaelm
--- a/jdk/src/solaris/native/java/net/NetworkInterface.c Thu Jun 12 17:26:47 2008 +0100
+++ b/jdk/src/solaris/native/java/net/NetworkInterface.c Thu Jun 12 17:28:08 2008 +0100
@@ -1117,9 +1117,33 @@
if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) >= 0) {
ret = if2.ifr_flags;
} 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",
"IOCTL failed");
- ret = -1;
+#endif
}
close(sock);
/* release the UTF string and interface list */
@@ -1484,8 +1508,23 @@
if (ioctl(sock, SIOCGLIFMTU, (caddr_t)&lifr) >= 0) {
ret = lifr.lifr_mtu;
} else {
- NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
- "IOCTL failed");
+ /* Try wIth an IPv6 socket in case the interface has only IPv6 addresses assigned to it */
+ 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
close(sock);