/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
private Net() { }
// unspecified protocol family
return "UNSPEC";
}
};
// Value of jdk.net.revealLocalAddress
private static boolean revealLocalAddress;
// True if jdk.net.revealLocalAddress had been read
private static volatile boolean propRevealLocalAddress;
// set to true if exclusive binding is on for Windows
private static final boolean exclusiveBind;
static {
int availLevel = isExclusiveBindAvailable();
if (availLevel >= 0) {
new PrivilegedAction<String>() {
return System.getProperty(
"sun.net.useExclusiveBind");
}
});
if (exclBindProp != null) {
} else if (availLevel == 1) {
exclusiveBind = true;
} else {
exclusiveBind = false;
}
} else {
exclusiveBind = false;
}
}
// -- Miscellaneous utilities --
private static volatile boolean checkedIPv6 = false;
private static volatile boolean isIPv6Available;
/**
*/
static boolean isIPv6Available() {
if (!checkedIPv6) {
checkedIPv6 = true;
}
return isIPv6Available;
}
/**
* Returns true if exclusive binding is on
*/
static boolean useExclusiveBind() {
return exclusiveBind;
}
/**
* Tells whether IPv6 sockets can join IPv4 multicast groups
*/
static boolean canIPv6SocketJoinIPv4Group() {
return canIPv6SocketJoinIPv4Group0();
}
/**
* Tells whether {@link #join6} can be used to join an IPv4
* multicast group (IPv4 group as IPv4-mapped IPv6 address)
*/
static boolean canJoin6WithIPv4Group() {
return canJoin6WithIPv4Group0();
}
throw new NullPointerException();
if (!(sa instanceof InetSocketAddress))
throw new UnsupportedAddressTypeException(); // ## needs arg
if (isa.isUnresolved())
throw new UnresolvedAddressException(); // ## needs arg
throw new IllegalArgumentException("Invalid address type");
return isa;
}
if (!(sa instanceof InetSocketAddress))
throw new UnsupportedAddressTypeException();
return (InetSocketAddress)sa;
}
throws SocketException
{
if (x instanceof SocketException)
throw (SocketException)x;
if (x instanceof ClosedChannelException)
else if (x instanceof NotYetConnectedException)
else if (x instanceof AlreadyBoundException)
else if (x instanceof NotYetBoundException)
else if (x instanceof UnsupportedAddressTypeException)
else if (x instanceof UnresolvedAddressException) {
}
if (nx != x)
if (nx instanceof SocketException)
throw (SocketException)nx;
else if (nx instanceof RuntimeException)
throw (RuntimeException)nx;
else
}
boolean unknownHostForUnresolved)
throws IOException
{
if (x instanceof IOException)
throw (IOException)x;
// Throw UnknownHostException from here since it cannot
// be thrown as a SocketException
if (unknownHostForUnresolved &&
(x instanceof UnresolvedAddressException))
{
throw new UnknownHostException();
}
}
throws IOException
{
translateException(x, false);
}
/**
* Returns the local address after performing a SecurityManager#checkConnect.
*/
return addr;
if (!getRevealLocalAddress()) {
// Return loopback address only if security check fails
try{
//Security check passed
} catch (SecurityException e) {
//Return loopback address
}
}
return addr;
}
}
private static boolean getRevealLocalAddress() {
if (!propRevealLocalAddress) {
try {
new PrivilegedExceptionAction<String>() {
return System.getProperty(
"jdk.net.revealLocalAddress");
}
}));
} catch (Exception e) {
// revealLocalAddress is false
}
propRevealLocalAddress = true;
}
return revealLocalAddress;
}
port);
}
/**
* Returns any IPv4 address of the given network interface, or
* null if the interface does not have any IPv4 addresses.
*/
public Inet4Address run() {
while (addrs.hasMoreElements()) {
if (addr instanceof Inet4Address) {
return (Inet4Address)addr;
}
}
return null;
}
});
}
/**
* Returns an IPv4 address as an int.
*/
if (ia instanceof Inet4Address) {
return address;
}
throw new AssertionError("Should not reach here");
}
/**
* Returns an InetAddress from the given IPv4 address
* represented as an int.
*/
byte[] addr = new byte[4];
try {
} catch (UnknownHostException uhe) {
throw new AssertionError("Should not reach here");
}
}
/**
* Returns an IPv6 address as a byte array
*/
if (ia instanceof Inet6Address) {
return ia.getAddress();
}
// need to construct IPv4-mapped address
if (ia instanceof Inet4Address) {
byte[] address = new byte[16];
return address;
}
throw new AssertionError("Should not reach here");
}
// -- Socket options
throws IOException
{
throw new IllegalArgumentException("Invalid option value");
// only simple values supported by this method
throw new AssertionError("Should not reach here");
// special handling
{
if (i < 0)
throw new IllegalArgumentException("Invalid send/receive buffer size");
}
if (i < 0)
if (i > 65535)
}
if (i < 0 || i > 255)
throw new IllegalArgumentException("Invalid IP_TOS value");
}
if (i < 0 || i > 255)
throw new IllegalArgumentException("Invalid TTL/hop value");
}
throw new AssertionError("Option not found");
int arg;
} else {
}
}
SocketOption<?> name)
throws IOException
{
// only simple values supported by this method
throw new AssertionError("Should not reach here");
throw new AssertionError("Option not found");
} else {
}
}
// -- Socket operations --
private static native boolean isIPv6Available0();
/*
* Returns 1 for Windows versions that support exclusive binding by default, 0
*/
private static native int isExclusiveBindAvailable();
private static native boolean canIPv6SocketJoinIPv4Group0();
private static native boolean canJoin6WithIPv4Group0();
}
throws IOException {
boolean preferIPv6 = isIPv6Available() &&
}
}
// Due to oddities SO_REUSEADDR on windows reuse is ignored
throws IOException
{
}
{
boolean preferIPv6 = isIPv6Available() &&
}
int port)
throws IOException;
throws IOException
{
}
throws IOException
{
boolean preferIPv6 = isIPv6Available() &&
}
int remotePort)
throws IOException;
throws IOException;
throws IOException;
throws IOException
{
}
throws IOException;
throws IOException;
throws IOException
{
}
throws IOException;
throws IOException;
// -- Multicast support --
/**
* Join IPv4 multicast group
*/
throws IOException
{
}
/**
* Drop membership of IPv4 multicast group
*/
throws IOException
{
}
private static native int joinOrDrop4(boolean join, FileDescriptor fd, int group, int interf, int source)
throws IOException;
/**
* Block IPv4 source
*/
throws IOException
{
}
/**
* Unblock IPv6 source
*/
throws IOException
{
}
throws IOException;
/**
* Join IPv6 multicast group
*/
throws IOException
{
}
/**
* Drop membership of IPv6 multicast group
*/
throws IOException
{
}
private static native int joinOrDrop6(boolean join, FileDescriptor fd, byte[] group, int index, byte[] source)
throws IOException;
/**
* Block IPv6 source
*/
throws IOException
{
}
/**
* Unblock IPv6 source
*/
throws IOException
{
}
static native int blockOrUnblock6(boolean block, FileDescriptor fd, byte[] group, int index, byte[] source)
throws IOException;
private static native void initIDs();
static {
initIDs();
}
}