Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/Inet4Address/PingThis.java
41149 views
1
/*
2
* Copyright (c) 2012, 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
* Portions Copyright (c) 2012 IBM Corporation
26
*/
27
28
/* @test
29
* @bug 7163874 8133015
30
* @library /test/lib
31
* @summary InetAddress.isReachable is returning false
32
* for InetAdress 0.0.0.0 and ::0
33
* @run main PingThis
34
* @run main/othervm -Djava.net.preferIPv4Stack=true PingThis
35
*/
36
37
import java.net.Inet6Address;
38
import java.net.InetAddress;
39
import java.net.NetworkInterface;
40
import java.util.ArrayList;
41
import java.util.Collections;
42
import java.util.Iterator;
43
import java.util.List;
44
import jdk.test.lib.net.IPSupport;
45
46
public class PingThis {
47
public static void main(String args[]) throws Exception {
48
if (System.getProperty("os.name").startsWith("Windows")) {
49
return;
50
}
51
IPSupport.throwSkippedExceptionIfNonOperational();
52
53
List<String> addrs = new ArrayList<String>();
54
55
if (IPSupport.hasIPv4()) {
56
addrs.add("0.0.0.0");
57
}
58
if (IPSupport.hasIPv6()) {
59
addrs.add("::0");
60
}
61
62
for (String addr : addrs) {
63
InetAddress inetAddress = InetAddress.getByName(addr);
64
System.out.println("The target ip is "
65
+ inetAddress.getHostAddress());
66
boolean isReachable = inetAddress.isReachable(3000);
67
System.out.println("the target is reachable: " + isReachable);
68
if (isReachable) {
69
System.out.println("Test passed ");
70
} else {
71
System.out.println("Test failed ");
72
throw new Exception("address " + inetAddress.getHostAddress()
73
+ " can not be reachable!");
74
}
75
}
76
}
77
}
78
79