< prev index next >

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

Print this page

        

@@ -147,10 +147,18 @@
  * prevent the problem where socketCreate runs out of file
  * descriptors, and is then unable to load the exception class.
  */
 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
  * Signature: (ZZ)V */
 JNIEXPORT void JNICALL

@@ -172,11 +180,11 @@
     if (fdObj == NULL) {
         (*env)->ThrowNew(env, socketExceptionCls, "null fd object");
         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.
          */
         NET_ThrowNew(env, errno, "can't create socket");
< prev index next >