author | jboes |
Fri, 08 Nov 2019 11:15:16 +0000 | |
changeset 59029 | 3786a0962570 |
parent 58052 | bc4e7a84e89d |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
44927 | 1 |
/* |
55596 | 2 |
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
44927 | 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 |
|
55596 | 26 |
* @bug 8179559 8225239 |
58052
bc4e7a84e89d
8230132: java/net/NetworkInterface/NetworkInterfaceRetrievalTests.java to skip Teredo Tunneling Pseudo-Interface
dfuchs
parents:
57509
diff
changeset
|
27 |
* @library /test/lib |
57509
c64a2df9dc7d
8227721: test/jdk/java/net/NetworkInterface/NetworkInterfaceRetrievalTests.java should open the java.net package
aefimov
parents:
55596
diff
changeset
|
28 |
* @modules java.base/java.net:open |
44927 | 29 |
*/ |
30 |
||
31 |
import java.net.InetAddress; |
|
32 |
import java.net.NetworkInterface; |
|
33 |
import java.util.Enumeration; |
|
55596 | 34 |
import java.lang.reflect.Method; |
58052
bc4e7a84e89d
8230132: java/net/NetworkInterface/NetworkInterfaceRetrievalTests.java to skip Teredo Tunneling Pseudo-Interface
dfuchs
parents:
57509
diff
changeset
|
35 |
import jdk.test.lib.Platform; |
44927 | 36 |
|
37 |
public class NetworkInterfaceRetrievalTests { |
|
38 |
public static void main(String[] args) throws Exception { |
|
39 |
int checkFailureCount = 0; |
|
40 |
||
55596 | 41 |
Method isBound = NetworkInterface.class.getDeclaredMethod("isBoundInetAddress", InetAddress.class); |
42 |
isBound.setAccessible(true); |
|
43 |
||
44927 | 44 |
try { |
45 |
Enumeration<NetworkInterface> en = NetworkInterface |
|
46 |
.getNetworkInterfaces(); |
|
47 |
while (en.hasMoreElements()) { |
|
48 |
NetworkInterface ni = en.nextElement(); |
|
58052
bc4e7a84e89d
8230132: java/net/NetworkInterface/NetworkInterfaceRetrievalTests.java to skip Teredo Tunneling Pseudo-Interface
dfuchs
parents:
57509
diff
changeset
|
49 |
|
bc4e7a84e89d
8230132: java/net/NetworkInterface/NetworkInterfaceRetrievalTests.java to skip Teredo Tunneling Pseudo-Interface
dfuchs
parents:
57509
diff
changeset
|
50 |
//JDK-8230132: Should not test on Windows with Teredo Tunneling Pseudo-Interface |
bc4e7a84e89d
8230132: java/net/NetworkInterface/NetworkInterfaceRetrievalTests.java to skip Teredo Tunneling Pseudo-Interface
dfuchs
parents:
57509
diff
changeset
|
51 |
String dName = ni.getDisplayName(); |
bc4e7a84e89d
8230132: java/net/NetworkInterface/NetworkInterfaceRetrievalTests.java to skip Teredo Tunneling Pseudo-Interface
dfuchs
parents:
57509
diff
changeset
|
52 |
if (Platform.isWindows() && dName != null && dName.contains("Teredo")) |
bc4e7a84e89d
8230132: java/net/NetworkInterface/NetworkInterfaceRetrievalTests.java to skip Teredo Tunneling Pseudo-Interface
dfuchs
parents:
57509
diff
changeset
|
53 |
continue; |
bc4e7a84e89d
8230132: java/net/NetworkInterface/NetworkInterfaceRetrievalTests.java to skip Teredo Tunneling Pseudo-Interface
dfuchs
parents:
57509
diff
changeset
|
54 |
|
44927 | 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 |
||
55596 | 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 |
} |
|
44927 | 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 |
} |