changeset 51827:78f16a9f7563

8196224: Even better Internet address support Reviewed-by: chegar, rriggs, rhalade, vtewari
author igerasim
date Mon, 05 Feb 2018 14:18:22 -0800
parents edd69f959190
children 393f8a42190b
files src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c
diffstat 2 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c	Wed Jan 31 18:13:13 2018 -0800
+++ b/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c	Mon Feb 05 14:18:22 2018 -0800
@@ -1017,6 +1017,7 @@
     struct in_addr in;
     jobjectArray addrArray;
     jsize len;
+    jint family;
     jobject addr;
     int i;
 
@@ -1047,8 +1048,9 @@
     in.s_addr = 0;
     for (i = 0; i < len; i++) {
         addr = (*env)->GetObjectArrayElement(env, addrArray, i);
-        if (getInetAddress_family(env, addr) == java_net_InetAddress_IPv4) {
-            JNU_CHECK_EXCEPTION(env);
+        family = getInetAddress_family(env, addr);
+        JNU_CHECK_EXCEPTION(env);
+        if (family == java_net_InetAddress_IPv4) {
             in.s_addr = htonl(getInetAddress_addr(env, addr));
             JNU_CHECK_EXCEPTION(env);
             break;
@@ -1896,6 +1898,7 @@
 
     jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
     jint fd;
+    jint family;
     jint ipv6_join_leave;
 
     if (IS_NULL(fdObj)) {
@@ -1916,8 +1919,9 @@
     ipv6_join_leave = ipv6_available();
 
 #ifdef __linux__
-    if (getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4) {
-        JNU_CHECK_EXCEPTION(env);
+    family = getInetAddress_family(env, iaObj);
+    JNU_CHECK_EXCEPTION(env);
+    if (family == java_net_InetAddress_IPv4) {
         ipv6_join_leave = JNI_FALSE;
     }
 #endif
--- a/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c	Wed Jan 31 18:13:13 2018 -0800
+++ b/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c	Mon Feb 05 14:18:22 2018 -0800
@@ -219,16 +219,16 @@
     jobject fd1Obj = (*env)->GetObjectField(env, this, pdsi_fd1ID);
     int ipv6_supported = ipv6_available();
     int fd, fd1 = -1, lcladdrlen = 0;
+    jint family;
     SOCKETADDRESS lcladdr;
 
-    if (getInetAddress_family(env, addressObj) == java_net_InetAddress_IPv6 &&
-        !ipv6_supported)
-    {
+    family = getInetAddress_family(env, addressObj);
+    JNU_CHECK_EXCEPTION(env);
+    if (family == java_net_InetAddress_IPv6 && !ipv6_supported) {
         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
                         "Protocol family not supported");
         return;
     }
-    JNU_CHECK_EXCEPTION(env);
     if (IS_NULL(fdObj) || (ipv6_supported && IS_NULL(fd1Obj))) {
         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed");
         return;