Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/Inet6Address/B6558853.java
41149 views
1
/*
2
* Copyright (c) 2008, 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
* @key intermittent
27
* @bug 6558853
28
* @summary getHostAddress() on connections using IPv6 link-local addrs should have zone id
29
* This test needs to bind to the wildcard address and as such is succeptible to
30
* fail intermittently because of port reuse issues.
31
* @library /test/lib
32
* @build jdk.test.lib.NetworkConfiguration
33
* jdk.test.lib.Platform
34
* @run main B6558853
35
*/
36
37
import java.io.IOException;
38
import java.io.InputStream;
39
import java.io.OutputStream;
40
import java.net.*;
41
import java.util.Optional;
42
import jdk.test.lib.NetworkConfiguration;
43
44
public class B6558853 implements Runnable {
45
private InetAddress addr = null;
46
private int port = 0;
47
48
public static void main(String[] args) throws Exception {
49
Optional<Inet6Address> oaddr = NetworkConfiguration.probe()
50
.ip6Addresses()
51
.filter(a -> a.isLinkLocalAddress())
52
.findFirst();
53
54
if (!oaddr.isPresent()) {
55
System.out.println("No suitable interface found. Exiting.");
56
return;
57
}
58
59
Inet6Address dest = oaddr.get();
60
System.out.println("Using " + dest);
61
62
try (ServerSocket ss = new ServerSocket(0)) {
63
int port = ss.getLocalPort();
64
B6558853 test = new B6558853(dest, port);
65
Thread thread = new Thread(test);
66
thread.start();
67
Socket s = ss.accept();
68
InetAddress a = s.getInetAddress();
69
OutputStream out = s.getOutputStream();
70
out.write(1);
71
out.close();
72
if (!(a instanceof Inet6Address) || a.getHostAddress().indexOf("%") == -1) {
73
// No Scope found in the address String
74
throw new RuntimeException("Wrong address: " + a.getHostAddress());
75
}
76
}
77
}
78
79
public B6558853(InetAddress a, int port) {
80
addr = a;
81
this.port = port;
82
}
83
84
public void run() {
85
try {
86
Socket s = new Socket(addr, port);
87
InputStream in = s.getInputStream();
88
int i = in.read();
89
in.close();
90
} catch (IOException iOException) {
91
}
92
}
93
}
94
95