Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/ipv6tests/BadIPv6Addresses.java
41149 views
1
/*
2
* Copyright (c) 2007, 2013, 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
* @bug 4742177 8019834
27
* @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
28
*/
29
import java.net.*;
30
import java.util.*;
31
32
33
public class BadIPv6Addresses {
34
public static void main(String[] args) throws Exception {
35
String[] badAddresses = new String[] {
36
"0:1:2:3:4:5:6:7:8", // too many :
37
"0:1:2:3:4:5:6", // not enough :
38
"0:1:2:3:4:5:6:x", // bad digits
39
"0:1:2:3:4:5:6::7", // adjacent :
40
"0:1:2:3:4:5:6:789abcdef", // too many digits
41
"0:1:2:3::x", // compressed, bad digits
42
"0:1:2:::3", // compressed, too many adjacent :
43
"0:1:2:3::abcde", // compressed, too many digits
44
"0:1", // compressed, not enough :
45
"0:0:0:0:0:x:10.0.0.1", // with embeded ipv4, bad ipv6 digits
46
"0:0:0:0:0:0:10.0.0.x", // with embeded ipv4, bad ipv4 digits
47
"0:0:0:0:0::0:10.0.0.1", // with embeded ipv4, adjacent :
48
"0:0:0:0:0:fffff:10.0.0.1", // with embeded ipv4, too many ipv6 digits
49
"0:0:0:0:0:0:0:10.0.0.1", // with embeded ipv4, too many :
50
"0:0:0:0:0:10.0.0.1", // with embeded ipv4, not enough :
51
"0:0:0:0:0:0:10.0.0.0.1", // with embeded ipv4, too many .
52
"0:0:0:0:0:0:10.0.1", // with embeded ipv4, not enough .
53
"0:0:0:0:0:0:10..0.0.1", // with embeded ipv4, adjacent .
54
"::fffx:192.168.0.1", // with compressed ipv4, bad ipv6 digits
55
"::ffff:192.168.0.x", // with compressed ipv4, bad ipv4 digits
56
":::ffff:192.168.0.1", // with compressed ipv4, too many adjacent :
57
"::fffff:192.168.0.1", // with compressed ipv4, too many ipv6 digits
58
"::ffff:1923.168.0.1", // with compressed ipv4, too many ipv4 digits
59
":ffff:192.168.0.1", // with compressed ipv4, not enough :
60
"::ffff:192.168.0.1.2", // with compressed ipv4, too many .
61
"::ffff:192.168.0", // with compressed ipv4, not enough .
62
"::ffff:192.168..0.1" // with compressed ipv4, adjacent .
63
};
64
65
List<String> failedAddrs = new ArrayList<String>();
66
for (String addrStr : badAddresses) {
67
try {
68
InetAddress addr = InetAddress.getByName(addrStr);
69
70
// it is an error if no exception
71
failedAddrs.add(addrStr);
72
} catch (UnknownHostException e) {
73
// expected
74
}
75
}
76
77
if (failedAddrs.size() > 0) {
78
System.out.println("We should reject following ipv6 addresses, but we didn't:");
79
for (String addr : failedAddrs) {
80
System.out.println("\t" + addr);
81
}
82
throw new RuntimeException("Test failed.");
83
}
84
}
85
}
86
87