src/java.base/unix/classes/sun/net/PortConfig.java
author redestad
Wed, 17 Jul 2019 12:35:46 +0200
changeset 55693 9a97b1393e72
parent 47216 71c04702a3d5
permissions -rw-r--r--
8227587: Add internal privileged System.loadLibrary Reviewed-by: rriggs, mchung, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22341
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff changeset
     1
/*
55693
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
     2
 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
22341
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
55693
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    28
import sun.security.action.GetPropertyAction;
22341
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 {
55693
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    44
        jdk.internal.loader.BootLoader.loadLibrary("net");
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    45
        String os = GetPropertyAction.privilegedGetProperty("os.name");
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    46
        if (os.startsWith("Linux")) {
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    47
            defaultLower = 32768;
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    48
            defaultUpper = 61000;
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    49
        } else if (os.startsWith("SunOS")) {
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    50
            defaultLower = 32768;
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    51
            defaultUpper = 65535;
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    52
        } else if (os.contains("OS X")) {
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    53
            defaultLower = 49152;
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    54
            defaultUpper = 65535;
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    55
        } else if (os.startsWith("AIX")) {
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    56
            // The ephemeral port is OS version dependent on AIX:
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    57
            // http://publib.boulder.ibm.com/infocenter/aix/v7r1/topic/com.ibm.aix.rsct315.admin/bl503_ephport.htm
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    58
            // However, on AIX 5.3 / 6.1 / 7.1 we always see the
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    59
            // settings below by using:
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    60
            // /usr/sbin/no -a | fgrep ephemeral
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    61
            defaultLower = 32768;
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    62
            defaultUpper = 65535;
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    63
        } else {
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    64
            throw new InternalError(
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    65
                "sun.net.PortConfig: unknown OS");
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 47216
diff changeset
    66
        }
22341
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff changeset
    67
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff changeset
    68
        int v = getLower0();
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff changeset
    69
        if (v == -1) {
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff changeset
    70
            v = defaultLower;
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
        lower = v;
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
        v = getUpper0();
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 = defaultUpper;
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
        upper = 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
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff changeset
    81
    static native int getLower0();
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff changeset
    82
    static native int getUpper0();
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
    public static int getLower() {
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff changeset
    85
        return lower;
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
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff changeset
    88
    public static int getUpper() {
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff changeset
    89
        return upper;
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff changeset
    90
    }
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents:
diff changeset
    91
}