8202154: Remove unused code in java.base/windows/native/libnet
authorigerasim
Wed, 25 Apr 2018 18:30:38 -0700
changeset 49892 8bed781a8d9c
parent 49891 61b0342b5711
child 49893 e1e60f75cd39
8202154: Remove unused code in java.base/windows/native/libnet Reviewed-by: vtewari, clanger
src/java.base/windows/classes/java/net/DualStackPlainDatagramSocketImpl.java
src/java.base/windows/classes/sun/net/PortConfig.java
src/java.base/windows/native/libnet/DualStackPlainDatagramSocketImpl.c
src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c
src/java.base/windows/native/libnet/net_util_md.c
src/java.base/windows/native/libnet/net_util_md.h
src/java.base/windows/native/libnet/portconfig.c
--- a/src/java.base/windows/classes/java/net/DualStackPlainDatagramSocketImpl.java	Thu Apr 26 09:45:47 2018 +0900
+++ b/src/java.base/windows/classes/java/net/DualStackPlainDatagramSocketImpl.java	Wed Apr 25 18:30:38 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2018, 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
@@ -69,7 +69,7 @@
         if (fd == null)
             throw new SocketException("Socket closed");
 
-        int newfd = socketCreate(false /* v6Only */);
+        int newfd = socketCreate();
 
         fdAccess.set(fd, newfd);
     }
@@ -274,7 +274,7 @@
 
     private static native void initIDs();
 
-    private static native int socketCreate(boolean v6Only);
+    private static native int socketCreate();
 
     private static native void socketBind(int fd, InetAddress localAddress,
             int localport, boolean exclBind) throws SocketException;
--- a/src/java.base/windows/classes/sun/net/PortConfig.java	Thu Apr 26 09:45:47 2018 +0900
+++ b/src/java.base/windows/classes/sun/net/PortConfig.java	Wed Apr 25 18:30:38 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2018, 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
@@ -25,49 +25,21 @@
 
 package sun.net;
 
-import java.security.AccessController;
-
 /**
  * Determines the ephemeral port range in use on this system.
- * If this cannot be determined, then the default settings
- * of the OS are returned.
+ * On Windows we always use the default range.
  */
 
 public final class PortConfig {
 
-    private static int defaultUpper, defaultLower;
-    private static final int upper, lower;
-
-    static {
-        AccessController.doPrivileged(
-            new java.security.PrivilegedAction<Void>() {
-                public Void run() {
-                    System.loadLibrary("net");
-                    return null;
-                }
-            });
-
-        int v = getLower0();
-        if (v == -1) {
-            v = defaultLower;
-        }
-        lower = v;
-
-        v = getUpper0();
-        if (v == -1) {
-            v = defaultUpper;
-        }
-        upper = v;
-    }
-
-    static native int getLower0();
-    static native int getUpper0();
+    private static final int defaultLower = 49152;
+    private static final int defaultUpper = 65535;
 
     public static int getLower() {
-        return lower;
+        return defaultLower;
     }
 
     public static int getUpper() {
-        return upper;
+        return defaultUpper;
     }
 }
--- a/src/java.base/windows/native/libnet/DualStackPlainDatagramSocketImpl.c	Thu Apr 26 09:45:47 2018 +0900
+++ b/src/java.base/windows/native/libnet/DualStackPlainDatagramSocketImpl.c	Wed Apr 25 18:30:38 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2018, 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
@@ -92,10 +92,10 @@
 /*
  * Class:     java_net_DualStackPlainDatagramSocketImpl
  * Method:    socketCreate
- * Signature: (Z)I
+ * Signature: ()I
  */
 JNIEXPORT jint JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketCreate
