< prev index next >

src/java.base/windows/native/libnet/net_util_md.h

Print this page
rev 53867 : 8250521: Configure initial RTO to use minimal retry for loopback connections on Windows
Reviewed-by: alanb
rev 53868 : 8255264: Support for identifying the full range of IPv4 localhost addresses on Windows
Reviewed-by: alanb

@@ -24,10 +24,11 @@
  */
 #include <winsock2.h>
 #include <WS2tcpip.h>
 #include <iphlpapi.h>
 #include <icmpapi.h>
+#include <mstcpip.h>
 
 /* used to disable connection reset messages on Windows XP */
 #ifndef SIO_UDP_CONNRESET
 #define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12)
 #endif

@@ -84,14 +85,39 @@
     }                                      \
 }
 
 #define GET_PORT(X) ((X)->sa.sa_family == AF_INET ? (X)->sa4.sin_port : (X)->sa6.sin6_port)
 
+/**
+ * With dual socket implementation the
+ * IPv4 addresseses might be mapped as IPv6.
+ * The IPv4 loopback adapter address ranges (127.0.0.0 through 127.255.255.255) will
+ * be mapped as the following IPv6 ::ffff:127.0.0.0 through ::ffff:127.255.255.255.
+ * For example, this is done by NET_InetAddressToSockaddr.
+ */
+#define IN6_IS_ADDR_V4MAPPED_LOOPBACK(x) ( \
+    (((x)->s6_words[0] == 0)               &&  \
+     ((x)->s6_words[1] == 0)               &&  \
+     ((x)->s6_words[2] == 0)               &&  \
+     ((x)->s6_words[3] == 0)               &&  \
+     ((x)->s6_words[4] == 0)               &&  \
+     ((x)->s6_words[5] == 0xFFFF)          &&  \
+     (((x)->s6_words[6] & 0x00FF) == 0x007F)) \
+)
+
+/**
+ * Check for IPv4 loopback adapter address ranges (127.0.0.0 through 127.255.255.255)
+ */
+#define IN4_IS_ADDR_NETLONG_LOOPBACK(l) ( \
+    ((l & 0xFF000000) == 0x7F000000) \
+)
+
 #define IS_LOOPBACK_ADDRESS(x) ( \
     ((x)->sa.sa_family == AF_INET) ? \
-        (ntohl((x)->sa4.sin_addr.s_addr) == INADDR_LOOPBACK) : \
-        (IN6ADDR_ISLOOPBACK(x)) \
+        (IN4_IS_ADDR_NETLONG_LOOPBACK(ntohl((x)->sa4.sin_addr.s_addr))) : \
+        ((IN6_IS_ADDR_LOOPBACK(&(x)->sa6.sin6_addr)) || \
+         (IN6_IS_ADDR_V4MAPPED_LOOPBACK(&(x)->sa6.sin6_addr))) \
 )
 
 JNIEXPORT int JNICALL NET_SocketClose(int fd);
 
 JNIEXPORT int JNICALL NET_Timeout(int fd, long timeout);

@@ -117,10 +143,12 @@
 JNIEXPORT int JNICALL NET_BindV6(struct ipv6bind *b, jboolean exclBind);
 
 JNIEXPORT int JNICALL NET_WinBind(int s, SOCKETADDRESS *sa, int len,
                                   jboolean exclBind);
 
+JNIEXPORT jint JNICALL NET_EnableFastTcpLoopbackConnect(int fd);
+
 /* XP versions of the native routines */
 
 JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0_XP
   (JNIEnv *env, jclass cls, jstring name);
 
< prev index next >