Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/ipv6tests/ScopeTests.java
41149 views
1
/*
2
* Copyright (c) 2003, 2018, 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
/*
25
* @test
26
* @bug 4868820
27
* @summary IPv6 support for Windows XP and 2003 server
28
* @library /test/lib
29
* @build jdk.test.lib.NetworkConfiguration
30
* jdk.test.lib.Platform
31
* @run main ScopeTests
32
*/
33
34
import java.net.*;
35
import java.util.*;
36
37
public class ScopeTests extends Tests {
38
39
public static void main (String[] args) throws Exception {
40
checkDebug (args);
41
simpleTests();
42
complexTests();
43
System.out.println ("Tests passed: OK");
44
}
45
46
static void sassert (boolean condition, String msg) throws Exception {
47
if (!condition) {
48
throw new Exception (msg);
49
}
50
}
51
52
static void checkAddress (String a, int numeric) throws Exception {
53
Inet6Address addr = (Inet6Address) InetAddress.getByName (a);
54
if (addr.getScopeId () != numeric) {
55
throw new Exception ("wroing numeric scopeid");
56
}
57
}
58
59
static void checkAddress (String a, String str) throws Exception {
60
Inet6Address addr = (Inet6Address) InetAddress.getByName (a);
61
if (!addr.getScopedInterface().getName().equals (str)) {
62
throw new Exception ("wroing scoped interface name");
63
}
64
}
65
66
/* These tests check generic API functionality that is not
67
* dependent on scoping being implemented in the platform
68
*/
69
static void simpleTests () throws Exception {
70
checkAddress ("fe80::%1", 1);
71
checkAddress ("fe80::1%1", 1);
72
checkAddress ("fec0::1:a00:20ff:feed:b08d%0", 0);
73
checkAddress ("fec0::1:a00:20ff:feed:b08d%1", 1);
74
checkAddress ("fec0::1:a00:20ff:feed:b08d%99", 99);
75
checkAddress ("fe80::", 0);
76
checkAddress ("fec0::1:a00:20ff:feed:b08d", 0);
77
checkAddress ("fec0::1:a00:20ff:feed:b08d", 0);
78
checkAddress ("fec0::1:a00:20ff:feed:b08d", 0);
79
}
80
81
/* These tests check the NetworkInterfaces for the actual scopeids
82
* configured on the system and do tests using that information
83
*/
84
static void complexTests () throws Exception {
85
dprintln ("ComplexTests");
86
Enumeration e = NetworkInterface.getNetworkInterfaces();
87
while (e.hasMoreElements()) {
88
NetworkInterface nif = (NetworkInterface)e.nextElement();
89
String name = nif.getName();
90
Enumeration addrs = nif.getInetAddresses();
91
while (addrs.hasMoreElements()) {
92
InetAddress addr = (InetAddress) addrs.nextElement();
93
dprintln ("ComplexTests: "+addr);
94
if (addr instanceof Inet6Address) {
95
Inet6Address ia6 = (Inet6Address) addr;
96
if (ia6.getScopeId() != 0) {
97
System.out.println ("Testing interface: " + name +
98
" and address: " + ia6);
99
ctest1 (name, ia6);
100
ctest2 (name, ia6);
101
} else {
102
System.out.println ("Interface: " + name +
103
" Address: "+ ia6 +
104
" does not support scope");
105
}
106
}
107
}
108
}
109
}
110
111
112
/* check the scoped name on the Inet6Address is the same as
113
* the interface it is attached to
114
*/
115
static void ctest1 (String ifname, Inet6Address ia6) throws Exception {
116
System.out.println ("ctest1:" + ia6);
117
String s = ia6.getScopedInterface().getName();
118
int scope = ia6.getScopeId();
119
sassert (ifname.equals (s), "ctest1:"+ifname+":"+s);
120
121
}
122
123
/* create an Inet6Adddress by all three methods using the ifname
124
* compare the numeric scope id with that of the Inet6Address passed in
125
*/
126
static void ctest2 (String ifname, Inet6Address ia6) throws Exception {
127
System.out.println ("ctest2:" + ia6);
128
String s = ia6.getScopedInterface().getName();
129
int scope = ia6.getScopeId();
130
String s1 = ia6.getHostAddress();
131
if (s1.indexOf('%') != -1) {
132
s1 = s1.substring (0, s1.indexOf ('%'));
133
}
134
Inet6Address add = (Inet6Address) InetAddress.getByName (s1+"%"+ifname);
135
sassert (add.getScopeId() == scope, "ctest2:1:" +scope);
136
}
137
}
138
139