1 /*
2 * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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.
10 *
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).
16 *
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.
20 *
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
23 * questions.
24 */
25
26 package java.net;
27
28 import java.util.NavigableSet;
29 import java.util.ArrayList;
30 import java.util.Objects;
31 import java.util.Scanner;
32 import java.security.AccessController;
33 import java.io.File;
34 import java.io.ObjectStreamException;
35 import java.io.ObjectStreamField;
36 import java.io.IOException;
37 import java.io.InvalidObjectException;
38 import java.io.ObjectInputStream;
39 import java.io.ObjectInputStream.GetField;
40 import java.io.ObjectOutputStream;
41 import java.io.ObjectOutputStream.PutField;
42 import java.lang.annotation.Native;
43 import java.util.concurrent.ConcurrentHashMap;
44 import java.util.concurrent.ConcurrentMap;
45 import java.util.concurrent.ConcurrentSkipListSet;
46 import java.util.concurrent.atomic.AtomicLong;
47 import java.util.Arrays;
48
49 import jdk.internal.access.JavaNetInetAddressAccess;
50 import jdk.internal.access.SharedSecrets;
51 import sun.security.action.*;
52 import sun.net.InetAddressCachePolicy;
300 /** use serialVersionUID from JDK 1.0.2 for interoperability */
301 @java.io.Serial
302 private static final long serialVersionUID = 3286316764910316507L;
303
304 /*
305 * Load net library into runtime, and perform initializations.
306 */
307 static {
308 String str = GetPropertyAction.privilegedGetProperty("java.net.preferIPv6Addresses");
309 if (str == null) {
310 preferIPv6Address = PREFER_IPV4_VALUE;
311 } else if (str.equalsIgnoreCase("true")) {
312 preferIPv6Address = PREFER_IPV6_VALUE;
313 } else if (str.equalsIgnoreCase("false")) {
314 preferIPv6Address = PREFER_IPV4_VALUE;
315 } else if (str.equalsIgnoreCase("system")) {
316 preferIPv6Address = PREFER_SYSTEM_VALUE;
317 } else {
318 preferIPv6Address = PREFER_IPV4_VALUE;
319 }
320 jdk.internal.loader.BootLoader.loadLibrary("net");
321 SharedSecrets.setJavaNetInetAddressAccess(
322 new JavaNetInetAddressAccess() {
323 public String getOriginalHostName(InetAddress ia) {
324 return ia.holder.getOriginalHostName();
325 }
326
327 public InetAddress getByName(String hostName,
328 InetAddress hostAddress)
329 throws UnknownHostException
330 {
331 return InetAddress.getByName(hostName, hostAddress);
332 }
333
334 public int addressValue(Inet4Address inet4Address) {
335 return inet4Address.addressValue();
336 }
337
338 public byte[] addressBytes(Inet6Address inet6Address) {
339 return inet6Address.addressBytes();
340 }
|
1 /*
2 * Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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.
10 *
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).
16 *
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.
20 *
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
23 * questions.
24 */
25
26 package java.net;
27
28 import java.util.NavigableSet;
29 import java.util.ArrayList;
30 import java.util.Objects;
31 import java.util.Scanner;
32 import java.io.File;
33 import java.io.ObjectStreamException;
34 import java.io.ObjectStreamField;
35 import java.io.IOException;
36 import java.io.InvalidObjectException;
37 import java.io.ObjectInputStream;
38 import java.io.ObjectInputStream.GetField;
39 import java.io.ObjectOutputStream;
40 import java.io.ObjectOutputStream.PutField;
41 import java.lang.annotation.Native;
42 import java.util.concurrent.ConcurrentHashMap;
43 import java.util.concurrent.ConcurrentMap;
44 import java.util.concurrent.ConcurrentSkipListSet;
45 import java.util.concurrent.atomic.AtomicLong;
46 import java.util.Arrays;
47
48 import jdk.internal.access.JavaNetInetAddressAccess;
49 import jdk.internal.access.SharedSecrets;
50 import sun.security.action.*;
51 import sun.net.InetAddressCachePolicy;
299 /** use serialVersionUID from JDK 1.0.2 for interoperability */
300 @java.io.Serial
301 private static final long serialVersionUID = 3286316764910316507L;
302
303 /*
304 * Load net library into runtime, and perform initializations.
305 */
306 static {
307 String str = GetPropertyAction.privilegedGetProperty("java.net.preferIPv6Addresses");
308 if (str == null) {
309 preferIPv6Address = PREFER_IPV4_VALUE;
310 } else if (str.equalsIgnoreCase("true")) {
311 preferIPv6Address = PREFER_IPV6_VALUE;
312 } else if (str.equalsIgnoreCase("false")) {
313 preferIPv6Address = PREFER_IPV4_VALUE;
314 } else if (str.equalsIgnoreCase("system")) {
315 preferIPv6Address = PREFER_SYSTEM_VALUE;
316 } else {
317 preferIPv6Address = PREFER_IPV4_VALUE;
318 }
319 LoadLibraryAction.privilegedLoadLibrary("net");
320 SharedSecrets.setJavaNetInetAddressAccess(
321 new JavaNetInetAddressAccess() {
322 public String getOriginalHostName(InetAddress ia) {
323 return ia.holder.getOriginalHostName();
324 }
325
326 public InetAddress getByName(String hostName,
327 InetAddress hostAddress)
328 throws UnknownHostException
329 {
330 return InetAddress.getByName(hostName, hostAddress);
331 }
332
333 public int addressValue(Inet4Address inet4Address) {
334 return inet4Address.addressValue();
335 }
336
337 public byte[] addressBytes(Inet6Address inet6Address) {
338 return inet6Address.addressBytes();
339 }
|