Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/NetworkInterface/NetworkInterfaceRetrievalTests.java
41149 views
1
/*
2
* Copyright (c) 2017, 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
/**
25
* @test
26
* @bug 8179559 8225239
27
* @library /test/lib
28
* @modules java.base/java.net:open
29
*/
30
31
import java.net.InetAddress;
32
import java.net.NetworkInterface;
33
import java.util.Enumeration;
34
import java.lang.reflect.Method;
35
import jdk.test.lib.Platform;
36
37
public class NetworkInterfaceRetrievalTests {
38
public static void main(String[] args) throws Exception {
39
int checkFailureCount = 0;
40
41
Method isBound = NetworkInterface.class.getDeclaredMethod("isBoundInetAddress", InetAddress.class);
42
isBound.setAccessible(true);
43
44
try {
45
Enumeration<NetworkInterface> en = NetworkInterface
46
.getNetworkInterfaces();
47
while (en.hasMoreElements()) {
48
NetworkInterface ni = en.nextElement();
49
50
//JDK-8230132: Should not test on Windows with Teredo Tunneling Pseudo-Interface
51
String dName = ni.getDisplayName();
52
if (Platform.isWindows() && dName != null && dName.contains("Teredo"))
53
continue;
54
55
Enumeration<InetAddress> addrs = ni.getInetAddresses();
56
System.out.println("############ Checking network interface + "
57
+ ni + " #############");
58
while (addrs.hasMoreElements()) {
59
InetAddress addr = addrs.nextElement();
60
System.out.println("************ Checking address + "
61
+ addr + " *************");
62
NetworkInterface addrNetIf = NetworkInterface
63
.getByInetAddress(addr);
64
if (addrNetIf.equals(ni)) {
65
System.out.println("Retreived net if " + addrNetIf
66
+ " equal to owning net if " + ni);
67
} else {
68
System.out.println("Retreived net if " + addrNetIf
69
+ "NOT equal to owning net if " + ni
70
+ "***********");
71
checkFailureCount++;
72
}
73
74
// Any bound address should return true when calling isBoundInetAddress
75
if (!((boolean)isBound.invoke(null, addr))) {
76
System.out.println("Retreived net if bound addr " + addr
77
+ "NOT shown as bound using NetworkInterface.isBoundAddress "
78
+ "***********");
79
checkFailureCount++;
80
}
81
}
82
}
83
84
} catch (Exception ex) {
85
86
}
87
88
if (checkFailureCount > 0) {
89
throw new RuntimeException(
90
"NetworkInterface lookup by address didn't match owner network interface");
91
}
92
}
93
}
94
95