author | martin |
Tue, 15 Sep 2015 21:56:04 -0700 | |
changeset 32649 | 2ee9017c7597 |
parent 29986 | 97167d851fc4 |
permissions | -rw-r--r-- |
22341
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
1 |
/* |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
4 |
* |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
10 |
* |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
15 |
* accompanied this code). |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
16 |
* |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
20 |
* |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
23 |
* questions. |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
24 |
*/ |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
25 |
|
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
26 |
package sun.net; |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
27 |
|
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
28 |
import java.security.AccessController; |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
29 |
|
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
30 |
/** |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
31 |
* Determines the ephemeral port range in use on this system. |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
32 |
* If this cannot be determined, then the default settings |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
33 |
* of the OS are returned. |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
34 |
*/ |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
35 |
|
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
36 |
public final class PortConfig { |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
37 |
|
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
38 |
private static int defaultUpper, defaultLower; |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
29986
diff
changeset
|
39 |
private static final int upper, lower; |
22341
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
40 |
|
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
41 |
private PortConfig() {} |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
42 |
|
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
43 |
static { |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
44 |
AccessController.doPrivileged( |
29986
97167d851fc4
8078467: Update core libraries to use diamond with anonymous classes
darcy
parents:
25859
diff
changeset
|
45 |
new java.security.PrivilegedAction<>() { |
22341
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
46 |
public Void run() { |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
47 |
System.loadLibrary("net"); |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
48 |
String os = System.getProperty("os.name"); |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
49 |
if (os.startsWith("Linux")) { |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
50 |
defaultLower = 32768; |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
51 |
defaultUpper = 61000; |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
52 |
} else if (os.startsWith("SunOS")) { |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
53 |
defaultLower = 32768; |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
54 |
defaultUpper = 65535; |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
55 |
} else if (os.contains("OS X")) { |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
56 |
defaultLower = 49152; |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
57 |
defaultUpper = 65535; |
23016
1805013d2034
8033154: PPC64: Fix AIX build after integration into jdk9/dev
simonis
parents:
22341
diff
changeset
|
58 |
} else if (os.startsWith("AIX")) { |
1805013d2034
8033154: PPC64: Fix AIX build after integration into jdk9/dev
simonis
parents:
22341
diff
changeset
|
59 |
// The ephemeral port is OS version dependent on AIX: |
1805013d2034
8033154: PPC64: Fix AIX build after integration into jdk9/dev
simonis
parents:
22341
diff
changeset
|
60 |
// http://publib.boulder.ibm.com/infocenter/aix/v7r1/topic/com.ibm.aix.rsct315.admin/bl503_ephport.htm |
1805013d2034
8033154: PPC64: Fix AIX build after integration into jdk9/dev
simonis
parents:
22341
diff
changeset
|
61 |
// However, on AIX 5.3 / 6.1 / 7.1 we always see the |
1805013d2034
8033154: PPC64: Fix AIX build after integration into jdk9/dev
simonis
parents:
22341
diff
changeset
|
62 |
// settings below by using: |
1805013d2034
8033154: PPC64: Fix AIX build after integration into jdk9/dev
simonis
parents:
22341
diff
changeset
|
63 |
// /usr/sbin/no -a | fgrep ephemeral |
1805013d2034
8033154: PPC64: Fix AIX build after integration into jdk9/dev
simonis
parents:
22341
diff
changeset
|
64 |
defaultLower = 32768; |
1805013d2034
8033154: PPC64: Fix AIX build after integration into jdk9/dev
simonis
parents:
22341
diff
changeset
|
65 |
defaultUpper = 65535; |
22341
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
66 |
} else { |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
67 |
throw new InternalError( |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
68 |
"sun.net.PortConfig: unknown OS"); |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
69 |
} |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
70 |
return null; |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
71 |
} |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
72 |
}); |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
73 |
|
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
74 |
int v = getLower0(); |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
75 |
if (v == -1) { |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
76 |
v = defaultLower; |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
77 |
} |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
78 |
lower = v; |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
79 |
|
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
80 |
v = getUpper0(); |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
81 |
if (v == -1) { |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
82 |
v = defaultUpper; |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
83 |
} |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
84 |
upper = v; |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
85 |
} |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
86 |
|
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
87 |
static native int getLower0(); |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
88 |
static native int getUpper0(); |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
89 |
|
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
90 |
public static int getLower() { |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
91 |
return lower; |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
92 |
} |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
93 |
|
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
94 |
public static int getUpper() { |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
95 |
return upper; |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
96 |
} |
4689530d03b9
8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff
changeset
|
97 |
} |