--- old/src/java.base/share/classes/java/net/InetAddress.java 2019-05-16 12:42:02.206569116 +0100 +++ new/src/java.base/share/classes/java/net/InetAddress.java 2019-05-16 12:42:01.946569125 +0100 @@ -308,7 +308,7 @@ String str = java.security.AccessController.doPrivileged( new GetPropertyAction("java.net.preferIPv6Addresses")); if (str == null) { - preferIPv6Address = PREFER_IPV4_VALUE; + preferIPv6Address = PREFER_IPV6_VALUE; } else if (str.equalsIgnoreCase("true")) { preferIPv6Address = PREFER_IPV6_VALUE; } else if (str.equalsIgnoreCase("false")) { --- old/src/java.base/unix/native/libnet/NetworkInterface.c 2019-05-16 12:42:02.982569089 +0100 +++ new/src/java.base/unix/native/libnet/NetworkInterface.c 2019-05-16 12:42:02.722569098 +0100 @@ -1071,13 +1071,21 @@ return prefix; } +static int socket0(int domain, int type, int protocol) { + if (domain == AF_INET) { + errno = EAFNOSUPPORT; + return -1; + } + return socket(domain, type, protocol); +} + /* * Opens a socket for further ioct calls. proto is one of AF_INET or AF_INET6. */ static int openSocket(JNIEnv *env, int proto) { int sock; - if ((sock = socket(proto, SOCK_DGRAM, 0)) < 0) { + if ((sock = socket0(proto, SOCK_DGRAM, 0)) < 0) { // If we lack support for this address family or protocol, // don't throw an exception. if (errno != EPROTONOSUPPORT && errno != EAFNOSUPPORT) { @@ -1100,9 +1108,9 @@ static int openSocketWithFallback(JNIEnv *env, const char *ifname) { int sock; - if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + if ((sock = socket0(AF_INET, SOCK_DGRAM, 0)) < 0) { if (errno == EPROTONOSUPPORT || errno == EAFNOSUPPORT) { - if ((sock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { + if ((sock = socket0(AF_INET6, SOCK_DGRAM, 0)) < 0) { JNU_ThrowByNameWithMessageAndLastError (env, JNU_JAVANETPKG "SocketException", "IPV6 Socket creation failed"); return -1; --- old/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c 2019-05-16 12:42:03.582569068 +0100 +++ new/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c 2019-05-16 12:42:03.330569077 +0100 @@ -890,6 +890,14 @@ } } +static int socket0(int domain, int type, int protocol) { + if (domain == AF_INET) { + errno = EAFNOSUPPORT; + return -1; + } + return socket(domain, type, protocol); +} + /* * Class: java_net_PlainDatagramSocketImpl * Method: datagramSocketCreate @@ -909,7 +917,7 @@ return; } - if ((fd = socket(domain, SOCK_DGRAM, 0)) == -1) { + if ((fd = socket0(domain, SOCK_DGRAM, 0)) == -1) { JNU_ThrowByNameWithMessageAndLastError (env, JNU_JAVANETPKG "SocketException", "Error creating socket"); return; --- old/src/java.base/unix/native/libnet/PlainSocketImpl.c 2019-05-16 12:42:04.162569048 +0100 +++ new/src/java.base/unix/native/libnet/PlainSocketImpl.c 2019-05-16 12:42:03.906569057 +0100 @@ -149,6 +149,14 @@ */ static jclass socketExceptionCls; +static int socket0(int domain, int type, int protocol) { + if (domain == AF_INET) { + errno = EAFNOSUPPORT; + return -1; + } + return socket(domain, type, protocol); +} + /* * Class: java_net_PlainSocketImpl * Method: socketCreate @@ -174,7 +182,7 @@ return; } - if ((fd = socket(domain, type, 0)) == -1) { + if ((fd = socket0(domain, type, 0)) == -1) { /* note: if you run out of fds, you may not be able to load * the exception class, and get a NoClassDefFoundError * instead. --- old/src/java.base/unix/native/libnet/net_util_md.c 2019-05-16 12:42:04.730569028 +0100 +++ new/src/java.base/unix/native/libnet/net_util_md.c 2019-05-16 12:42:04.478569037 +0100 @@ -280,12 +280,7 @@ jint IPv4_supported() { - int fd = socket(AF_INET, SOCK_STREAM, 0) ; - if (fd < 0) { - return JNI_FALSE; - } - close(fd); - return JNI_TRUE; + return JNI_FALSE; } #if defined(DONT_ENABLE_IPV6) --- old/src/java.base/unix/native/libnio/ch/Net.c 2019-05-16 12:42:05.298569009 +0100 +++ new/src/java.base/unix/native/libnio/ch/Net.c 2019-05-16 12:42:05.046569018 +0100 @@ -203,6 +203,14 @@ #endif } +static int socket0(int domain, int type, int protocol) { + if (domain == AF_INET) { + errno = EAFNOSUPPORT; + return -1; + } + return socket(domain, type, protocol); +} + JNIEXPORT jint JNICALL Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6, jboolean stream, jboolean reuse, jboolean ignored) @@ -211,7 +219,7 @@ int type = (stream ? SOCK_STREAM : SOCK_DGRAM); int domain = (ipv6_available() && preferIPv6) ? AF_INET6 : AF_INET; - fd = socket(domain, type, 0); + fd = socket0(domain, type, 0); if (fd < 0) { return handleSocketError(env, errno); }