8167295: Further cleanup to the native parts of libnet/libnio
authorclanger
Mon, 10 Oct 2016 22:42:45 +0200
changeset 41380 c27cf95dd7e6
parent 41379 509c0e9a6b47
child 41381 3e7e2ee8ba73
child 41412 4d1d88a4f815
8167295: Further cleanup to the native parts of libnet/libnio Reviewed-by: chegar
jdk/make/mapfiles/libnet/mapfile-vers
jdk/src/java.base/share/native/libnet/net_util.h
jdk/src/java.base/unix/native/libnet/Inet4AddressImpl.c
jdk/src/java.base/unix/native/libnet/Inet6AddressImpl.c
jdk/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c
jdk/src/java.base/unix/native/libnet/PlainSocketImpl.c
jdk/src/java.base/unix/native/libnet/net_util_md.c
jdk/src/java.base/unix/native/libnet/net_util_md.h
jdk/src/java.base/unix/native/libnio/ch/DatagramChannelImpl.c
jdk/src/java.base/unix/native/libnio/ch/InheritedChannel.c
jdk/src/java.base/unix/native/libnio/ch/Net.c
jdk/src/java.base/unix/native/libnio/ch/ServerSocketChannelImpl.c
jdk/src/java.base/windows/native/libnet/Inet6AddressImpl.c
jdk/src/java.base/windows/native/libnet/NetworkInterface.c
jdk/src/java.base/windows/native/libnet/NetworkInterface_winXP.c
jdk/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c
jdk/src/java.base/windows/native/libnet/TwoStacksPlainSocketImpl.c
jdk/src/java.base/windows/native/libnet/net_util_md.c
jdk/src/java.base/windows/native/libnet/net_util_md.h
jdk/src/jdk.sctp/unix/native/libsctp/SctpChannelImpl.c
jdk/src/jdk.sctp/unix/native/libsctp/SctpNet.c
--- a/jdk/make/mapfiles/libnet/mapfile-vers	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/make/mapfiles/libnet/mapfile-vers	Mon Oct 10 22:42:45 2016 +0200
@@ -98,7 +98,6 @@
 		Java_sun_net_sdp_SdpSupport_create0;
 		Java_sun_net_spi_DefaultProxySelector_init;
 		Java_sun_net_spi_DefaultProxySelector_getSystemProxy;
-		NET_AllocSockaddr;
 		NET_SockaddrToInetAddress;
                 NET_SockaddrEqualsInetAddress;
 		NET_InetAddressToSockaddr;
--- a/jdk/src/java.base/share/native/libnet/net_util.h	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/share/native/libnet/net_util.h	Mon Oct 10 22:42:45 2016 +0200
@@ -42,6 +42,10 @@
 #define NET_ERROR(env, ex, msg) \
 { if (!(*env)->ExceptionOccurred(env)) JNU_ThrowByName(env, ex, msg); }
 
+#define NET_WAIT_READ    0x01
+#define NET_WAIT_WRITE   0x02
+#define NET_WAIT_CONNECT 0x04
+
 /************************************************************************
  * Cached field IDs
  *
@@ -133,9 +137,6 @@
 
 JNIEXPORT jint JNICALL reuseport_available() ;
 
-void
-NET_AllocSockaddr(struct sockaddr **him, int *len);
-
 JNIEXPORT int JNICALL
 NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr *him, int *len, jboolean v4MappedAddress);
 
@@ -196,4 +197,6 @@
 
 unsigned short in_cksum(unsigned short *addr, int len);
 
+jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);
+
 #endif /* NET_UTILS_H */
--- a/jdk/src/java.base/unix/native/libnet/Inet4AddressImpl.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/unix/native/libnet/Inet4AddressImpl.c	Mon Oct 10 22:42:45 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -788,9 +788,9 @@
         case ENETUNREACH: /* Network Unreachable */
         case EAFNOSUPPORT: /* Address Family not supported */
         case EADDRNOTAVAIL: /* address is not available on  the  remote machine */
-#ifdef __linux__
+#if defined(__linux__) || defined(_AIX)
         case EINVAL:
-        case EHOSTUNREACH:
+        case EHOSTUNREACH: /* No route to host */
           /*
            * On some Linux versions, when a socket is bound to the loopback
            * interface, connect will fail and errno will be set to EINVAL
--- a/jdk/src/java.base/unix/native/libnet/Inet6AddressImpl.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/unix/native/libnet/Inet6AddressImpl.c	Mon Oct 10 22:42:45 2016 +0200
@@ -775,9 +775,9 @@
         case ENETUNREACH: /* Network Unreachable */
         case EAFNOSUPPORT: /* Address Family not supported */
         case EADDRNOTAVAIL: /* address is not available on  the  remote machine */
-#ifdef __linux__
+#if defined(__linux__) || defined(_AIX)
         case EINVAL:
-        case EHOSTUNREACH:
+        case EHOSTUNREACH: /* No route to host */
           /*
            * On some Linux versions, when  a socket is bound to the
            * loopback interface, connect will fail and errno will
@@ -804,7 +804,7 @@
                          &optlen) <0) {
             connect_rv = errno;
           }
-          if (connect_rv == 0 || ECONNREFUSED) {
+          if (connect_rv == 0 || connect_rv == ECONNREFUSED) {
             close(fd);
             return JNI_TRUE;
           }
--- a/jdk/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c	Mon Oct 10 22:42:45 2016 +0200
@@ -193,8 +193,8 @@
     /* fd is an int field on fdObj */
     int fd;
     int len = 0;
-    SOCKADDR him;
-    socklen_t slen = sizeof(him);
+    SOCKETADDRESS him;
+    socklen_t slen = sizeof(SOCKETADDRESS);
 
     if (IS_NULL(fdObj)) {
         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
@@ -210,12 +210,12 @@
     }
 
     /* bind */