-  (JNIEnv *env, jclass clazz, jboolean v6Only /*unused*/) {
+  (JNIEnv *env, jclass clazz) {
     int fd, rv, opt=0, t=TRUE;
     DWORD x1, x2; /* ignored result codes */
 
@@ -121,7 +121,7 @@
      * when the socket is connected.
      */
     t = FALSE;
-    WSAIoctl(fd ,SIO_UDP_CONNRESET ,&t ,sizeof(t) ,&x1 ,sizeof(x1) ,&x2 ,0 ,0);
+    WSAIoctl(fd, SIO_UDP_CONNRESET, &t, sizeof(t), &x1, sizeof(x1), &x2, 0, 0);
 
     return fd;
 }
@@ -158,7 +158,7 @@
 JNIEXPORT void JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketConnect
   (JNIEnv *env, jclass clazz, jint fd, jobject iaObj, jint port) {
     SOCKETADDRESS sa;
-    int rv, sa_len = 0, t = TRUE;
+    int rv, sa_len = 0, t;
     DWORD x1, x2; /* ignored result codes */
 
     if (NET_InetAddressToSockaddr(env, iaObj, port, &sa,
@@ -173,6 +173,7 @@
     }
 
     /* see comment in socketCreate */
+    t = TRUE;
     WSAIoctl(fd, SIO_UDP_CONNRESET, &t, sizeof(t), &x1, sizeof(x1), &x2, 0, 0);
 }
 
--- a/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c	Thu Apr 26 09:45:47 2018 +0900
+++ b/src/java.base/windows/native/libnet/TwoStacksPlainDatagramSocketImpl.c	Wed Apr 25 18:30:38 2018 -0700
@@ -63,13 +63,6 @@
 static jclass ia4_clazz;
 static jmethodID ia4_ctor;
 
-static CRITICAL_SECTION sizeCheckLock;
-
-/* Windows OS version is XP or better */
-static int xp_or_later = 0;
-/* Windows OS version is Windows 2000 or better */
-static int w2k_or_later = 0;
-
 /*
  * Notes about UDP/IPV6 on Windows (XP and 2003 server):
  *
@@ -137,182 +130,6 @@
 }
 
 /*
- * This function returns JNI_TRUE if the datagram size exceeds the underlying
- * provider's ability to send to the target address. The following OS
- * oddities have been observed :-
- *
- * 1. On Windows 95/98 if we try to send a datagram > 12k to an application
- *    on the same machine then the send will fail silently.
- *
- * 2. On Windows ME if we try to send a datagram > supported by underlying
- *    provider then send will not return an error.
- *
- * 3. On Windows NT/2000 if we exceeds the maximum size then send will fail
- *    with WSAEADDRNOTAVAIL.
- *
- * 4. On Windows 95/98 if we exceed the maximum size when sending to
- *    another machine then WSAEINVAL is returned.
- *
- */
-jboolean exceedSizeLimit(JNIEnv *env, jint fd, jint addr, jint size)
-{
-#define DEFAULT_MSG_SIZE        65527
-    static jboolean initDone;
-    static jboolean is95or98;
-    static int maxmsg;
-
-    typedef struct _netaddr  {          /* Windows 95/98 only */
-        unsigned long addr;
-        struct _netaddr *next;
-    } netaddr;
-    static netaddr *addrList;
-    netaddr *curr;
-
-    /*
-     * First time we are called we must determine which OS this is and also
-     * get the maximum size supported by the underlying provider.
-     *
-     * In addition on 95/98 we must enumerate our IP addresses.
-     */
-    if (!initDone) {
-        EnterCriticalSection(&sizeCheckLock);
-
-        if (initDone) {
-            /* another thread got there first */
-            LeaveCriticalSection(&sizeCheckLock);
-
-        } else {
-            OSVERSIONINFO ver;
-            int len;
-
-            /*
-             * Step 1: Determine which OS this is.
-             */
-            ver.dwOSVersionInfoSize = sizeof(ver);
-            GetVersionEx(&ver);
-
-            is95or98 = JNI_FALSE;
-            if (ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS &&
-                ver.dwMajorVersion == 4 &&
-                (ver.dwMinorVersion == 0 || ver.dwMinorVersion == 10)) {
-
-                is95or98 = JNI_TRUE;
-            }
-
-            /*
-             * Step 2: Determine the maximum datagram supported by the
-             * underlying provider. On Windows 95 if winsock hasn't been
-             * upgraded (ie: unsupported configuration) then we assume
-             * the default 64k limit.
-             */
-            len = sizeof(maxmsg);
-            if (NET_GetSockOpt(fd, SOL_SOCKET, SO_MAX_MSG_SIZE, (char *)&maxmsg, &len) < 0) {
-                maxmsg = DEFAULT_MSG_SIZE;
-            }
-
-            /*
-             * Step 3: On Windows 95/98 then enumerate the IP addresses on
-             * this machine. This is neccesary because we need to check if the
-             * datagram is being sent to an application on the same machine.
-             */
-            if (is95or98) {
-                char hostname[255];
-                struct hostent *hp;
-
-                if (gethostname(hostname, sizeof(hostname)) == -1) {
-                    LeaveCriticalSection(&sizeCheckLock);
-                    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Unable to obtain hostname");
-                    return JNI_TRUE;
-                }
-                hp = (struct hostent *)gethostbyname(hostname);
-                if (hp != NULL) {
-                    struct in_addr **addrp = (struct in_addr **) hp->h_addr_list;
-
-                    while (*addrp != (struct in_addr *) 0) {
-                        curr = (netaddr *)malloc(sizeof(netaddr));
-                        if (curr == NULL) {
-                            while (addrList != NULL) {
-                                curr = addrList->next;
-                                free(addrList);
-                                addrList = curr;
-                            }
-                            LeaveCriticalSection(&sizeCheckLock);
-                            JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
-                            return JNI_TRUE;
-                        }
-                        curr->addr = htonl((*addrp)->S_un.S_addr);
-                        curr->next = addrList;
-                        addrList = curr;
-                        addrp++;
-                    }
-                }
-            }
-
-            /*
-             * Step 4: initialization is done so set flag and unlock cs
-             */
-            initDone = JNI_TRUE;
-            LeaveCriticalSection(&sizeCheckLock);
-        }
-    }
-
-    /*
-     * Now examine the size of the datagram :-
-     *
-     * (a) If exceeds size of service provider return 'false' to indicate that
-     *     we exceed the limit.
-     * (b) If not 95/98 then return 'true' to indicate that the size is okay.
-     * (c) On 95/98 if the size is <12k we are okay.
-     * (d) On 95/98 if size > 12k then check if the destination is the current
-     *     machine.
-     */
-    if (size > maxmsg) {        /* step (a) */
-        return JNI_TRUE;
-    }
-    if (!is95or98) {            /* step (b) */
-        return JNI_FALSE;
-    }
-    if (size <= 12280) {        /* step (c) */
-        return JNI_FALSE;
-    }
-
-    /* step (d) */
-
-    if ((addr & 0x7f000000) == 0x7f000000) {
-        return JNI_TRUE;
-    }
-    curr = addrList;
-    while (curr != NULL) {
-        if (curr->addr == addr) {
-            return JNI_TRUE;
-        }
-        curr = curr->next;
-    }
-    return JNI_FALSE;
-}
-
-/*
- * Return JNI_TRUE if this Windows edition supports ICMP Port Unreachable
- */
-__inline static jboolean supportPortUnreachable() {
-    static jboolean initDone;
-    static jboolean portUnreachableSupported;
-
-    if (!initDone) {
-        OSVERSIONINFO ver;
-        ver.dwOSVersionInfoSize = sizeof(ver);
-        GetVersionEx(&ver);
-        if (ver.dwPlatformId == VER_PLATFORM_WIN32_NT && ver.dwMajorVersion >= 5) {
-            portUnreachableSupported = JNI_TRUE;
-        } else {
-            portUnreachableSupported = JNI_FALSE;
-        }
-        initDone = JNI_TRUE;
-    }
-    return portUnreachableSupported;
-}
-
-/*
  * This function "purges" all outstanding ICMP port unreachable packets
  * outstanding on a socket and returns JNI_TRUE if any ICMP messages
  * have been purged. The rational for purging is to emulate normal BSD
@@ -331,13 +148,6 @@
     memset((char *)&rmtaddr, 0, sizeof(rmtaddr));
 
     /*
-     * A no-op if this OS doesn't support it.
-     */
-    if (!supportPortUnreachable()) {
-        return JNI_FALSE;
-    }
-
-    /*
      * Peek at the queue to see if there is an ICMP port unreachable. If there
      * is then receive it.
      */
@@ -370,16 +180,6 @@
  */
 JNIEXPORT void JNICALL
 Java_java_net_TwoStacksPlainDatagramSocketImpl_init(JNIEnv *env, jclass cls) {
-
-    OSVERSIONINFO ver;
-    int version;
-    ver.dwOSVersionInfoSize = sizeof(ver);
-    GetVersionEx(&ver);
-
-    version = ver.dwMajorVersion * 10 + ver.dwMinorVersion;
-    xp_or_later = (ver.dwPlatformId == VER_PLATFORM_WIN32_NT) && (version >= 51);
-    w2k_or_later = (ver.dwPlatformId == VER_PLATFORM_WIN32_NT) && (version >= 50);
-
     /* get fieldIDs */
     pdsi_fdID = (*env)->GetFieldID(env, cls, "fd", "Ljava/io/FileDescriptor;");
     CHECK_NULL(pdsi_fdID);
@@ -409,9 +209,6 @@
     CHECK_NULL(ia4_clazz);
     ia4_ctor = (*env)->GetMethodID(env, ia4_clazz, "<init>", "()V");
     CHECK_NULL(ia4_ctor);
-
-
-    InitializeCriticalSection(&sizeCheckLock);
 }
 
 JNIEXPORT void JNICALL
@@ -524,6 +321,8 @@
     jint fd = -1, fd1 = -1, fdc, family;
     SOCKETADDRESS rmtaddr;
     int rmtaddrlen = 0;
+    DWORD x1, x2; /* ignored result codes */
+    int res, t;
 
     if (IS_NULL(fdObj) && IS_NULL(fd1Obj)) {
         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
@@ -553,16 +352,13 @@
 
     fdc = family == java_net_InetAddress_IPv4 ? fd : fd1;
 
-    if (xp_or_later) {
-        /* SIO_UDP_CONNRESET fixes a bug introduced in Windows 2000, which
-         * returns connection reset errors on connected UDP sockets (as well
-         * as connected sockets). The solution is to only enable this feature
-         * when the socket is connected
-         */
-        DWORD x1, x2; /* ignored result codes */
-        int res, t = TRUE;
-        res = WSAIoctl(fdc,SIO_UDP_CONNRESET,&t,sizeof(t),&x1,sizeof(x1),&x2,0,0);
-    }
+    /* SIO_UDP_CONNRESET fixes a bug introduced in Windows 2000, which
+     * returns connection reset errors on connected UDP sockets (as well
+     * as connected sockets). The solution is to only enable this feature
+     * when the socket is connected
+     */
+    t = TRUE;
+    res = WSAIoctl(fdc, SIO_UDP_CONNRESET, &t, sizeof(t), &x1, sizeof(x1), &x2, 0, 0);
 
     if (NET_InetAddressToSockaddr(env, address, port, &rmtaddr,
                                   &rmtaddrlen, JNI_FALSE) != 0) {
@@ -588,6 +384,8 @@
     /* The fdObj'fd */
     jint fd, len;
     SOCKETADDRESS addr;
+    DWORD x1 = 0, x2 = 0; /* ignored result codes */
+    int t;
 
     if (family == java_net_InetAddress_IPv4) {
         fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
@@ -610,11 +408,8 @@
      * use SIO_UDP_CONNRESET
      * to disable ICMP port unreachable handling here.
      */
-    if (xp_or_later) {
-        DWORD x1 = 0, x2 = 0; /* ignored result codes */
-        int t = FALSE;
-        WSAIoctl(fd,SIO_UDP_CONNRESET,&t,sizeof(t),&x1,sizeof(x1),&x2,0,0);
-    }
+    t = FALSE;
+    WSAIoctl(fd, SIO_UDP_CONNRESET, &t, sizeof(t), &x1, sizeof(x1), &x2, 0, 0);
 }
 
 /*
@@ -632,7 +427,6 @@
     jint fd;
 
     jobject iaObj;
-    jint address;
     jint family;
 
     jint packetBufferOffset, packetBufferLen, packetPort;
@@ -697,32 +491,6 @@
     }
 
     if (packetBufferLen > MAX_BUFFER_LEN) {
-
-        /*
-         * On 95/98 if we try to send a datagram >12k to an application
-         * on the same machine then this will fail silently. Thus we
-         * catch this situation here so that we can throw an exception
-         * when this arises.
-         * On ME if we try to send a datagram with a size greater than
-         * that supported by the service provider then no error is
-         * returned.
-         */
-        if (!w2k_or_later) { /* avoid this check on Win 2K or better. Does not work with IPv6.
-                      * Check is not necessary on these OSes */
-            if (connected) {
-                address = getInetAddress_addr(env, iaObj);
-            } else {
-                address = ntohl(rmtaddr.sa4.sin_addr.s_addr);
-            }
-
-            if (exceedSizeLimit(env, fd, address, packetBufferLen)) {
-                if (!((*env)->ExceptionOccurred(env))) {
-                    NET_ThrowNew(env, WSAEMSGSIZE, "Datagram send failed");
-                }
-                return;
-            }
-        }
-
         /* When JNI-ifying the JDK's IO routines, we turned
          * reads and writes of byte arrays of size greater
          * than 2048 bytes into several operations of size 2048.
@@ -1282,16 +1050,15 @@
 
 
     /*
-     * If this Windows edition supports ICMP port unreachable and if we
-     * are not connected then we need to know if a timeout has been specified
-     * and if so we need to pick up the current time. These are required in
-     * order to implement the semantics of timeout, viz :-
+     * If we are not connected then we need to know if a timeout has been
+     * specified and if so we need to pick up the current time. These are
+     * required in order to implement the semantics of timeout, viz :-
      * timeout set to t1 but ICMP port unreachable arrives in t2 where
      * t2 < t1. In this case we must discard the ICMP packets and then
      * wait for the next packet up to a maximum of t1 minus t2.
      */
     connected = (*env)->GetBooleanField(env, this, pdsi_connected);
-    if (supportPortUnreachable() && !connected && timeout &&!ipv6_supported) {
+    if (!connected && timeout && !ipv6_supported) {
         prevTime = JVM_CurrentTimeMillis(env, 0);
     }
 
--- a/src/java.base/windows/native/libnet/net_util_md.c	Thu Apr 26 09:45:47 2018 +0900
+++ b/src/java.base/windows/native/libnet/net_util_md.c	Wed Apr 25 18:30:38 2018 -0700
@@ -227,73 +227,9 @@
 
 jint reuseport_supported()
 {
-    /* SO_REUSEPORT is not supported onn Windows */
+    /* SO_REUSEPORT is not supported on Windows */
     return JNI_FALSE;
 }
-/*
- * Return the default TOS value
- */
-int NET_GetDefaultTOS() {
-    static int default_tos = -1;
-    OSVERSIONINFO ver;
-    HKEY hKey;
-    LONG ret;
-
-    /*
-     * If default ToS already determined then return it
-     */
-    if (default_tos >= 0) {
-        return default_tos;
-    }
-
-    /*
-     * Assume default is "normal service"
-     */
-    default_tos = 0;
-
-    /*
-     * Which OS is this?
-     */
-    ver.dwOSVersionInfoSize = sizeof(ver);
-    GetVersionEx(&ver);
-
-    /*
-     * If 2000 or greater then no default ToS in registry
-     */
-    if (ver.dwPlatformId == VER_PLATFORM_WIN32_NT) {
-        if (ver.dwMajorVersion >= 5) {
-            return default_tos;
-        }
-    }
-
-    /*
-     * Query the registry to see if a Default ToS has been set.
-     * Different registry entry for NT vs 95/98/ME.
-     */
-    if (ver.dwPlatformId == VER_PLATFORM_WIN32_NT) {
-        ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-                           "SYSTEM\\CurrentControlSet\\Services\\Tcp\\Parameters",
-                           0, KEY_READ, (PHKEY)&hKey);
-    } else {
-        ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-                           "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP\\Parameters",
-                           0, KEY_READ, (PHKEY)&hKey);
-    }
-    if (ret == ERROR_SUCCESS) {
-        DWORD dwLen;
-        DWORD dwDefaultTOS;
-        ULONG ulType;
-        dwLen = sizeof(dwDefaultTOS);
-
-        ret = RegQueryValueEx(hKey, "DefaultTOS",  NULL, &ulType,
-                             (LPBYTE)&dwDefaultTOS, &dwLen);
-        RegCloseKey(hKey);
-        if (ret == ERROR_SUCCESS) {
-            default_tos = (int)dwDefaultTOS;
-        }
-    }
-    return default_tos;
-}
 
 /* call NET_MapSocketOptionV6 for the IPv6 fd only
  * and NET_MapSocketOption for the IPv4 fd
@@ -454,10 +390,7 @@
         if (WSAGetLastError() == WSAENOPROTOOPT &&
             level == IPPROTO_IP && optname == IP_TOS) {
 
-            int *tos;
-            tos = (int *)optval;
-            *tos = NET_GetDefaultTOS();
-
+            *((int *)optval) = 0;
             rv = 0;
         }
     }
--- a/src/java.base/windows/native/libnet/net_util_md.h	Thu Apr 26 09:45:47 2018 +0900
+++ b/src/java.base/windows/native/libnet/net_util_md.h	Wed Apr 25 18:30:38 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -52,11 +52,6 @@
 
 void NET_ThrowCurrent(JNIEnv *env, char *msg);
 
-/*
- * Return default Type Of Service
- */
-int NET_GetDefaultTOS(void);
-
 typedef union {
     struct sockaddr     sa;
     struct sockaddr_in  sa4;
--- a/src/java.base/windows/native/libnet/portconfig.c	Thu Apr 26 09:45:47 2018 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2013, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#include <windows.h>
-#include "jni.h"
-#include "net_util.h"
-#include "sun_net_PortConfig.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct portrange {
-    int lower;
-    int higher;
-};
-
-static int getPortRange(struct portrange *range)
-{
-    OSVERSIONINFO ver;
-    ver.dwOSVersionInfoSize = sizeof(ver);
-    GetVersionEx(&ver);
-
-    /* Check for major version 5 or less = Windows XP/2003 or older */
-    if (ver.dwMajorVersion <= 5) {
-        LONG ret;
-        HKEY hKey;
-        range->lower = 1024;
-        range->higher = 4999;
-
-        /* check registry to see if upper limit was raised */
-        ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-                   "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
-                   0, KEY_READ, (PHKEY)&hKey
-        );
-        if (ret == ERROR_SUCCESS) {
-            DWORD maxuserport;
-            ULONG ulType;
-            DWORD dwLen = sizeof(maxuserport);
-            ret = RegQueryValueEx(hKey, "MaxUserPort",  NULL, &ulType,
-                             (LPBYTE)&maxuserport, &dwLen);
-            RegCloseKey(hKey);
-            if (ret == ERROR_SUCCESS) {
-                range->higher = maxuserport;
-            }
-        }
-    } else {
-        /* There doesn't seem to be an API to access this. "MaxUserPort"
-          * is affected, but is not sufficient to determine.
-         * so we just use the defaults, which are less likely to change
-          */
-        range->lower = 49152;
-        range->higher = 65535;
-    }
-    return 0;
-}
-
-/*
- * Class:     sun_net_PortConfig
- * Method:    getLower0
- * Signature: ()I
- */
-JNIEXPORT jint JNICALL Java_sun_net_PortConfig_getLower0
-  (JNIEnv *env, jclass clazz)
-{
-    struct portrange range;
-    getPortRange(&range);
-    return range.lower;
-}
-
-/*
- * Class:     sun_net_PortConfig
- * Method:    getUpper0
- * Signature: ()I
- */
-JNIEXPORT jint JNICALL Java_sun_net_PortConfig_getUpper0
-  (JNIEnv *env, jclass clazz)
-{
-    struct portrange range;
-    getPortRange(&range);
-    return range.higher;
-}
-#ifdef __cplusplus
-}
-#endif