author | aefimov |
Wed, 24 Jul 2019 13:08:36 +0100 | |
changeset 57509 | c64a2df9dc7d |
parent 55596 | d01b345865d7 |
child 58052 | bc4e7a84e89d |
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 |
57509
c64a2df9dc7d
8227721: test/jdk/java/net/NetworkInterface/NetworkInterfaceRetrievalTests.java should open the java.net package
aefimov
parents:
55596
diff
changeset
|
27 |
* @modules java.base/java.net:open |
44927 | 28 |
*/ |
29 |
||
30 |
import java.net.InetAddress; |
|
31 |
import java.net.NetworkInterface; |
|
32 |
import java.util.Enumeration; |
|
55596 | 33 |
import java.lang.reflect.Method; |
44927 | 34 |
|
35 |
public class NetworkInterfaceRetrievalTests { |
|
36 |
public static void main(String[] args) throws Exception { |
|
37 |
int checkFailureCount = 0; |
|
38 |
||
55596 | 39 |
Method isBound = NetworkInterface.class.getDeclaredMethod("isBoundInetAddress", InetAddress.class); |
40 |
isBound.setAccessible(true); |
|
41 |
||
44927 | 42 |
try { |
43 |
Enumeration<NetworkInterface> en = NetworkInterface |
|
44 |
.getNetworkInterfaces(); |
|
45 |
while (en.hasMoreElements()) { |
|
46 |
NetworkInterface ni = en.nextElement(); |
|
47 |
Enumeration<InetAddress> addrs = ni.getInetAddresses(); |
|
48 |
System.out.println("############ Checking network interface + " |
|
49 |
+ ni + " #############"); |
|
50 |
while (addrs.hasMoreElements()) { |
|
51 |
InetAddress addr = addrs.nextElement(); |
|
52 |
System.out.println("************ Checking address + " |
|
53 |
+ addr + " *************"); |
|
54 |
NetworkInterface addrNetIf = NetworkInterface |
|
55 |
.getByInetAddress(addr); |
|
56 |
if (addrNetIf.equals(ni)) { |
|
57 |
System.out.println("Retreived net if " + addrNetIf |
|
58 |
+ " equal to owning net if " + ni); |
|
59 |
} else { |
|
60 |
System.out.println("Retreived net if " + addrNetIf |
|
61 |
+ "NOT equal to owning net if " + ni |
|
62 |
+ "***********"); |
|
63 |
checkFailureCount++; |
|
64 |
} |
|
65 |
||
55596 | 66 |
// Any bound address should return true when calling isBoundInetAddress |
67 |
if (!((boolean)isBound.invoke(null, addr))) { |
|
68 |
System.out.println("Retreived net if bound addr " + addr |
|
69 |
+ "NOT shown as bound using NetworkInterface.isBoundAddress " |
|
70 |
+ "***********"); |
|
71 |
checkFailureCount++; |
|
72 |
} |
|
44927 | 73 |
} |
74 |
} |
|
75 |
||
76 |
} catch (Exception ex) { |
|
77 |
||
78 |
} |
|
79 |
||
80 |
if (checkFailureCount > 0) { |
|
81 |
throw new RuntimeException( |
|
82 |
"NetworkInterface lookup by address didn't match owner network interface"); |
|
83 |
} |
|
84 |
} |
|
85 |
} |