2
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
27
import java.security.AccessController;
28
import java.security.PrivilegedAction;
31
* This class defines a factory for creating DatagramSocketImpls. It defaults
32
* to creating plain DatagramSocketImpls, but may create other DatagramSocketImpls
33
* by setting the impl.prefix system property.
35
* For Windows versions lower than Windows Vista a TwoStacksPlainDatagramSocketImpl
36
* is always created. This impl supports IPv6 on these platform where available.
38
* On Windows platforms greater than Vista that support a dual layer TCP/IP stack
39
* a DualStackPlainDatagramSocketImpl is created for DatagramSockets. For MulticastSockets
40
* a TwoStacksPlainDatagramSocketImpl is always created. This is to overcome the lack
41
* of behavior defined for multicasting over a dual layer socket by the RFC.
43
* @author Chris Hegarty
46
class DefaultDatagramSocketImplFactory
48
static Class prefixImplClass = null;
50
/* the windows version. */
51
private static float version;
53
/* java.net.preferIPv4Stack */
54
private static boolean preferIPv4Stack = false;
56
/* If the version supports a dual stack TCP implementation */
57
private static boolean useDualStackImpl = false;
60
// Determine Windows Version.
61
java.security.AccessController.doPrivileged( new PrivilegedAction<Object>() {
65
version = Float.parseFloat(System.getProperties().getProperty("os.version"));
66
preferIPv4Stack = Boolean.parseBoolean(
67
System.getProperties().getProperty("java.net.preferIPv4Stack"));
68
} catch (NumberFormatException e ) {
71
return null; // nothing to return
74
String ipv6 = ikvm.internal.Util.SafeGetEnvironmentVariable("IKVM_IPV6");
77
if ((Integer.parseInt(ipv6) & 4) == 0) {
78
preferIPv4Stack = true;
80
useDualStackImpl = true;
82
} catch (NumberFormatException _) {
84
} else if (!InetAddressImplFactory.isIPv6Supported()) {
85
preferIPv4Stack = true;
88
// (version >= 6.0) implies Vista or greater.
89
if (version >= 6.0 && !preferIPv4Stack) {
90
useDualStackImpl = true;
96
prefix = AccessController.doPrivileged(
97
new sun.security.action.GetPropertyAction("impl.prefix", null));
99
prefixImplClass = Class.forName("java.net."+prefix+"DatagramSocketImpl");
100
} catch (Exception e) {
101
System.err.println("Can't find class: java.net." +
103
"DatagramSocketImpl: check impl.prefix property");
108
* Creates a new <code>DatagramSocketImpl</code> instance.
110
* @param isMulticast true if this impl is to be used for a MutlicastSocket
111
* @return a new instance of <code>PlainDatagramSocketImpl</code>.
113
static DatagramSocketImpl createDatagramSocketImpl(boolean isMulticast)
114
throws SocketException {
115
if (prefixImplClass != null) {
117
return (DatagramSocketImpl) prefixImplClass.newInstance();
118
} catch (Exception e) {
119
throw new SocketException("can't instantiate DatagramSocketImpl");
122
if (useDualStackImpl && !isMulticast)
123
return new DualStackPlainDatagramSocketImpl();
125
return new TwoStacksPlainDatagramSocketImpl();