author | chegar |
Fri, 14 Apr 2017 10:47:08 +0100 | |
changeset 44671 | d1d011d4654d |
parent 7668 | d4a77089c587 |
child 45186 | 387a39577f09 |
permissions | -rw-r--r-- |
482
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
1 |
/* |
7668 | 2 |
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. |
482
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
4 |
* |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
8 |
* |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
13 |
* accompanied this code). |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
14 |
* |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
18 |
* |
5506 | 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. |
|
482
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
22 |
*/ |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
23 |
|
44671
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
24 |
/* |
482
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
25 |
* @test |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
26 |
* @bug 6558853 |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
27 |
* @summary getHostAddress() on connections using IPv6 link-local addrs should have zone id |
44671
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
28 |
* @library /lib/testlibrary |
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
29 |
* @build jdk.testlibrary.NetworkConfiguration |
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
30 |
* @run main B6558853 |
482
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
31 |
*/ |
44671
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
32 |
|
482
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
33 |
import java.io.IOException; |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
34 |
import java.io.InputStream; |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
35 |
import java.io.OutputStream; |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
36 |
import java.net.*; |
44671
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
37 |
import java.util.Optional; |
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
38 |
import jdk.testlibrary.NetworkConfiguration; |
482
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
39 |
|
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
40 |
public class B6558853 implements Runnable { |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
41 |
private InetAddress addr = null; |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
42 |
private int port = 0; |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
43 |
|
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
44 |
public static void main(String[] args) throws Exception { |
44671
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
45 |
Optional<Inet6Address> oaddr = NetworkConfiguration.probe() |
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
46 |
.ip6Addresses() |
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
47 |
.filter(a -> a.isLinkLocalAddress()) |
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
48 |
.findFirst(); |
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
49 |
|
44671
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
50 |
if (!oaddr.isPresent()) { |
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
51 |
System.out.println("No suitable interface found. Exiting."); |
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
52 |
return; |
482
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
53 |
} |
44671
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
54 |
|
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
55 |
Inet6Address dest = oaddr.get(); |
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
56 |
System.out.println("Using " + dest); |
44671
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
57 |
|
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
58 |
try (ServerSocket ss = new ServerSocket(0)) { |
d1d011d4654d
8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
chegar
parents:
7668
diff
changeset
|
59 |
int port = ss.getLocalPort(); |
482
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
60 |
B6558853 test = new B6558853(dest, port); |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
61 |
Thread thread = new Thread(test); |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
62 |
thread.start(); |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
63 |
Socket s = ss.accept(); |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
64 |
InetAddress a = s.getInetAddress(); |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
65 |
OutputStream out = s.getOutputStream(); |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
66 |
out.write(1); |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
67 |
out.close(); |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
68 |
if (!(a instanceof Inet6Address) || a.getHostAddress().indexOf("%") == -1) { |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
69 |
// No Scope found in the address String |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
70 |
throw new RuntimeException("Wrong address: " + a.getHostAddress()); |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
71 |
} |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
72 |
} |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
73 |
} |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
74 |
|
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
75 |
public B6558853(InetAddress a, int port) { |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
76 |
addr = a; |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
77 |
this.port = port; |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
78 |
} |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
79 |
|
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
80 |
public void run() { |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
81 |
try { |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
82 |
Socket s = new Socket(addr, port); |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
83 |
InputStream in = s.getInputStream(); |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
84 |
int i = in.read(); |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
85 |
in.close(); |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
86 |
} catch (IOException iOException) { |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
87 |
} |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
88 |
} |
9cb089744f91
6558853: getHostAddress() on connections using IPv6 link-local addrs should have zone id
jccollet
parents:
diff
changeset
|
89 |
} |