< prev index next >

src/java.base/unix/native/libnet/NetworkInterface.c

Print this page

        

@@ -1069,17 +1069,25 @@
     }
 
     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) {
             JNU_ThrowByNameWithMessageAndLastError
                 (env, JNU_JAVANETPKG "SocketException", "Socket creation failed");

@@ -1098,13 +1106,13 @@
  * if it fails return AF_INET6 socket.
  */
 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;
             }
         } else { // errno is not NOSUPPORT
< prev index next >