Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/InetAddress/CheckJNI.java
41149 views
1
/*
2
* Copyright (c) 2003, 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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
* @bug 4889870 4890033
26
* @summary java -Xcheck:jni failing in net code on Solaris / [Datagram]Socket.getLocalAddress() failure
27
* @library /test/lib
28
* @build jdk.test.lib.NetworkConfiguration
29
* jdk.test.lib.Platform
30
* @run main/othervm -Xcheck:jni CheckJNI
31
*/
32
33
import java.net.*;
34
import java.util.*;
35
import java.util.stream.Collectors;
36
import jdk.test.lib.NetworkConfiguration;
37
import jdk.test.lib.net.IPSupport;
38
39
public class CheckJNI {
40
public static void main (String[] args) throws Exception {
41
/* try to invoke as much java.net native code as possible */
42
43
InetAddress loopback = InetAddress.getLoopbackAddress();
44
System.out.println("Testing loopback Socket/ServerSocket");
45
testSocket(loopback);
46
47
System.out.println("Testing loopback DatagramSocket");
48
testDatagram(loopback);
49
50
if (IPSupport.hasIPv4()) {
51
InetAddress loopback4 = InetAddress.getByName("127.0.0.1");
52
System.out.println("Testing IPv4 Socket/ServerSocket");
53
testSocket(loopback4);
54
55
System.out.println("Testing IPv4 DatagramSocket");
56
testDatagram(loopback4);
57
}
58
59
/* Find link local IPv6 addrs to test */
60
List<Inet6Address> addrs = NetworkConfiguration.probe()
61
.ip6Addresses()
62
.filter(Inet6Address::isLinkLocalAddress)
63
.collect(Collectors.toList());
64
65
for (Inet6Address ia6 : addrs) {
66
System.out.println("Address:" + ia6);
67
System.out.println("Testing IPv6 Socket");
68
testSocket(ia6);
69
70
System.out.println("Testing IPv6 DatagramSocket");
71
testDatagram(ia6);
72
}
73
System.out.println("OK");
74
}
75
76
static void testSocket(InetAddress ia) throws Exception {
77
ServerSocket server = new ServerSocket(0, 0, ia);
78
Socket s = new Socket(ia, server.getLocalPort());
79
s.close();
80
server.close();
81
}
82
83
static void testDatagram(InetAddress ia) throws Exception {
84
DatagramSocket s1 = new DatagramSocket(0, ia);
85
DatagramSocket s2 = new DatagramSocket(0, ia);
86
System.out.println("s1: local address=" + s1.getLocalAddress()
87
+ ", local port=" + s1.getLocalPort());
88
System.out.println("s2: local address=" + s2.getLocalAddress()
89
+ ", local port=" + s2.getLocalPort());
90
91
DatagramPacket p1 = new DatagramPacket (
92
"hello world".getBytes(),
93
0, "hello world".length(), s2.getLocalAddress(),
94
s2.getLocalPort()
95
);
96
97
DatagramPacket p2 = new DatagramPacket(new byte[128], 128);
98
s1.send(p1);
99
s2.receive(p2);
100
s1.close();
101
s2.close();
102
}
103
}
104
105