changeset 894:f8a9a7aff362

6800805: java.net.NetworkInterface.getNetworkInterfaces() does not list IPv6 network interfaces correctly Reviewed-by: jccollet
author chegar
date Mon, 16 Feb 2009 17:19:05 +0000
parents f06f30b29f36
children 1109646be6f6 a144afafb6fe
files src/solaris/native/java/net/NetworkInterface.c
diffstat 1 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/native/java/net/NetworkInterface.c	Sun Feb 15 12:25:54 2009 +0000
+++ b/src/solaris/native/java/net/NetworkInterface.c	Mon Feb 16 17:19:05 2009 +0000
@@ -969,13 +969,39 @@
            // Got access to parent, so create it if necessary.
            strcpy(vname, name);
            *unit = '\0';
-        }
-        else {
+        } else {
+#if defined(__solaris__) && defined(AF_INET6)
+          struct   lifreq lifr;
+          memset((char *) &lifr, 0, sizeof(lifr));
+          strcpy(lifr.lifr_name, vname);
+
+          /* 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) {
+            NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
+                                         "Socket creation failed");
+            return ifs; /* return untouched list */
+          }
+
+          if (ioctl(sock, SIOCGLIFFLAGS, (char *)&lifr) >= 0) {
+            // Got access to parent, so create it if necessary.
+            strcpy(vname, name);
+            *unit = '\0';
+          } else {
+            // failed to access parent interface do not create parent.
+            // We are a virtual interface with no parent.
+            isVirtual = 1;
+            vname[0] = 0;
+          }
+#else
           // failed to access parent interface do not create parent.
           // We are a virtual interface with no parent.
           isVirtual = 1;
-
           vname[0] = 0;
+#endif
         }
       }
       close(sock);