-    if (NET_InetAddressToSockaddr(env, iaObj, localport, (struct sockaddr *)&him, &len, JNI_TRUE) != 0) {
+    if (NET_InetAddressToSockaddr(env, iaObj, localport, &him.sa, &len, JNI_TRUE) != 0) {
       return;
     }
-    setDefaultScopeID(env, (struct sockaddr *)&him);
+    setDefaultScopeID(env, &him.sa);
 
-    if (NET_Bind(fd, (struct sockaddr *)&him, len) < 0)  {
+    if (NET_Bind(fd, &him.sa, len) < 0)  {
         if (errno == EADDRINUSE || errno == EADDRNOTAVAIL ||
             errno == EPERM || errno == EACCES) {
             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "BindException",
@@ -232,13 +232,13 @@
         /* Now that we're a connected socket, let's extract the port number
          * that the system chose for us and store it in the Socket object.
          */
-        if (getsockname(fd, (struct sockaddr *)&him, &slen) == -1) {
+        if (getsockname(fd, &him.sa, &slen) == -1) {
             JNU_ThrowByNameWithMessageAndLastError
                 (env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
             return;
         }
 
-        localport = NET_GetPortFromSockaddr((struct sockaddr *)&him);
+        localport = NET_GetPortFromSockaddr(&him.sa);
 
         (*env)->SetIntField(env, this, pdsi_localPortID, localport);
     } else {
@@ -259,7 +259,7 @@
     /* The fdObj'fd */
     jint fd;
     /* The packetAddress address, family and port */
-    SOCKADDR rmtaddr;
+    SOCKETADDRESS rmtaddr;
     int len = 0;
 
     if (IS_NULL(fdObj)) {
@@ -274,18 +274,16 @@
         return;
     }
 
-    if (NET_InetAddressToSockaddr(env, address, port, (struct sockaddr *)&rmtaddr, &len, JNI_TRUE) != 0) {
+    if (NET_InetAddressToSockaddr(env, address, port, &rmtaddr.sa, &len, JNI_TRUE) != 0) {
       return;
     }
 
-    setDefaultScopeID(env, (struct sockaddr *)&rmtaddr);
+    setDefaultScopeID(env, &rmtaddr.sa);
 
-    if (NET_Connect(fd, (struct sockaddr *)&rmtaddr, len) == -1) {
+    if (NET_Connect(fd, &rmtaddr.sa, len) == -1) {
         NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
                         "Connect failed");
-        return;
     }
-
 }
 
 /*
@@ -301,7 +299,7 @@
     jint fd;
 
 #if defined(__linux__) || defined(_ALLBSD_SOURCE)
-    SOCKADDR addr;
+    SOCKETADDRESS addr;
     socklen_t len;
 #endif
 
@@ -314,36 +312,34 @@
         memset(&addr, 0, sizeof(addr));
 #ifdef AF_INET6
         if (ipv6_available()) {
-            struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)&addr;
-            him6->sin6_family = AF_UNSPEC;
+            addr.sa6.sin6_family = AF_UNSPEC;
             len = sizeof(struct sockaddr_in6);
         } else
 #endif
         {
-            struct sockaddr_in *him4 = (struct sockaddr_in*)&addr;
-            him4->sin_family = AF_UNSPEC;
+            addr.sa4.sin_family = AF_UNSPEC;
             len = sizeof(struct sockaddr_in);
         }
-        NET_Connect(fd, (struct sockaddr *)&addr, len);
+        NET_Connect(fd, &addr.sa, len);
 
 #ifdef __linux__
         int localPort = 0;
-        if (getsockname(fd, (struct sockaddr *)&addr, &len) == -1)
+        if (getsockname(fd, &addr.sa, &len) == -1)
             return;
 
-        localPort = NET_GetPortFromSockaddr((struct sockaddr *)&addr);
+        localPort = NET_GetPortFromSockaddr(&addr.sa);
         if (localPort == 0) {
             localPort = (*env)->GetIntField(env, this, pdsi_localPortID);
 #ifdef AF_INET6
-            if (((struct sockaddr*)&addr)->sa_family == AF_INET6) {
-                ((struct sockaddr_in6*)&addr)->sin6_port = htons(localPort);
+            if (addr.sa.sa_family == AF_INET6) {
+                addr.sa6.sin6_port = htons(localPort);
             } else
 #endif /* AF_INET6 */
             {
-                ((struct sockaddr_in*)&addr)->sin_port = htons(localPort);
+                addr.sa4.sin_port = htons(localPort);
             }
 
-            NET_Bind(fd, (struct sockaddr *)&addr, len);
+            NET_Bind(fd, &addr.sa, len);
         }
 
 #endif
@@ -376,7 +372,7 @@
     /* The fdObj'fd */
     jint fd;
 
-    SOCKADDR rmtaddr, *rmtaddrP=&rmtaddr;
+    SOCKETADDRESS rmtaddr, *rmtaddrP = &rmtaddr;
     int len;
 
     if (IS_NULL(fdObj)) {
@@ -409,11 +405,11 @@
         rmtaddrP = 0;
     } else {
         packetPort = (*env)->GetIntField(env, packet, dp_portID);
-        if (NET_InetAddressToSockaddr(env, packetAddress, packetPort, (struct sockaddr *)&rmtaddr, &len, JNI_TRUE) != 0) {
-          return;
+        if (NET_InetAddressToSockaddr(env, packetAddress, packetPort, &rmtaddr.sa, &len, JNI_TRUE) != 0) {
+            return;
         }
     }
-    setDefaultScopeID(env, (struct sockaddr *)&rmtaddr);
+    setDefaultScopeID(env, &rmtaddr.sa);
 
     if (packetBufferLen > MAX_BUFFER_LEN) {
         /* When JNI-ifying the JDK's IO routines, we turned
@@ -449,7 +445,7 @@
                                (jbyte *)fullPacket);
 #ifdef AF_INET6
     if (trafficClass != 0 && ipv6_available()) {
-        NET_SetTrafficClass((struct sockaddr *)&rmtaddr, trafficClass);
+        NET_SetTrafficClass(&rmtaddr.sa, trafficClass);
     }
 #endif /* AF_INET6 */
 
@@ -492,8 +488,8 @@
     jint timeout = (*env)->GetIntField(env, this, pdsi_timeoutID);
     jint fd;
     ssize_t n;
-    SOCKADDR remote_addr;
-    socklen_t slen = SOCKADDR_LEN;
+    SOCKETADDRESS rmtaddr;
+    socklen_t slen = sizeof(SOCKETADDRESS);
     char buf[1];
     jint family;
     jobject iaObj;
@@ -527,7 +523,7 @@
         }
     }
 
-    n = NET_RecvFrom(fd, buf, 1, MSG_PEEK, (struct sockaddr *)&remote_addr, &slen);
+    n = NET_RecvFrom(fd, buf, 1, MSG_PEEK, &rmtaddr.sa, &slen);
 
     if (n == -1) {
 
@@ -552,7 +548,7 @@
         return 0;
     }
 
-    iaObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&remote_addr, &port);
+    iaObj = NET_SockaddrToInetAddress(env, &rmtaddr.sa, &port);
 #ifdef AF_INET6
     family = getInetAddress_family(env, iaObj) == IPv4? AF_INET : AF_INET6;
 #else
@@ -574,16 +570,13 @@
     int mallocedPacket = JNI_FALSE;
     jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
     jint timeout = (*env)->GetIntField(env, this, pdsi_timeoutID);
-
     jbyteArray packetBuffer;
     jint packetBufferOffset, packetBufferLen;
-
     int fd;
-
     int n;
-    SOCKADDR remote_addr;
-    socklen_t slen = SOCKADDR_LEN;
-    int port;
+    SOCKETADDRESS rmtaddr;
+    socklen_t slen = sizeof(SOCKETADDRESS);
+    int port = -1;
 
     if (IS_NULL(fdObj)) {
         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
@@ -661,7 +654,7 @@
     }
 
     n = NET_RecvFrom(fd, fullPacket, packetBufferLen, MSG_PEEK,
-                     (struct sockaddr *)&remote_addr, &slen);
+                     &rmtaddr.sa, &slen);
     /* truncate the data if the packet's length is too small */
     if (n > packetBufferLen) {
         n = packetBufferLen;
@@ -706,18 +699,18 @@
          */
         packetAddress = (*env)->GetObjectField(env, packet, dp_addressID);
         if (packetAddress != NULL) {
-            if (!NET_SockaddrEqualsInetAddress(env, (struct sockaddr *)&remote_addr, packetAddress)) {
+            if (!NET_SockaddrEqualsInetAddress(env, &rmtaddr.sa, packetAddress)) {
                 /* force a new InetAddress to be created */
                 packetAddress = NULL;
             }
         }
         if (packetAddress == NULL) {
-            packetAddress = NET_SockaddrToInetAddress(env, (struct sockaddr *)&remote_addr, &port);
+            packetAddress = NET_SockaddrToInetAddress(env, &rmtaddr.sa, &port);
             /* stuff the new Inetaddress in the packet */
             (*env)->SetObjectField(env, packet, dp_addressID, packetAddress);
         } else {
             /* only get the new port number */
-            port = NET_GetPortFromSockaddr((struct sockaddr *)&remote_addr);
+            port = NET_GetPortFromSockaddr(&rmtaddr.sa);
         }
         /* and fill in the data, remote address/port and such */
         (*env)->SetByteArrayRegion(env, packetBuffer, packetBufferOffset, n,
@@ -753,8 +746,8 @@
     int fd;
 
     int n;
-    SOCKADDR remote_addr;
-    socklen_t slen = SOCKADDR_LEN;
+    SOCKETADDRESS rmtaddr;
+    socklen_t slen = sizeof(SOCKETADDRESS);
     jboolean retry;
 #ifdef __linux__
     jboolean connected = JNI_FALSE;
@@ -849,7 +842,7 @@
         }
 
         n = NET_RecvFrom(fd, fullPacket, packetBufferLen, 0,
-                         (struct sockaddr *)&remote_addr, &slen);
+                         &rmtaddr.sa, &slen);
         /* truncate the data if the packet's length is too small */
         if (n > packetBufferLen) {
             n = packetBufferLen;
@@ -887,18 +880,18 @@
              */
             packetAddress = (*env)->GetObjectField(env, packet, dp_addressID);
             if (packetAddress != NULL) {
-                if (!NET_SockaddrEqualsInetAddress(env, (struct sockaddr *)&remote_addr, packetAddress)) {
+                if (!NET_SockaddrEqualsInetAddress(env, &rmtaddr.sa, packetAddress)) {
                     /* force a new InetAddress to be created */
                     packetAddress = NULL;
                 }
             }
             if (packetAddress == NULL) {
-                packetAddress = NET_SockaddrToInetAddress(env, (struct sockaddr *)&remote_addr, &port);
+                packetAddress = NET_SockaddrToInetAddress(env, &rmtaddr.sa, &port);
                 /* stuff the new Inetaddress in the packet */
                 (*env)->SetObjectField(env, packet, dp_addressID, packetAddress);
             } else {
                 /* only get the new port number */
-                port = NET_GetPortFromSockaddr((struct sockaddr *)&remote_addr);
+                port = NET_GetPortFromSockaddr(&rmtaddr.sa);
             }
             /* and fill in the data, remote address/port and such */
             (*env)->SetByteArrayRegion(env, packetBuffer, packetBufferOffset, n,
@@ -1729,19 +1722,17 @@
      */
     if (opt == java_net_SocketOptions_SO_BINDADDR) {
         /* find out local IP address */
-        SOCKADDR him;
-        socklen_t len = 0;
+        SOCKETADDRESS him;
+        socklen_t len = sizeof(SOCKETADDRESS);
         int port;
         jobject iaObj;
 
-        len = SOCKADDR_LEN;
-
-        if (getsockname(fd, (struct sockaddr *)&him, &len) == -1) {
+        if (getsockname(fd, &him.sa, &len) == -1) {
             JNU_ThrowByNameWithMessageAndLastError
                 (env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
             return NULL;
         }
-        iaObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&him, &port);
+        iaObj = NET_SockaddrToInetAddress(env, &him.sa, &port);
 
         return iaObj;
     }
--- a/jdk/src/java.base/unix/native/libnet/PlainSocketImpl.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/unix/native/libnet/PlainSocketImpl.c	Mon Oct 10 22:42:45 2016 +0200
@@ -274,7 +274,7 @@
     /* fd is an int field on iaObj */
     jint fd;
 
-    SOCKADDR him;
+    SOCKETADDRESS him;
     /* The result of the connection */
     int connect_rv = -1;
 
@@ -290,18 +290,18 @@
     }
 
     /* connect */
-    if (NET_InetAddressToSockaddr(env, iaObj, port, (struct sockaddr *)&him, &len, JNI_TRUE) != 0) {
-      return;
+    if (NET_InetAddressToSockaddr(env, iaObj, port, &him.sa, &len, JNI_TRUE) != 0) {
+        return;
     }
-    setDefaultScopeID(env, (struct sockaddr *)&him);
+    setDefaultScopeID(env, &him.sa);
 
 #ifdef AF_INET6
     if (trafficClass != 0 && ipv6_available()) {
-        NET_SetTrafficClass((struct sockaddr *)&him, trafficClass);
+        NET_SetTrafficClass(&him.sa, trafficClass);
     }
 #endif /* AF_INET6 */
     if (timeout <= 0) {
-        connect_rv = NET_Connect(fd, (struct sockaddr *)&him, len);
+        connect_rv = NET_Connect(fd, &him.sa, len);
 #ifdef __solaris__
         if (connect_rv == -1 && errno == EINPROGRESS ) {
 
@@ -350,7 +350,7 @@
         SET_NONBLOCKING(fd);
 
         /* no need to use NET_Connect as non-blocking */
-        connect_rv = connect(fd, (struct sockaddr *)&him, len);
+        connect_rv = connect(fd, &him.sa, len);
 
         /* connection not established immediately */
         if (connect_rv != 0) {
@@ -497,12 +497,12 @@
         /* Now that we're a connected socket, let's extract the port number
          * that the system chose for us and store it in the Socket object.
          */
-        socklen_t slen = SOCKADDR_LEN;
-        if (getsockname(fd, (struct sockaddr *)&him, &slen) == -1) {
+        socklen_t slen = sizeof(SOCKETADDRESS);
+        if (getsockname(fd, &him.sa, &slen) == -1) {
             JNU_ThrowByNameWithMessageAndLastError
                 (env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
         } else {
-            localport = NET_GetPortFromSockaddr((struct sockaddr *)&him);
+            localport = NET_GetPortFromSockaddr(&him.sa);
             (*env)->SetIntField(env, this, psi_localportID, localport);
         }
     }
@@ -522,7 +522,7 @@
     /* fd is an int field on fdObj */
     int fd;
     int len;
-    SOCKADDR him;
+    SOCKETADDRESS him;
 
     if (IS_NULL(fdObj)) {
         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
@@ -537,13 +537,13 @@
     }
 
     /* bind */
-    if (NET_InetAddressToSockaddr(env, iaObj, localport, (struct sockaddr *)&him,
+    if (NET_InetAddressToSockaddr(env, iaObj, localport, &him.sa,
                                   &len, JNI_TRUE) != 0) {
         return;
     }
-    setDefaultScopeID(env, (struct sockaddr *)&him);
+    setDefaultScopeID(env, &him.sa);
 
-    if (NET_Bind(fd, (struct sockaddr *)&him, len) < 0) {
+    if (NET_Bind(fd, &him.sa, len) < 0) {
         if (errno == EADDRINUSE || errno == EADDRNOTAVAIL ||
             errno == EPERM || errno == EACCES) {
             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "BindException",
@@ -560,16 +560,16 @@
 
     /* initialize the local port */
     if (localport == 0) {
-        socklen_t slen = sizeof(him);
+        socklen_t slen = sizeof(SOCKETADDRESS);
         /* Now that we're a connected socket, let's extract the port number
          * that the system chose for us and store it in the Socket object.
          */
-        if (getsockname(fd, (struct sockaddr *)&him, &slen) == -1) {
+        if (getsockname(fd, &him.sa, &slen) == -1) {
             JNU_ThrowByNameWithMessageAndLastError
                 (env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
             return;
         }
-        localport = NET_GetPortFromSockaddr((struct sockaddr *)&him);
+        localport = NET_GetPortFromSockaddr(&him.sa);
         (*env)->SetIntField(env, this, psi_localportID, localport);
     } else {
         (*env)->SetIntField(env, this, psi_localportID, localport);
@@ -637,8 +637,8 @@
     /* accepted fd */
     jint newfd;
 
-    SOCKADDR him;
-    socklen_t slen = SOCKADDR_LEN;
+    SOCKETADDRESS him;
+    socklen_t slen = sizeof(SOCKETADDRESS);
 
     if (IS_NULL(fdObj)) {
         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
@@ -692,7 +692,7 @@
             return;
         }
 
-        newfd = NET_Accept(fd, (struct sockaddr *)&him, &slen);
+        newfd = NET_Accept(fd, &him.sa, &slen);
 
         /* connection accepted */
         if (newfd >= 0) {
@@ -740,7 +740,7 @@
     /*
      * fill up the remote peer port and address in the new socket structure.
      */
-    socketAddressObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&him, &port);
+    socketAddressObj = NET_SockaddrToInetAddress(env, &him.sa, &port);
     if (socketAddressObj == NULL) {
         /* should be pending exception */
         close(newfd);
@@ -975,21 +975,19 @@
      * SO_BINDADDR isn't a socket option
      */
     if (cmd == java_net_SocketOptions_SO_BINDADDR) {
-        SOCKADDR him;
-        socklen_t len = 0;
+        SOCKETADDRESS him;
+        socklen_t len = sizeof(SOCKETADDRESS);
         int port;
         jobject iaObj;
         jclass iaCntrClass;
         jfieldID iaFieldID;
 
-        len = SOCKADDR_LEN;
-
-        if (getsockname(fd, (struct sockaddr *)&him, &len) < 0) {
+        if (getsockname(fd, &him.sa, &len) < 0) {
             JNU_ThrowByNameWithMessageAndLastError
                 (env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
             return -1;
         }
-        iaObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&him, &port);
+        iaObj = NET_SockaddrToInetAddress(env, &him.sa, &port);
         CHECK_NULL_RETURN(iaObj, -1);
 
         iaCntrClass = (*env)->GetObjectClass(env, iaContainerObj);
--- a/jdk/src/java.base/unix/native/libnet/net_util_md.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/unix/native/libnet/net_util_md.c	Mon Oct 10 22:42:45 2016 +0200
@@ -334,8 +334,8 @@
 #ifdef AF_INET6
     int fd;
     void *ipv6_fn;
-    SOCKADDR sa;
-    socklen_t sa_len = sizeof(sa);
+    SOCKETADDRESS sa;
+    socklen_t sa_len = sizeof(SOCKETADDRESS);
 
     fd = socket(AF_INET6, SOCK_STREAM, 0) ;
     if (fd < 0) {
@@ -351,9 +351,8 @@
      * xinetd. If it's a socket then check the family - if it's an
      * IPv4 socket then we need to disable IPv6.
      */
-    if (getsockname(0, (struct sockaddr *)&sa, &sa_len) == 0) {
-        struct sockaddr *saP = (struct sockaddr *)&sa;
-        if (saP->sa_family != AF_INET6) {
+    if (getsockname(0, &sa.sa, &sa_len) == 0) {
+        if (sa.sa.sa_family != AF_INET6) {
             close(fd);
             return JNI_FALSE;
         }
@@ -488,25 +487,8 @@
     }
 }
 
-void
-NET_AllocSockaddr(struct sockaddr **him, int *len) {
-#ifdef AF_INET6
-    if (ipv6_available()) {
-        struct sockaddr_in6 *him6 = (struct sockaddr_in6*)malloc(sizeof(struct sockaddr_in6));
-        *him = (struct sockaddr*)him6;
-        *len = sizeof(struct sockaddr_in6);
-    } else
-#endif /* AF_INET6 */
-        {
-            struct sockaddr_in *him4 = (struct sockaddr_in*)malloc(sizeof(struct sockaddr_in));
-            *him = (struct sockaddr*)him4;
-            *len = sizeof(struct sockaddr_in);
-        }
-}
-
 #if defined(__linux__) && defined(AF_INET6)
 
-
 /* following code creates a list of addresses from the kernel
  * routing table that are routed via the loopback address.
  * We check all destination addresses against this table
--- a/jdk/src/java.base/unix/native/libnet/net_util_md.h	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/unix/native/libnet/net_util_md.h	Mon Oct 10 22:42:45 2016 +0200
@@ -60,9 +60,9 @@
 void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
                                   const char *defaultDetail);
 
-#define NET_WAIT_READ    0x01
-#define NET_WAIT_WRITE   0x02
-#define NET_WAIT_CONNECT 0x04
+/************************************************************************
+ * Macros and constants
+ */
 
 /* Defines SO_REUSEPORT */
 #ifndef SO_REUSEPORT
@@ -77,12 +77,6 @@
 #endif
 #endif
 
-jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);
-
-/************************************************************************
- * Macros and constants
- */
-
 /*
  * On 64-bit JDKs we use a much larger stack and heap buffer.
  */
@@ -95,20 +89,16 @@
 #endif
 
 #ifdef AF_INET6
-
-#define SOCKADDR        union { \
-                            struct sockaddr_in him4; \
-                            struct sockaddr_in6 him6; \
-                        }
-
-#define SOCKADDR_LEN    (ipv6_available() ? sizeof(SOCKADDR) : \
-                         sizeof(struct sockaddr_in))
-
+typedef union {
+    struct sockaddr     sa;
+    struct sockaddr_in  sa4;
+    struct sockaddr_in6 sa6;
+} SOCKETADDRESS;
 #else
-
-#define SOCKADDR        union { struct sockaddr_in him4; }
-#define SOCKADDR_LEN    sizeof(SOCKADDR)
-
+typedef union {
+    struct sockaddr     sa;
+    struct sockaddr_in  sa4;
+} SOCKETADDRESS;
 #endif
 
 /************************************************************************
--- a/jdk/src/java.base/unix/native/libnio/ch/DatagramChannelImpl.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/unix/native/libnio/ch/DatagramChannelImpl.c	Mon Oct 10 22:42:45 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -87,58 +87,50 @@
     jint fd = fdval(env, fdo);
     int rv;
 
-#ifdef __solaris__
+#if defined(__solaris__)
     rv = connect(fd, 0, 0);
-#endif
+#else
+    int len;
+    SOCKETADDRESS sa;
 
-#if defined(__linux__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
-    {
-        int len;
-        SOCKADDR sa;
-
-        memset(&sa, 0, sizeof(sa));
+    memset(&sa, 0, sizeof(sa));
 
 #ifdef AF_INET6
-        if (isIPv6) {
-            struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)&sa;
+    if (isIPv6) {
 #if defined(_ALLBSD_SOURCE)
-            him6->sin6_family = AF_INET6;
+        sa.sa6.sin6_family = AF_INET6;
 #else
-            him6->sin6_family = AF_UNSPEC;
+        sa.sa6.sin6_family = AF_UNSPEC;
 #endif
-            len = sizeof(struct sockaddr_in6);
-        } else
+        len = sizeof(struct sockaddr_in6);
+    } else
 #endif
-        {
-            struct sockaddr_in *him4 = (struct sockaddr_in*)&sa;
+    {
 #if defined(_ALLBSD_SOURCE)
-            him4->sin_family = AF_INET;
+        sa.sa4.sin_family = AF_INET;
 #else
-            him4->sin_family = AF_UNSPEC;
+        sa.sa4.sin_family = AF_UNSPEC;
 #endif
-            len = sizeof(struct sockaddr_in);
-        }
+        len = sizeof(struct sockaddr_in);
+    }
 
-        rv = connect(fd, (struct sockaddr *)&sa, len);
+    rv = connect(fd, &sa.sa, len);
 
 #if defined(_ALLBSD_SOURCE)
-        if (rv < 0 && errno == EADDRNOTAVAIL)
-                rv = errno = 0;
+    if (rv < 0 && errno == EADDRNOTAVAIL)
+        rv = errno = 0;
+#elif defined(_AIX)
+    /* See W. Richard Stevens, "UNIX Network Programming, Volume 1", p. 254:
+     * 'Setting the address family to AF_UNSPEC might return EAFNOSUPPORT
+     * but that is acceptable.
+     */
+    if (rv < 0 && errno == EAFNOSUPPORT)
+        rv = errno = 0;
 #endif
-#if defined(_AIX)
-        /* See W. Richard Stevens, "UNIX Network Programming, Volume 1", p. 254:
-         * 'Setting the address family to AF_UNSPEC might return EAFNOSUPPORT
-         * but that is acceptable.
-         */
-        if (rv < 0 && errno == EAFNOSUPPORT)
-            rv = errno = 0;
-#endif
-    }
 #endif
 
     if (rv < 0)
         handleSocketError(env, errno);
-
 }
 
 JNIEXPORT jint JNICALL
@@ -148,8 +140,8 @@
 {
     jint fd = fdval(env, fdo);
     void *buf = (void *)jlong_to_ptr(address);
-    SOCKADDR sa;
-    socklen_t sa_len = SOCKADDR_LEN;
+    SOCKETADDRESS sa;
+    socklen_t sa_len = sizeof(SOCKETADDRESS);
     jboolean retry = JNI_FALSE;
     jint n = 0;
     jobject senderAddr;
@@ -160,7 +152,7 @@
 
     do {
         retry = JNI_FALSE;
-        n = recvfrom(fd, buf, len, 0, (struct sockaddr *)&sa, &sa_len);
+        n = recvfrom(fd, buf, len, 0, &sa.sa, &sa_len);
         if (n < 0) {
             if (errno == EWOULDBLOCK) {
                 return IOS_UNAVAILABLE;
@@ -189,12 +181,11 @@
      */
     senderAddr = (*env)->GetObjectField(env, this, dci_senderAddrID);
     if (senderAddr != NULL) {
-        if (!NET_SockaddrEqualsInetAddress(env, (struct sockaddr *)&sa,
-                                           senderAddr)) {
+        if (!NET_SockaddrEqualsInetAddress(env, &sa.sa, senderAddr)) {
             senderAddr = NULL;
         } else {
             jint port = (*env)->GetIntField(env, this, dci_senderPortID);
-            if (port != NET_GetPortFromSockaddr((struct sockaddr *)&sa)) {
+            if (port != NET_GetPortFromSockaddr(&sa.sa)) {
                 senderAddr = NULL;
             }
         }
@@ -202,7 +193,7 @@
     if (senderAddr == NULL) {
         jobject isa = NULL;
         int port = 0;
-        jobject ia = NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
+        jobject ia = NET_SockaddrToInetAddress(env, &sa.sa, &port);
         if (ia != NULL) {
             isa = (*env)->NewObject(env, isa_class, isa_ctorID, ia, port);
         }
@@ -210,7 +201,7 @@
 
         (*env)->SetObjectField(env, this, dci_senderAddrID, ia);
         (*env)->SetIntField(env, this, dci_senderPortID,
-                            NET_GetPortFromSockaddr((struct sockaddr *)&sa));
+                            NET_GetPortFromSockaddr(&sa.sa));
         (*env)->SetObjectField(env, this, dci_senderID, isa);
     }
     return n;
@@ -223,21 +214,20 @@
 {
     jint fd = fdval(env, fdo);
     void *buf = (void *)jlong_to_ptr(address);
-    SOCKADDR sa;
-    int sa_len = SOCKADDR_LEN;
+    SOCKETADDRESS sa;
+    int sa_len = sizeof(SOCKETADDRESS);
     jint n = 0;
 
     if (len > MAX_PACKET_LEN) {
         len = MAX_PACKET_LEN;
     }
 
-    if (NET_InetAddressToSockaddr(env, destAddress, destPort,
-                                  (struct sockaddr *)&sa,
+    if (NET_InetAddressToSockaddr(env, destAddress, destPort, &sa.sa,
                                   &sa_len, preferIPv6) != 0) {
       return IOS_THROWN;
     }
 
-    n = sendto(fd, buf, len, 0, (struct sockaddr *)&sa, sa_len);
+    n = sendto(fd, buf, len, 0, &sa.sa, sa_len);
     if (n < 0) {
         if (errno == EAGAIN) {
             return IOS_UNAVAILABLE;
--- a/jdk/src/java.base/unix/native/libnio/ch/InheritedChannel.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/unix/native/libnio/ch/InheritedChannel.c	Mon Oct 10 22:42:45 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -57,18 +57,16 @@
 JNIEXPORT jobject JNICALL
 Java_sun_nio_ch_InheritedChannel_peerAddress0(JNIEnv *env, jclass cla, jint fd)
 {
-    struct sockaddr *sa;
-    socklen_t sa_len;
+    SOCKETADDRESS sa;
+    socklen_t len = sizeof(SOCKETADDRESS);
     jobject remote_ia = NULL;
     jint remote_port;
 
-    NET_AllocSockaddr(&sa, (int *)&sa_len);
-    if (getpeername(fd, sa, &sa_len) == 0) {
-        if (matchFamily(sa)) {
-            remote_ia = NET_SockaddrToInetAddress(env, sa, (int *)&remote_port);
+    if (getpeername(fd, &sa.sa, &len) == 0) {
+        if (matchFamily(&sa.sa)) {
+            remote_ia = NET_SockaddrToInetAddress(env, &sa.sa, (int *)&remote_port);
         }
     }
-    free((void *)sa);
 
     return remote_ia;
 }
@@ -77,17 +75,15 @@
 JNIEXPORT jint JNICALL
 Java_sun_nio_ch_InheritedChannel_peerPort0(JNIEnv *env, jclass cla, jint fd)
 {
-    struct sockaddr *sa;
-    socklen_t sa_len;
+    SOCKETADDRESS sa;
+    socklen_t len = sizeof(SOCKETADDRESS);
     jint remote_port = -1;
 
-    NET_AllocSockaddr(&sa, (int *)&sa_len);
-    if (getpeername(fd, sa, &sa_len) == 0) {
-        if (matchFamily(sa)) {
-            NET_SockaddrToInetAddress(env, sa, (int *)&remote_port);
+    if (getpeername(fd, &sa.sa, &len) == 0) {
+        if (matchFamily(&sa.sa)) {
+            NET_SockaddrToInetAddress(env, &sa.sa, (int *)&remote_port);
         }
     }
-    free((void *)sa);
 
     return remote_port;
 }
--- a/jdk/src/java.base/unix/native/libnio/ch/Net.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/unix/native/libnio/ch/Net.c	Mon Oct 10 22:42:45 2016 +0200
@@ -273,15 +273,16 @@
 Java_sun_nio_ch_Net_bind0(JNIEnv *env, jclass clazz, jobject fdo, jboolean preferIPv6,
                           jboolean useExclBind, jobject iao, int port)
 {
-    SOCKADDR sa;
-    int sa_len = SOCKADDR_LEN;
+    SOCKETADDRESS sa;
+    int sa_len = sizeof(SOCKETADDRESS);
     int rv = 0;
 
-    if (NET_InetAddressToSockaddr(env, iao, port, (struct sockaddr *)&sa, &sa_len, preferIPv6) != 0) {
-      return;
+    if (NET_InetAddressToSockaddr(env, iao, port, &sa.sa, &sa_len,
+                                  preferIPv6) != 0) {
+        return;
     }
 
-    rv = NET_Bind(fdval(env, fdo), (struct sockaddr *)&sa, sa_len);
+    rv = NET_Bind(fdval(env, fdo), &sa.sa, sa_len);
     if (rv != 0) {
         handleSocketError(env, errno);
     }
@@ -298,17 +299,16 @@
 Java_sun_nio_ch_Net_connect0(JNIEnv *env, jclass clazz, jboolean preferIPv6,
                              jobject fdo, jobject iao, jint port)
 {
-    SOCKADDR sa;
-    int sa_len = SOCKADDR_LEN;
+    SOCKETADDRESS sa;
+    int sa_len = sizeof(SOCKETADDRESS);
     int rv;
 
-    if (NET_InetAddressToSockaddr(env, iao, port, (struct sockaddr *) &sa,
-                                  &sa_len, preferIPv6) != 0)
-    {
-      return IOS_THROWN;
+    if (NET_InetAddressToSockaddr(env, iao, port, &sa.sa, &sa_len,
+                                  preferIPv6) != 0) {
+        return IOS_THROWN;
     }
 
-    rv = connect(fdval(env, fdo), (struct sockaddr *)&sa, sa_len);
+    rv = connect(fdval(env, fdo), &sa.sa, sa_len);
     if (rv != 0) {
         if (errno == EINPROGRESS) {
             return IOS_UNAVAILABLE;
@@ -323,9 +323,9 @@
 JNIEXPORT jint JNICALL
 Java_sun_nio_ch_Net_localPort(JNIEnv *env, jclass clazz, jobject fdo)
 {
-    SOCKADDR sa;
-    socklen_t sa_len = SOCKADDR_LEN;
-    if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
+    SOCKETADDRESS sa;
+    socklen_t sa_len = sizeof(SOCKETADDRESS);
+    if (getsockname(fdval(env, fdo), &sa.sa, &sa_len) < 0) {
 #ifdef _ALLBSD_SOURCE
         /*
          * XXXBSD:
@@ -335,13 +335,11 @@
          * it shouldn't fail. As such, we just fill in generic Linux-compatible values.
          */
         if (errno == ECONNRESET) {
-            struct sockaddr_in *sin;
-            sin = (struct sockaddr_in *) &sa;
-            bzero(sin, sizeof(*sin));
-            sin->sin_len  = sizeof(struct sockaddr_in);
-            sin->sin_family = AF_INET;
-            sin->sin_port = htonl(0);
-            sin->sin_addr.s_addr = INADDR_ANY;
+            bzero(&sa.sa4, sizeof(sa));
+            sa.sa4.sin_len = sizeof(struct sockaddr_in);
+            sa.sa4.sin_family = AF_INET;
+            sa.sa4.sin_port = htonl(0);
+            sa.sa4.sin_addr.s_addr = INADDR_ANY;
         } else {
             handleSocketError(env, errno);
             return -1;
@@ -351,16 +349,16 @@
         return -1;
 #endif /* _ALLBSD_SOURCE */
     }
-    return NET_GetPortFromSockaddr((struct sockaddr *)&sa);
+    return NET_GetPortFromSockaddr(&sa.sa);
 }
 
 JNIEXPORT jobject JNICALL
 Java_sun_nio_ch_Net_localInetAddress(JNIEnv *env, jclass clazz, jobject fdo)
 {
-    SOCKADDR sa;
-    socklen_t sa_len = SOCKADDR_LEN;
+    SOCKETADDRESS sa;
+    socklen_t sa_len = sizeof(SOCKETADDRESS);
     int port;
-    if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
+    if (getsockname(fdval(env, fdo), &sa.sa, &sa_len) < 0) {
 #ifdef _ALLBSD_SOURCE
         /*
          * XXXBSD:
@@ -370,13 +368,11 @@
          * it shouldn't fail. As such, we just fill in generic Linux-compatible values.
          */
         if (errno == ECONNRESET) {
-            struct sockaddr_in *sin;
-            sin = (struct sockaddr_in *) &sa;
-            bzero(sin, sizeof(*sin));
-            sin->sin_len  = sizeof(struct sockaddr_in);
-            sin->sin_family = AF_INET;
-            sin->sin_port = htonl(0);
-            sin->sin_addr.s_addr = INADDR_ANY;
+            bzero(&sa.sa4, sizeof(sa));
+            sa.sa4.sin_len  = sizeof(struct sockaddr_in);
+            sa.sa4.sin_family = AF_INET;
+            sa.sa4.sin_port = htonl(0);
+            sa.sa4.sin_addr.s_addr = INADDR_ANY;
         } else {
             handleSocketError(env, errno);
             return NULL;
@@ -386,7 +382,7 @@
         return NULL;
 #endif /* _ALLBSD_SOURCE */
     }
-    return NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
+    return NET_SockaddrToInetAddress(env, &sa.sa, &port);
 }
 
 JNIEXPORT jint JNICALL
--- a/jdk/src/java.base/unix/native/libnio/ch/ServerSocketChannelImpl.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/unix/native/libnio/ch/ServerSocketChannelImpl.c	Mon Oct 10 22:42:45 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -80,26 +80,19 @@
 {
     jint ssfd = (*env)->GetIntField(env, ssfdo, fd_fdID);
     jint newfd;
-    struct sockaddr *sa;
-    int alloc_len;
+    SOCKETADDRESS sa;
+    socklen_t sa_len = sizeof(SOCKETADDRESS);
     jobject remote_ia = 0;
     jobject isa;
     jint remote_port = 0;
 
-    NET_AllocSockaddr(&sa, &alloc_len);
-    if (sa == NULL) {
-        JNU_ThrowOutOfMemoryError(env, NULL);
-        return IOS_THROWN;
-    }
-
     /*
      * accept connection but ignore ECONNABORTED indicating that
      * a connection was eagerly accepted but was reset before
      * accept() was called.
      */
     for (;;) {
-        socklen_t sa_len = alloc_len;
-        newfd = accept(ssfd, sa, &sa_len);
+        newfd = accept(ssfd, &sa.sa, &sa_len);
         if (newfd >= 0) {
             break;
         }
@@ -110,7 +103,6 @@
     }
 
     if (newfd < 0) {
-        free((void *)sa);
         if (errno == EAGAIN)
             return IOS_UNAVAILABLE;
         if (errno == EINTR)
@@ -120,8 +112,7 @@
     }
 
     (*env)->SetIntField(env, newfdo, fd_fdID, newfd);
-    remote_ia = NET_SockaddrToInetAddress(env, sa, (int *)&remote_port);
-    free((void *)sa);
+    remote_ia = NET_SockaddrToInetAddress(env, &sa.sa, (int *)&remote_port);
     CHECK_NULL_RETURN(remote_ia, IOS_THROWN);
     isa = (*env)->NewObject(env, isa_class, isa_ctorID, remote_ia, remote_port);
     CHECK_NULL_RETURN(isa, IOS_THROWN);
--- a/jdk/src/java.base/windows/native/libnet/Inet6AddressImpl.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/windows/native/libnet/Inet6AddressImpl.c	Mon Oct 10 22:42:45 2016 +0200
@@ -83,7 +83,7 @@
     jboolean preferIPv6Address;
 
     int error=0;
-    struct addrinfo hints, *res, *resNew = NULL;
+    struct addrinfo hints, *res = NULL, *resNew = NULL;
 
     initInetAddressIDs(env);
     JNU_CHECK_EXCEPTION_RETURN(env, NULL);
@@ -223,7 +223,7 @@
               setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
               setInetAddress_hostName(env, iaObj, host);
               (*env)->SetObjectArrayElement(env, ret, (inetIndex | originalIndex), iaObj);
-                inetIndex ++;
+              inetIndex ++;
             } else if (iterator->ai_family == AF_INET6) {
               jint scope = 0;
               jboolean ret1;
--- a/jdk/src/java.base/windows/native/libnet/NetworkInterface.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/windows/native/libnet/NetworkInterface.c	Mon Oct 10 22:42:45 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -429,8 +429,8 @@
                 return -1;
             }
 
-            curr->addr.him4.sin_family = AF_INET;
-            curr->addr.him4.sin_addr.s_addr = tableP->table[i].dwAddr;
+            curr->addr.sa4.sin_family = AF_INET;
+            curr->addr.sa4.sin_addr.s_addr = tableP->table[i].dwAddr;
             /*
              * Get netmask / broadcast address
              */
@@ -447,11 +447,11 @@
                * to 0 or 1.
                * Yes, I know it's stupid, but what can I say, it's MSFTs API.
                */
-              curr->brdcast.him4.sin_family = AF_INET;
+              curr->brdcast.sa4.sin_family = AF_INET;
               if (tableP->table[i].dwBCastAddr == 1)
-                curr->brdcast.him4.sin_addr.s_addr = (tableP->table[i].dwAddr & tableP->table[i].dwMask) | (0xffffffff ^ tableP->table[i].dwMask);
+                curr->brdcast.sa4.sin_addr.s_addr = (tableP->table[i].dwAddr & tableP->table[i].dwMask) | (0xffffffff ^ tableP->table[i].dwMask);
               else
-                curr->brdcast.him4.sin_addr.s_addr = (tableP->table[i].dwAddr & tableP->table[i].dwMask);
+                curr->brdcast.sa4.sin_addr.s_addr = (tableP->table[i].dwAddr & tableP->table[i].dwMask);
               mask = ntohl(tableP->table[i].dwMask);
               curr->mask = 0;
               while (mask) {
@@ -584,7 +584,7 @@
     while (addrs != NULL) {
         jobject iaObj, ia2Obj;
         jobject ibObj = NULL;
-        if (addrs->addr.him.sa_family == AF_INET) {
+        if (addrs->addr.sa.sa_family == AF_INET) {
             iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
             if (iaObj == NULL) {
                 free_netaddr(netaddrP);
@@ -592,7 +592,7 @@
             }
             /* default ctor will set family to AF_INET */
 
-            setInetAddress_addr(env, iaObj, ntohl(addrs->addr.him4.sin_addr.s_addr));
+            setInetAddress_addr(env, iaObj, ntohl(addrs->addr.sa4.sin_addr.s_addr));
             if (addrs->mask != -1) {
               ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
               if (ibObj == NULL) {
@@ -605,7 +605,7 @@
                 free_netaddr(netaddrP);
                 return NULL;
               }
-              setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.him4.sin_addr.s_addr));
+              setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.sa4.sin_addr.s_addr));
               (*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj);
               (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
               (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
@@ -614,12 +614,12 @@
             int scope;
             iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
             if (iaObj) {
-                jboolean ret = setInet6Address_ipaddress(env, iaObj,  (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr));
+                jboolean ret = setInet6Address_ipaddress(env, iaObj,  (jbyte *)&(addrs->addr.sa6.sin6_addr.s6_addr));
                 if (ret == JNI_FALSE) {
                     return NULL;
                 }
 
-                scope = addrs->addr.him6.sin6_scope_id;
+                scope = addrs->addr.sa6.sin6_scope_id;
                 if (scope != 0) { /* zero is default value, no need to set */
                     setInet6Address_scopeid(env, iaObj, scope);
                     setInet6Address_scopeifname(env, iaObj, netifObj);
@@ -795,7 +795,7 @@
         addrP = addrList;
 
         while (addrP != NULL) {
-            if ((unsigned long)addr == ntohl(addrP->addr.him4.sin_addr.s_addr)) {
+            if ((unsigned long)addr == ntohl(addrP->addr.sa4.sin_addr.s_addr)) {
                 break;
             }
             addrP = addrP->next;
--- a/jdk/src/java.base/windows/native/libnet/NetworkInterface_winXP.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/windows/native/libnet/NetworkInterface_winXP.c	Mon Oct 10 22:42:45 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -595,14 +595,14 @@
     while (addrs != NULL) {
         jobject iaObj, ia2Obj;
         jobject ibObj = NULL;
-        if (addrs->addr.him.sa_family == AF_INET) {
+        if (addrs->addr.sa.sa_family == AF_INET) {
             iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
             if (iaObj == NULL) {
                 return NULL;
             }
             /* default ctor will set family to AF_INET */
 
-            setInetAddress_addr(env, iaObj, ntohl(addrs->addr.him4.sin_addr.s_addr));
+            setInetAddress_addr(env, iaObj, ntohl(addrs->addr.sa4.sin_addr.s_addr));
 
             ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
             if (ibObj == NULL) {
@@ -615,7 +615,7 @@
               free_netaddr(netaddrP);
               return NULL;
             }
-            setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.him4.sin_addr.s_addr));
+            setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.sa4.sin_addr.s_addr));
             (*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj);
             (*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
             (*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
@@ -623,11 +623,11 @@
             int scope;
             iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
             if (iaObj) {
-                jboolean ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.him6.sin6_addr.s6_addr));
+                jboolean ret = setInet6Address_ipaddress(env, iaObj, (jbyte *)&(addrs->addr.sa6.sin6_addr.s6_addr));
                 if (ret == JNI_FALSE) {
                     return NULL;
                 }
-                scope = addrs->addr.him6.sin6_scope_id;
+                scope = addrs->addr.sa6.sin6_scope_id;
                 if (scope != 0) { /* zero is default value, no need to set */
                     setInet6Address_scopeid(env, iaObj, scope);
                     setInet6Address_scopeifname(env, iaObj, netifObj);
--- a/jdk/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c	Mon Oct 10 22:42:45 2016 +0200
@@ -51,6 +51,8 @@
 #define IN_CLASSD(i)    (((long)(i) & 0xf0000000) == 0xe0000000)
 #define IN_MULTICAST(i) IN_CLASSD(i)
 
+extern int getAllInterfacesAndAddresses(JNIEnv *env, netif **netifPP);
+
 /************************************************************************
  * TwoStacksPlainDatagramSocketImpl
  */
@@ -88,7 +90,7 @@
  * Returns a java.lang.Integer based on 'i'
  */
 jobject createInteger(JNIEnv *env, int i) {
-    static jclass i_class;
+    static jclass i_class = NULL;
     static jmethodID i_ctrID;
     static jfieldID i_valueID;
 
@@ -101,14 +103,14 @@
         CHECK_NULL_RETURN(i_class, NULL);
     }
 
-    return ( (*env)->NewObject(env, i_class, i_ctrID, i) );
+    return (*env)->NewObject(env, i_class, i_ctrID, i);
 }
 
 /*
  * Returns a java.lang.Boolean based on 'b'
  */
 jobject createBoolean(JNIEnv *env, int b) {
-    static jclass b_class;
+    static jclass b_class = NULL;
     static jmethodID b_ctrID;
     static jfieldID b_valueID;
 
@@ -121,10 +123,9 @@
         CHECK_NULL_RETURN(b_class, NULL);
     }
 
-    return( (*env)->NewObject(env, b_class, b_ctrID, (jboolean)(b!=0)) );
+    return (*env)->NewObject(env, b_class, b_ctrID, (jboolean)(b!=0));
 }
 
-
 static int getFD(JNIEnv *env, jobject this) {
     jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
 
@@ -333,7 +334,7 @@
     fd_set tbl;
     struct timeval t = { 0, 0 };
     SOCKETADDRESS rmtaddr;
-    int addrlen = sizeof(rmtaddr);
+    int addrlen = sizeof(SOCKETADDRESS);
 
     memset((char *)&rmtaddr, 0, sizeof(rmtaddr));
 
@@ -354,8 +355,7 @@
         if (select(/*ignored*/fd+1, &tbl, 0, 0, &t) <= 0) {
             break;
         }
-        if (recvfrom(fd, buf, 1, MSG_PEEK,
-                         (struct sockaddr *)&rmtaddr, &addrlen) != SOCKET_ERROR) {
+        if (recvfrom(fd, buf, 1, MSG_PEEK, &rmtaddr.sa, &addrlen) != SOCKET_ERROR) {
             break;
         }
         if (WSAGetLastError() != WSAECONNRESET) {
@@ -363,7 +363,7 @@
             break;
         }
 
-        recvfrom(fd, buf, 1, 0,  (struct sockaddr *)&rmtaddr, &addrlen);
+        recvfrom(fd, buf, 1, 0, &rmtaddr.sa, &addrlen);
         got_icmp = JNI_TRUE;
     }
 
@@ -429,11 +429,11 @@
     jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
     jobject fd1Obj = (*env)->GetObjectField(env, this, pdsi_fd1ID);
 
-    int fd, fd1, family;
+    int fd, fd1 = -1, family;
     int ipv6_supported = ipv6_available();
 
     SOCKETADDRESS lcladdr;
-    int lcladdrlen = sizeof(lcladdr);
+    int lcladdrlen = sizeof(SOCKETADDRESS);
     int address;
 
     memset((char *)&lcladdr, 0, sizeof(lcladdr));
@@ -461,8 +461,9 @@
         address = getInetAddress_addr(env, addressObj);
     }
 
-    if (NET_InetAddressToSockaddr(env, addressObj, port, (struct sockaddr *)&lcladdr, &lcladdrlen, JNI_FALSE) != 0) {
-      return;
+    if (NET_InetAddressToSockaddr(env, addressObj, port, &lcladdr.sa,
+                                  &lcladdrlen, JNI_FALSE) != 0) {
+        return;
     }
 
     if (ipv6_supported) {
@@ -500,7 +501,7 @@
             return;
         }
     } else {
-        if (NET_WinBind(fd, (struct sockaddr *)&lcladdr, lcladdrlen, exclBind) == -1) {
+        if (NET_WinBind(fd, &lcladdr.sa, lcladdrlen, exclBind) == -1) {
             if (WSAGetLastError() == WSAEACCES) {
                 WSASetLastError(WSAEADDRINUSE);
             }
@@ -510,11 +511,7 @@
     }
 
     if (port == 0) {
-        if (fd == -1) {
-            /* must be an IPV6 only socket. */
-            fd = fd1;
-        }
-        if (getsockname(fd, (struct sockaddr *)&lcladdr, &lcladdrlen) == -1) {
+        if (getsockname(fd == -1 ? fd1 : fd, &lcladdr.sa, &lcladdrlen) == -1) {
             NET_ThrowCurrent(env, "getsockname");
             return;
         }
@@ -583,11 +580,12 @@
         res = WSAIoctl(fdc,SIO_UDP_CONNRESET,&t,sizeof(t),&x1,sizeof(x1),&x2,0,0);
     }
 
-    if (NET_InetAddressToSockaddr(env, address, port,(struct sockaddr *)&rmtaddr, &rmtaddrlen, JNI_FALSE) != 0) {
-      return;
+    if (NET_InetAddressToSockaddr(env, address, port, &rmtaddr.sa,
+                                  &rmtaddrlen, JNI_FALSE) != 0) {
+        return;
     }
 
-    if (connect(fdc, (struct sockaddr *)&rmtaddr, sizeof(rmtaddr)) == -1) {
+    if (connect(fdc, &rmtaddr.sa, sizeof(rmtaddr)) == -1) {
         NET_ThrowCurrent(env, "connect");
         return;
     }
@@ -622,7 +620,7 @@
     fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
 
     memset((char *)&addr, 0, len);
-    connect(fd, (struct sockaddr *)&addr, len);
+    connect(fd, &addr.sa, len);
 
     /*
      * use SIO_UDP_CONNRESET
@@ -657,8 +655,7 @@
     jbyteArray packetBuffer;
     jboolean connected;
 
-    SOCKETADDRESS rmtaddr;
-    SOCKETADDRESS *addrp = &rmtaddr;
+    SOCKETADDRESS rmtaddr, *addrp = &rmtaddr;
     int addrlen = 0;
 
     memset((char *)&rmtaddr, 0, sizeof(rmtaddr));
@@ -711,9 +708,10 @@
         addrp = 0; /* arg to sendto () null in this case */
         addrlen = 0;
     } else {
-      if (NET_InetAddressToSockaddr(env, iaObj, packetPort, (struct sockaddr *)&rmtaddr, &addrlen, JNI_FALSE) != 0) {
-        return;
-      }
+        if (NET_InetAddressToSockaddr(env, iaObj, packetPort, &rmtaddr.sa,
+                                      &addrlen, JNI_FALSE) != 0) {
+            return;
+        }
     }
 
     if (packetBufferLen > MAX_BUFFER_LEN) {
@@ -732,7 +730,7 @@
             if (connected) {
                 address = getInetAddress_addr(env, iaObj);
             } else {
-                address = ntohl(rmtaddr.him4.sin_addr.s_addr);
+                address = ntohl(rmtaddr.sa4.sin_addr.s_addr);
             }
 
             if (exceedSizeLimit(env, fd, address, packetBufferLen)) {
@@ -813,8 +811,8 @@
     jint address, family;
 
     int n;
-    struct sockaddr_in remote_addr;
-    jint remote_addrsize = sizeof (remote_addr);
+    SOCKETADDRESS remote_addr;
+    jint remote_addrsize = sizeof(SOCKETADDRESS);
     char buf[1];
     BOOL retry;
     jlong prevTime = 0;
@@ -860,8 +858,7 @@
         }
 
         /* now try the peek */
-        n = recvfrom(fd, buf, 1, MSG_PEEK,
-                         (struct sockaddr *)&remote_addr, &remote_addrsize);
+        n = recvfrom(fd, buf, 1, MSG_PEEK, &remote_addr.sa, &remote_addrsize);
 
         if (n == SOCKET_ERROR) {
             if (WSAGetLastError() == WSAECONNRESET) {
@@ -907,11 +904,11 @@
         NET_ThrowCurrent(env, "Datagram peek failed");
         return 0;
     }
-    setInetAddress_addr(env, addressObj, ntohl(remote_addr.sin_addr.s_addr));
+    setInetAddress_addr(env, addressObj, ntohl(remote_addr.sa4.sin_addr.s_addr));
     setInetAddress_family(env, addressObj, IPv4);
 
     /* return port */
-    return ntohs(remote_addr.sin_port);
+    return ntohs(remote_addr.sa4.sin_port);
 }
 
 JNIEXPORT jint JNICALL
@@ -927,13 +924,13 @@
     jbyteArray packetBuffer;
     jint packetBufferOffset, packetBufferLen;
 
-    int fd, fd1, fduse, nsockets=0, errorCode;
+    int fd = -1, fd1 = -1, fduse, nsockets = 0, errorCode;
     int port;
 
     int checkBoth = 0;
     int n;
     SOCKETADDRESS remote_addr;
-    jint remote_addrsize=sizeof(remote_addr);
+    jint remote_addrsize = sizeof(SOCKETADDRESS);
     BOOL retry;
     jlong prevTime = 0;
 
@@ -1063,7 +1060,7 @@
 
         /* receive the packet */
         n = recvfrom(fduse, fullPacket, packetBufferLen, MSG_PEEK,
-                         (struct sockaddr *)&remote_addr, &remote_addrsize);
+                     &remote_addr.sa, &remote_addrsize);
         port = (int) ntohs ((u_short) GET_PORT((SOCKETADDRESS *)&remote_addr));
         if (n == SOCKET_ERROR) {
             if (WSAGetLastError() == WSAECONNRESET) {
@@ -1145,15 +1142,15 @@
          */
         packetAddress = (*env)->GetObjectField(env, packet, dp_addressID);
         if (packetAddress != NULL) {
-            if (!NET_SockaddrEqualsInetAddress(env, (struct sockaddr *)
-                                                &remote_addr, packetAddress)) {
+            if (!NET_SockaddrEqualsInetAddress(env, &remote_addr.sa,
+                                               packetAddress)) {
                 /* force a new InetAddress to be created */
                 packetAddress = NULL;
             }
         }
         if (packetAddress == NULL) {
-            packetAddress = NET_SockaddrToInetAddress(env, (struct sockaddr *)
-                                &remote_addr, &port);
+            packetAddress = NET_SockaddrToInetAddress(env, &remote_addr.sa,
+                                                      &port);
             /* stuff the new Inetaddress in the packet */
             (*env)->SetObjectField(env, packet, dp_addressID, packetAddress);
         }
@@ -1195,11 +1192,11 @@
     /* as a result of the changes for ipv6, peek() or peekData()
      * must be called prior to receive() so that fduse can be set.
      */
-    int fd, fd1, fduse, errorCode;
+    int fd = -1, fd1 = -1, fduse, errorCode;
 
     int n, nsockets=0;
     SOCKETADDRESS remote_addr;
-    jint remote_addrsize=sizeof(remote_addr);
+    jint remote_addrsize = sizeof(SOCKETADDRESS);
     BOOL retry;
     jlong prevTime = 0, selectTime=0;
     jboolean connected;
@@ -1327,8 +1324,8 @@
         retry = FALSE;
 
         /* receive the packet */
-        n = recvfrom(fduse, fullPacket, packetBufferLen, 0,
-                         (struct sockaddr *)&remote_addr, &remote_addrsize);
+        n = recvfrom(fduse, fullPacket, packetBufferLen, 0, &remote_addr.sa,
+                     &remote_addrsize);
 
         if (n == SOCKET_ERROR) {
             if (WSAGetLastError() == WSAECONNRESET) {
@@ -1431,18 +1428,18 @@
         packetAddress = (*env)->GetObjectField(env, packet, dp_addressID);
 
         if (packetAddress != NULL) {
-            if (!NET_SockaddrEqualsInetAddress(env, (struct sockaddr *)&remote_addr, packetAddress)) {
+            if (!NET_SockaddrEqualsInetAddress(env, &remote_addr.sa, packetAddress)) {
                 /* force a new InetAddress to be created */
                 packetAddress = NULL;
             }
         }
         if (packetAddress == NULL) {
-            packetAddress = NET_SockaddrToInetAddress(env, (struct sockaddr *)&remote_addr, &port);
+            packetAddress = NET_SockaddrToInetAddress(env, &remote_addr.sa, &port);
             /* stuff the new Inetaddress in the packet */
             (*env)->SetObjectField(env, packet, dp_addressID, packetAddress);
         } else {
             /* only get the new port number */
-            port = NET_GetPortFromSockaddr((struct sockaddr *)&remote_addr);
+            port = NET_GetPortFromSockaddr(&remote_addr.sa);
         }
         /* populate the packet */
         (*env)->SetByteArrayRegion(env, packetBuffer, packetBufferOffset, n,
@@ -1612,7 +1609,7 @@
 /* Get the multicasting index from the interface */
 
 static int getIndexFromIf (JNIEnv *env, jobject nif) {
-    static jfieldID ni_indexID;
+    static jfieldID ni_indexID = NULL;
 
     if (ni_indexID == NULL) {
         jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
@@ -1625,10 +1622,9 @@
 }
 
 static int isAdapterIpv6Enabled(JNIEnv *env, int index) {
-  extern int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP);
   netif *ifList, *curr;
   int ipv6Enabled = 0;
-  if (getAllInterfacesAndAddresses (env, &ifList) < 0) {
+  if (getAllInterfacesAndAddresses(env, &ifList) < 0) {
       return ipv6Enabled;
   }
 
@@ -1689,7 +1685,7 @@
          * option instead of IP_MULTICAST_IF
          */
         if (ipv6_supported) {
-            static jclass ni_class;
+            static jclass ni_class = NULL;
             if (ni_class == NULL) {
                 jclass c = (*env)->FindClass(env, "java/net/NetworkInterface");
                 CHECK_NULL(c);
@@ -1729,7 +1725,7 @@
          * option. For IPv6 both must be done.
          */
         if (ipv6_supported) {
-            static jfieldID ni_indexID;
+            static jfieldID ni_indexID = NULL;
             struct in_addr in;
             int index;
 
@@ -2250,10 +2246,10 @@
  * Signature: (I)Ljava/lang/Object;
  */
 JNIEXPORT jobject JNICALL
-Java_java_net_TwoStacksPlainDatagramSocketImpl_socketLocalAddress(JNIEnv *env, jobject this,
-                                                      jint family) {
-
-    int fd=-1, fd1=-1;
+Java_java_net_TwoStacksPlainDatagramSocketImpl_socketLocalAddress
+  (JNIEnv *env, jobject this, jint family)
+{
+    int fd = -1, fd1 = -1;
     SOCKETADDRESS him;
     int len = 0;
     int port;
@@ -2273,7 +2269,7 @@
 
     /* find out local IP address */
 
-    len = sizeof (struct sockaddr_in);
+    len = sizeof(struct sockaddr_in);
 
     /* family==-1 when socket is not connected */
     if ((family == IPv6) || (family == -1 && fd == -1)) {
@@ -2287,12 +2283,12 @@
         return NULL;
     }
 
-    if (getsockname(fd, (struct sockaddr *)&him, &len) == -1) {
+    if (getsockname(fd, &him.sa, &len) == -1) {
         JNU_ThrowByNameWithMessageAndLastError
             (env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
         return NULL;
     }
-    iaObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&him, &port);
+    iaObj = NET_SockaddrToInetAddress(env, &him.sa, &port);
 
     return iaObj;
 }
@@ -2450,17 +2446,17 @@
         return;
     }
 
-    if (NET_InetAddressToSockaddr(env, iaObj, 0, (struct sockaddr *)&name, &len, JNI_FALSE) != 0) {
+    if (NET_InetAddressToSockaddr(env, iaObj, 0, &name.sa, &len, JNI_FALSE) != 0) {
       return;
     }
 
     /* Set the multicast group address in the ip_mreq field
      * eventually this check should be done by the security manager
      */
-    family = name.him.sa_family;
+    family = name.sa.sa_family;
 
     if (family == AF_INET) {
-        int address = name.him4.sin_addr.s_addr;
+        int address = name.sa4.sin_addr.s_addr;
         if (!IN_MULTICAST(ntohl(address))) {
             JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "not in multicast");
             return;
@@ -2499,7 +2495,7 @@
     } else /* AF_INET6 */ {
         if (ipv6_supported) {
             struct in6_addr *address;
-            address = &name.him6.sin6_addr;
+            address = &name.sa6.sin6_addr;
             if (!IN6_IS_ADDR_MULTICAST(address)) {
                 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "not in6 multicast");
                 return;
--- a/jdk/src/java.base/windows/native/libnet/TwoStacksPlainSocketImpl.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/windows/native/libnet/TwoStacksPlainSocketImpl.c	Mon Oct 10 22:42:45 2016 +0200
@@ -192,7 +192,7 @@
 
     /* family and localport are int fields of iaObj */
     int family;
-    jint fd, fd1=-1;
+    jint fd = -1, fd1 = -1;
     jint len;
     int  ipv6_supported = ipv6_available();
 
@@ -222,11 +222,11 @@
         return;
     }
 
-    if (NET_InetAddressToSockaddr(env, iaObj, port, (struct sockaddr *)&him, &len, JNI_FALSE) != 0) {
+    if (NET_InetAddressToSockaddr(env, iaObj, port, &him.sa, &len, JNI_FALSE) != 0) {
       return;
     }
 
-    family = him.him.sa_family;
+    family = him.sa.sa_family;
     if (family == AF_INET6) {
         if (!ipv6_supported) {
             JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
@@ -258,7 +258,7 @@
     (*env)->SetObjectField(env, this, psi_fd1ID, NULL);
 
     if (timeout <= 0) {
-        connect_res = connect(fd, (struct sockaddr *) &him, SOCKETADDRESS_LEN(&him));
+        connect_res = connect(fd, &him.sa, sizeof(SOCKETADDRESS));
         if (connect_res == SOCKET_ERROR) {
             connect_res = WSAGetLastError();
         }
@@ -268,10 +268,10 @@
 
         /* make socket non-blocking */
         optval = 1;
-        ioctlsocket( fd, FIONBIO, &optval );
+        ioctlsocket(fd, FIONBIO, &optval);
 
         /* initiate the connect */
-        connect_res = connect(fd, (struct sockaddr *) &him, SOCKETADDRESS_LEN(&him));
+        connect_res = connect(fd, &him.sa, sizeof(SOCKETADDRESS));
         if (connect_res == SOCKET_ERROR) {
             if (WSAGetLastError() != WSAEWOULDBLOCK) {
                 connect_res = WSAGetLastError();
@@ -371,18 +371,17 @@
          * that the system chose for us and store it in the Socket object.
          */
         u_short port;
-        int len = SOCKETADDRESS_LEN(&him);
-        if (getsockname(fd, (struct sockaddr *)&him, &len) == -1) {
-
+        int len = sizeof(SOCKETADDRESS);
+        if (getsockname(fd, &him.sa, &len) == -1) {
             if (WSAGetLastError() == WSAENOTSOCK) {
                 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
-                        "Socket closed");
+                                "Socket closed");
             } else {
                 NET_ThrowCurrent(env, "getsockname failed");
             }
             return;
         }
-        port = ntohs ((u_short)GET_PORT(&him));
+        port = ntohs((u_short)GET_PORT(&him));
         (*env)->SetIntField(env, this, psi_localportID, (int) port);
     }
 }
@@ -400,7 +399,7 @@
     /* fdObj is the FileDescriptor field on this */
     jobject fdObj, fd1Obj;
     /* fd is an int field on fdObj */
-    int fd, fd1, len = 0;
+    int fd, fd1 = -1, len = 0;
     int ipv6_supported = ipv6_available();
 
     /* family is an int field of iaObj */
@@ -435,9 +434,9 @@
         return;
     }
 
-    if (NET_InetAddressToSockaddr(env, iaObj, localport,
-                          (struct sockaddr *)&him, &len, JNI_FALSE) != 0) {
-      return;
+    if (NET_InetAddressToSockaddr(env, iaObj, localport, &him.sa, &len,
+                                  JNI_FALSE) != 0) {
+        return;
     }
     if (ipv6_supported) {
         struct ipv6bind v6bind;
@@ -473,7 +472,7 @@
             (*env)->SetObjectField(env, this, psi_fd1ID, NULL);
         }
     } else {
-        rv = NET_WinBind(fd, (struct sockaddr *)&him, len, exclBind);
+        rv = NET_WinBind(fd, &him.sa, len, exclBind);
     }
 
     if (rv == -1) {
@@ -489,17 +488,16 @@
         /* Now that we're a bound socket, let's extract the port number
          * that the system chose for us and store it in the Socket object.
          */
-        int len = SOCKETADDRESS_LEN(&him);
+        int len = sizeof(SOCKETADDRESS);
         u_short port;
-        fd = him.him.sa_family == AF_INET? fd: fd1;
 
-        if (getsockname(fd, (struct sockaddr *)&him, &len) == -1) {
+        if (getsockname(him.sa.sa_family == AF_INET ? fd: fd1, &him.sa, &len) == -1) {
             NET_ThrowCurrent(env, "getsockname in plain socketBind");
             return;
         }
-        port = ntohs ((u_short) GET_PORT (&him));
+        port = ntohs((u_short) GET_PORT (&him));
 
-        (*env)->SetIntField(env, this, psi_localportID, (int) port);
+        (*env)->SetIntField(env, this, psi_localportID, (int)port);
     } else {
         (*env)->SetIntField(env, this, psi_localportID, localport);
     }
@@ -511,16 +509,17 @@
  * Signature: (I)V
  */
 JNIEXPORT void JNICALL
-Java_java_net_TwoStacksPlainSocketImpl_socketListen (JNIEnv *env, jobject this,
-                                            jint count)
+Java_java_net_TwoStacksPlainSocketImpl_socketListen
+  (JNIEnv *env, jobject this, jint count)
 {
     /* this FileDescriptor fd field */
     jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
     jobject fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID);
     jobject address;
     /* fdObj's int fd field */
-    int fd, fd1;
-    SOCKETADDRESS addr; int addrlen;
+    int fd = INVALID_SOCKET, fd1 = INVALID_SOCKET;
+    SOCKETADDRESS addr;
+    int addrlen;
 
     if (IS_NULL(fdObj) && IS_NULL(fd1Obj)) {
         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
@@ -540,12 +539,12 @@
         JNU_ThrowNullPointerException(env, "socket address");
         return;
     }
-    if (NET_InetAddressToSockaddr(env, address, 0, (struct sockaddr *)&addr,
-                                  &addrlen, JNI_FALSE) != 0) {
-      return;
+    if (NET_InetAddressToSockaddr(env, address, 0, &addr.sa, &addrlen,
+                                  JNI_FALSE) != 0) {
+        return;
     }
 
-    if (addr.him.sa_family == AF_INET || IN6ADDR_ISANY(&addr.him6)) {
+    if (addr.sa.sa_family == AF_INET || IN6ADDR_ISANY(&addr.sa6)) {
         /* listen on v4 */
         if (listen(fd, count) == -1) {
             NET_ThrowCurrent(env, "listen failed");
@@ -556,7 +555,7 @@
     }
     if (ipv6_available() && !IS_NULL(fd1Obj)) {
         fd1 = (*env)->GetIntField(env, fd1Obj, IO_fd_fdID);
-        if (addr.him.sa_family == AF_INET6 || addr.him4.sin_addr.s_addr == INADDR_ANY) {
+        if (addr.sa.sa_family == AF_INET6 || addr.sa4.sin_addr.s_addr == INADDR_ANY) {
             /* listen on v6 */
             if (listen(fd1, count) == -1) {
                 NET_ThrowCurrent(env, "listen failed");
@@ -687,7 +686,7 @@
             }
         }
     }
-    fd = accept(fd, (struct sockaddr *)&him, &len);
+    fd = accept(fd, &him.sa, &len);
     if (fd < 0) {
         /* REMIND: SOCKET CLOSED PROBLEM */
         if (fd == -2) {
@@ -702,7 +701,7 @@
     SetHandleInformation((HANDLE)(UINT_PTR)fd, HANDLE_FLAG_INHERIT, 0);
     (*env)->SetIntField(env, socketFdObj, IO_fd_fdID, fd);
 
-    if (him.him.sa_family == AF_INET) {
+    if (him.sa.sa_family == AF_INET) {
         if (inet4Cls == NULL) {
             jclass c = (*env)->FindClass(env, "java/net/Inet4Address");
             if (c != NULL) {
@@ -728,7 +727,7 @@
             return;
         }
 
-        setInetAddress_addr(env, socketAddressObj, ntohl(him.him4.sin_addr.s_addr));
+        setInetAddress_addr(env, socketAddressObj, ntohl(him.sa4.sin_addr.s_addr));
         setInetAddress_family(env, socketAddressObj, IPv4);
         (*env)->SetObjectField(env, socket, psi_addressID, socketAddressObj);
     } else {
@@ -754,9 +753,9 @@
             NET_SocketClose(fd);
             return;
         }
-        setInet6Address_ipaddress(env, socketAddressObj, (char *)&him.him6.sin6_addr);
+        setInet6Address_ipaddress(env, socketAddressObj, (char *)&him.sa6.sin6_addr);
         setInetAddress_family(env, socketAddressObj, IPv6);
-        setInet6Address_scopeid(env, socketAddressObj, him.him6.sin6_scope_id);
+        setInet6Address_scopeid(env, socketAddressObj, him.sa6.sin6_scope_id);
 
     }
     /* fields common to AF_INET and AF_INET6 */
@@ -1036,13 +1035,12 @@
      */
     if (opt == java_net_SocketOptions_SO_BINDADDR) {
         SOCKETADDRESS him;
-        int len;
+        int len = sizeof(SOCKETADDRESS);
         int port;
         jobject iaObj;
         jclass iaCntrClass;
         jfieldID iaFieldID;
 
-        len = sizeof(him);
         memset((char *)&him, 0, len);
 
         if (fd == -1) {
@@ -1052,12 +1050,12 @@
             fd = getFD1 (env, this);
         }
 
-        if (getsockname(fd, (struct sockaddr *)&him, &len) < 0) {
+        if (getsockname(fd, &him.sa, &len) < 0) {
             JNU_ThrowByNameWithMessageAndLastError
                 (env, JNU_JAVANETPKG "SocketException", "Error getting socket name");
             return -1;
         }
-        iaObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&him, &port);
+        iaObj = NET_SockaddrToInetAddress(env, &him.sa, &port);
         CHECK_NULL_RETURN(iaObj, -1);
 
         iaCntrClass = (*env)->GetObjectClass(env, iaContainerObj);
--- a/jdk/src/java.base/windows/native/libnet/net_util_md.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/windows/native/libnet/net_util_md.c	Mon Oct 10 22:42:45 2016 +0200
@@ -668,21 +668,21 @@
  */
 
 JNIEXPORT int JNICALL
-NET_BindV6(struct ipv6bind* b, jboolean exclBind) {
+NET_BindV6(struct ipv6bind *b, jboolean exclBind) {
     int fd=-1, ofd=-1, rv, len;
     /* need to defer close until new sockets created */
     int close_fd=-1, close_ofd=-1;
     SOCKETADDRESS oaddr; /* other address to bind */
-    int family = b->addr->him.sa_family;
+    int family = b->addr->sa.sa_family;
     int ofamily;
     u_short port; /* requested port parameter */
     u_short bound_port;
 
-    if (family == AF_INET && (b->addr->him4.sin_addr.s_addr != INADDR_ANY)) {
+    if (family == AF_INET && (b->addr->sa4.sin_addr.s_addr != INADDR_ANY)) {
         /* bind to v4 only */
         int ret;
-        ret = NET_WinBind ((int)b->ipv4_fd, (struct sockaddr *)b->addr,
-                                sizeof (struct sockaddr_in), exclBind);
+        ret = NET_WinBind((int)b->ipv4_fd, (struct sockaddr *)b->addr,
+                                sizeof(SOCKETADDRESS), exclBind);
         if (ret == SOCKET_ERROR) {
             CLOSE_SOCKETS_AND_RETURN;
         }
@@ -690,11 +690,11 @@
         b->ipv6_fd = -1;
         return 0;
     }
-    if (family == AF_INET6 && (!IN6_IS_ADDR_ANY(&b->addr->him6.sin6_addr))) {
+    if (family == AF_INET6 && (!IN6_IS_ADDR_ANY(&b->addr->sa6.sin6_addr))) {
         /* bind to v6 only */
         int ret;
-        ret = NET_WinBind ((int)b->ipv6_fd, (struct sockaddr *)b->addr,
-                                sizeof (struct SOCKADDR_IN6), exclBind);
+        ret = NET_WinBind((int)b->ipv6_fd, (struct sockaddr *)b->addr,
+                          sizeof(SOCKETADDRESS), exclBind);
         if (ret == SOCKET_ERROR) {
             CLOSE_SOCKETS_AND_RETURN;
         }
@@ -711,32 +711,32 @@
         fd = (int)b->ipv4_fd;
         ofd = (int)b->ipv6_fd;
         port = (u_short)GET_PORT (b->addr);
-        IN6ADDR_SETANY (&oaddr.him6);
-        oaddr.him6.sin6_port = port;
+        IN6ADDR_SETANY(&oaddr.sa6);
+        oaddr.sa6.sin6_port = port;
     } else {
         ofamily = AF_INET;
         ofd = (int)b->ipv4_fd;
         fd = (int)b->ipv6_fd;
         port = (u_short)GET_PORT (b->addr);
-        oaddr.him4.sin_family = AF_INET;
-        oaddr.him4.sin_port = port;
-        oaddr.him4.sin_addr.s_addr = INADDR_ANY;
+        oaddr.sa4.sin_family = AF_INET;
+        oaddr.sa4.sin_port = port;
+        oaddr.sa4.sin_addr.s_addr = INADDR_ANY;
     }
 
-    rv = NET_WinBind(fd, (struct sockaddr *)b->addr, SOCKETADDRESS_LEN(b->addr), exclBind);
+    rv = NET_WinBind(fd, (struct sockaddr *)b->addr, sizeof(SOCKETADDRESS), exclBind);
     if (rv == SOCKET_ERROR) {
         CLOSE_SOCKETS_AND_RETURN;
     }
 
     /* get the port and set it in the other address */
-    len = SOCKETADDRESS_LEN(b->addr);
+    len = sizeof(SOCKETADDRESS);
     if (getsockname(fd, (struct sockaddr *)b->addr, &len) == -1) {
         CLOSE_SOCKETS_AND_RETURN;
     }
     bound_port = GET_PORT (b->addr);
     SET_PORT (&oaddr, bound_port);
-    if ((rv=NET_WinBind (ofd, (struct sockaddr *) &oaddr,
-                         SOCKETADDRESS_LEN (&oaddr), exclBind)) == SOCKET_ERROR) {
+    if ((rv = NET_WinBind(ofd, &oaddr.sa,
+                          sizeof(SOCKETADDRESS), exclBind)) == SOCKET_ERROR) {
         int retries;
         int sotype, arglen=sizeof(sotype);
 
@@ -772,8 +772,7 @@
 
             /* bind random port on first socket */
             SET_PORT (&oaddr, 0);
-            rv = NET_WinBind (ofd, (struct sockaddr *)&oaddr, SOCKETADDRESS_LEN(&oaddr),
-                              exclBind);
+            rv = NET_WinBind(ofd, &oaddr.sa, sizeof(SOCKETADDRESS), exclBind);
             if (rv == SOCKET_ERROR) {
                 CLOSE_SOCKETS_AND_RETURN;
             }
@@ -783,14 +782,14 @@
             close_fd = close_ofd = -1;
 
             /* bind new port on second socket */
-            len = SOCKETADDRESS_LEN(&oaddr);
-            if (getsockname(ofd, (struct sockaddr *)&oaddr, &len) == -1) {
+            len = sizeof(SOCKETADDRESS);
+            if (getsockname(ofd, &oaddr.sa, &len) == -1) {
                 CLOSE_SOCKETS_AND_RETURN;
             }
             bound_port = GET_PORT (&oaddr);
             SET_PORT (b->addr, bound_port);
-            rv = NET_WinBind (fd, (struct sockaddr *)b->addr, SOCKETADDRESS_LEN(b->addr),
-                              exclBind);
+            rv = NET_WinBind(fd, (struct sockaddr *)b->addr,
+                             sizeof(SOCKETADDRESS), exclBind);
 
             if (rv != SOCKET_ERROR) {
                 if (family == AF_INET) {
@@ -826,9 +825,9 @@
     }
 
     ret = WSAIoctl(fd, SIO_ROUTING_INTERFACE_QUERY,
-                    (void *)target_addr, sizeof(struct sockaddr_in6),
-                    (void *)&route, sizeof(struct sockaddr_in6),
-                    &b, 0, 0);
+                   (void *)target_addr, sizeof(struct sockaddr_in6),
+                   (void *)&route, sizeof(struct sockaddr_in6),
+                   &b, 0, 0);
     if (ret == SOCKET_ERROR) {
         // error
         closesocket(fd);
@@ -909,13 +908,13 @@
         him6->sin6_scope_id = scopeid != 0 ? scopeid : cached_scope_id;
         *len = sizeof(struct SOCKADDR_IN6) ;
     } else {
-        struct sockaddr_in *him4 = (struct sockaddr_in*)him;
+        struct sockaddr_in *him4 = (struct sockaddr_in *)him;
         jint address;
         if (family != AF_INET) {
           JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Protocol family unavailable");
           return -1;
         }
-        memset((char *) him4, 0, sizeof(struct sockaddr_in));
+        memset((char *)him4, 0, sizeof(struct sockaddr_in));
         address = getInetAddress_addr(env, iaObj);
         him4->sin_port = htons((short) port);
         him4->sin_addr.s_addr = (u_long) htonl(address);
@@ -928,9 +927,9 @@
 JNIEXPORT jint JNICALL
 NET_GetPortFromSockaddr(struct sockaddr *him) {
     if (him->sa_family == AF_INET6) {
-        return ntohs(((struct sockaddr_in6*)him)->sin6_port);
+        return ntohs(((struct sockaddr_in6 *)him)->sin6_port);
     } else {
-        return ntohs(((struct sockaddr_in*)him)->sin_port);
+        return ntohs(((struct sockaddr_in *)him)->sin_port);
     }
 }
 
@@ -966,12 +965,12 @@
     return 1;
 }
 
-int getScopeID (struct sockaddr *him) {
+int getScopeID(struct sockaddr *him) {
     struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
     return him6->sin6_scope_id;
 }
 
-int cmpScopeID (unsigned int scope, struct sockaddr *him) {
+int cmpScopeID(unsigned int scope, struct sockaddr *him) {
     struct SOCKADDR_IN6 *him6 = (struct SOCKADDR_IN6 *)him;
     return him6->sin6_scope_id == scope;
 }
--- a/jdk/src/java.base/windows/native/libnet/net_util_md.h	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/java.base/windows/native/libnet/net_util_md.h	Mon Oct 10 22:42:45 2016 +0200
@@ -247,9 +247,9 @@
 int NET_GetDefaultTOS(void);
 
 typedef union {
-    struct sockaddr     him;
-    struct sockaddr_in  him4;
-    struct SOCKADDR_IN6 him6;
+    struct sockaddr     sa;
+    struct sockaddr_in  sa4;
+    struct SOCKADDR_IN6 sa6;
 } SOCKETADDRESS;
 
 /*
@@ -257,15 +257,11 @@
  * sockets. On return they may refer to different sockets.
  */
 struct ipv6bind {
-    SOCKETADDRESS       *addr;
-    SOCKET               ipv4_fd;
-    SOCKET               ipv6_fd;
+    SOCKETADDRESS      *addr;
+    SOCKET              ipv4_fd;
+    SOCKET              ipv6_fd;
 };
 
-#define SOCKETADDRESS_LEN(X)    \
-        (((X)->him.sa_family==AF_INET6)? sizeof(struct SOCKADDR_IN6) : \
-                         sizeof(struct sockaddr_in))
-
 #define SOCKETADDRESS_COPY(DST,SRC) {                           \
     if ((SRC)->sa_family == AF_INET6) {                         \
         memcpy ((DST), (SRC), sizeof (struct SOCKADDR_IN6));    \
@@ -274,20 +270,20 @@
     }                                                           \
 }
 
-#define SET_PORT(X,Y) {                         \
-    if ((X)->him.sa_family == AF_INET) {        \
-        (X)->him4.sin_port = (Y);               \
-    } else {                                    \
-        (X)->him6.sin6_port = (Y);              \
-    }                                           \
+#define SET_PORT(X,Y) {                    \
+    if ((X)->sa.sa_family == AF_INET) {    \
+        (X)->sa4.sin_port = (Y);           \
+    } else {                               \
+        (X)->sa6.sin6_port = (Y);          \
+    }                                      \
 }
 
-#define GET_PORT(X) ((X)->him.sa_family==AF_INET ?(X)->him4.sin_port: (X)->him6.sin6_port)
+#define GET_PORT(X) ((X)->sa.sa_family == AF_INET ? (X)->sa4.sin_port : (X)->sa6.sin6_port)
 
 #define IS_LOOPBACK_ADDRESS(x) ( \
-    ((x)->him.sa_family == AF_INET) ? \
-        (ntohl((x)->him4.sin_addr.s_addr)==INADDR_LOOPBACK) : \
-        (IN6ADDR_ISLOOPBACK (x)) \
+    ((x)->sa.sa_family == AF_INET) ? \
+        (ntohl((x)->sa4.sin_addr.s_addr) == INADDR_LOOPBACK) : \
+        (IN6ADDR_ISLOOPBACK(x)) \
 )
 
 JNIEXPORT int JNICALL NET_SocketClose(int fd);
@@ -297,7 +293,7 @@
 int NET_Socket(int domain, int type, int protocol);
 
 void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
-         const char *defaultDetail);
+                                  const char *defaultDetail);
 
 /*
  * differs from NET_Timeout() as follows:
@@ -312,46 +308,39 @@
  */
 JNIEXPORT int JNICALL NET_Timeout2(int fd, int fd1, long timeout, int *fdret);
 
-JNIEXPORT int JNICALL NET_BindV6(struct ipv6bind* b, jboolean exclBind);
-
-#define NET_WAIT_READ   0x01
-#define NET_WAIT_WRITE  0x02
-#define NET_WAIT_CONNECT        0x04
-
-extern jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);
+JNIEXPORT int JNICALL NET_BindV6(struct ipv6bind *b, jboolean exclBind);
 
 JNIEXPORT int JNICALL NET_WinBind(int s, struct sockaddr *him, int len,
-                                   jboolean exclBind);
+                                  jboolean exclBind);
 
 /* XP versions of the native routines */
 
 JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0_XP
-    (JNIEnv *env, jclass cls, jstring name);
+  (JNIEnv *env, jclass cls, jstring name);
 
 JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByIndex0_XP
   (JNIEnv *env, jclass cls, jint index);
 
 JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0_XP
-    (JNIEnv *env, jclass cls, jobject iaObj);
+  (JNIEnv *env, jclass cls, jobject iaObj);
 
 JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll_XP
-    (JNIEnv *env, jclass cls);
+  (JNIEnv *env, jclass cls);
 
 JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0_XP
-(JNIEnv *env, jclass cls, jstring name, jint index);
+  (JNIEnv *env, jclass cls, jstring name, jint index);
 
 JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0_XP
-(JNIEnv *env, jclass cls, jstring name, jint index);
+  (JNIEnv *env, jclass cls, jstring name, jint index);
 
 JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0_XP
-(JNIEnv *env, jclass cls, jstring name, jint index);
+  (JNIEnv *env, jclass cls, jstring name, jint index);
 
 JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0_XP
-(JNIEnv *env, jclass cls, jstring name, jint index);
+  (JNIEnv *env, jclass cls, jstring name, jint index);
 
 JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0_XP
-(JNIEnv *env, jclass class, jstring name, jint index);
+  (JNIEnv *env, jclass class, jstring name, jint index);
 
 JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0_XP
-(JNIEnv *env, jclass cls, jstring name, jint index);
-
+  (JNIEnv *env, jclass cls, jstring name, jint index);
--- a/jdk/src/jdk.sctp/unix/native/libsctp/SctpChannelImpl.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/jdk.sctp/unix/native/libsctp/SctpChannelImpl.c	Mon Oct 10 22:42:45 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -417,8 +417,8 @@
 JNIEXPORT jint JNICALL Java_sun_nio_ch_sctp_SctpChannelImpl_receive0
   (JNIEnv *env, jclass klass, jint fd, jobject resultContainerObj,
    jlong address, jint length, jboolean peek) {
-    SOCKADDR sa;
-    int sa_len = sizeof(sa);
+    SOCKETADDRESS sa;
+    int sa_len = sizeof(SOCKETADDRESS);
     ssize_t rv = 0;
     jlong *addr = jlong_to_ptr(address);
     struct iovec iov[1];
@@ -501,7 +501,7 @@
             snp = (union sctp_notification *) bufp;
             if (handleNotification(env, fd, resultContainerObj, snp, rv,
                                    (msg->msg_flags & MSG_EOR),
-                                   (struct sockaddr*)&sa ) == JNI_TRUE) {
+                                   &sa.sa) == JNI_TRUE) {
                 /* We have received a notification that is of interest
                    to the Java API. The appropriate notification will be
                    set in the result container. */
@@ -524,7 +524,7 @@
     } while (msg->msg_flags & MSG_NOTIFICATION);
 
     handleMessage(env, resultContainerObj, msg, rv,
-            (msg->msg_flags & MSG_EOR), (struct sockaddr*)&sa);
+            (msg->msg_flags & MSG_EOR), &sa.sa);
     return rv;
 }
 
@@ -537,8 +537,8 @@
   (JNIEnv *env, jclass klass, jint fd, jlong address, jint length,
    jobject targetAddress, jint targetPort, jint assocId, jint streamNumber,
    jboolean unordered, jint ppid) {
-    SOCKADDR sa;
-    int sa_len = sizeof(sa);
+    SOCKETADDRESS sa;
+    int sa_len = sizeof(SOCKETADDRESS);
     ssize_t rv = 0;
     jlong *addr = jlong_to_ptr(address);
     struct iovec iov[1];
@@ -555,8 +555,7 @@
      *    Association already existing, assocId != -1, targetAddress = preferred addr
      */
     if (targetAddress != NULL /*&& assocId <= 0*/) {
-        if (NET_InetAddressToSockaddr(env, targetAddress, targetPort,
-                                      (struct sockaddr *)&sa,
+        if (NET_InetAddressToSockaddr(env, targetAddress, targetPort, &sa.sa,
                                       &sa_len, JNI_TRUE) != 0) {
             return IOS_THROWN;
         }
--- a/jdk/src/jdk.sctp/unix/native/libsctp/SctpNet.c	Mon Oct 10 13:28:44 2016 -0700
+++ b/jdk/src/jdk.sctp/unix/native/libsctp/SctpNet.c	Mon Oct 10 22:42:45 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -210,20 +210,20 @@
 JNIEXPORT void JNICALL Java_sun_nio_ch_sctp_SctpNet_bindx
   (JNIEnv *env, jclass klass, jint fd, jobjectArray addrs, jint port,
    jint addrsLength, jboolean add, jboolean preferIPv6) {
-    SOCKADDR *sap, *tmpSap;
-    int i, sa_len = sizeof(SOCKADDR);
+    SOCKETADDRESS *sap, *tmpSap;
+    int i, sa_len = sizeof(SOCKETADDRESS);
     jobject ia;
 
     if (addrsLength < 1)
         return;
 
-    if ((sap = calloc(addrsLength,  sa_len)) == NULL) {
+    if ((sap = calloc(addrsLength, sa_len)) == NULL) {
           JNU_ThrowOutOfMemoryError(env, "heap allocation failure");
         return;
     }
 
     tmpSap = sap;
-    for (i=0; i<addrsLength; i++) {
+    for (i = 0; i < addrsLength; i++) {
         ia = (*env)->GetObjectArrayElement(env, addrs, i);
         if (NET_InetAddressToSockaddr(env, ia, port, (struct sockaddr*)tmpSap,
                                       &sa_len, preferIPv6) != 0) {
@@ -233,7 +233,7 @@
         tmpSap++;
     }
 
-    if (nio_sctp_bindx(fd, (void*)sap, addrsLength, add ? SCTP_BINDX_ADD_ADDR :
+    if (nio_sctp_bindx(fd, (void *)sap, addrsLength, add ? SCTP_BINDX_ADD_ADDR :
                        SCTP_BINDX_REM_ADDR) != 0) {
         handleSocketError(env, errno);
     }
@@ -261,16 +261,16 @@
 JNIEXPORT jint JNICALL
 Java_sun_nio_ch_sctp_SctpNet_connect0
   (JNIEnv *env, jclass clazz, int fd, jobject iao, jint port) {
-    SOCKADDR sa;
-    int sa_len = SOCKADDR_LEN;
+    SOCKETADDRESS sa;
+    int sa_len = sizeof(SOCKETADDRESS);
     int rv;
 
-    if (NET_InetAddressToSockaddr(env, iao, port, (struct sockaddr *) &sa,
+    if (NET_InetAddressToSockaddr(env, iao, port, &sa.sa,
                                   &sa_len, JNI_TRUE) != 0) {
         return IOS_THROWN;
     }
 
-    rv = connect(fd, (struct sockaddr *)&sa, sa_len);
+    rv = connect(fd, &sa.sa, sa_len);
     if (rv != 0) {
         if (errno == EINPROGRESS) {
             return IOS_UNAVAILABLE;