Path: blob/master/test/jdk/java/net/ipv6tests/BadIPv6Addresses.java
41149 views
/*1* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4742177 801983426* @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code27*/28import java.net.*;29import java.util.*;303132public class BadIPv6Addresses {33public static void main(String[] args) throws Exception {34String[] badAddresses = new String[] {35"0:1:2:3:4:5:6:7:8", // too many :36"0:1:2:3:4:5:6", // not enough :37"0:1:2:3:4:5:6:x", // bad digits38"0:1:2:3:4:5:6::7", // adjacent :39"0:1:2:3:4:5:6:789abcdef", // too many digits40"0:1:2:3::x", // compressed, bad digits41"0:1:2:::3", // compressed, too many adjacent :42"0:1:2:3::abcde", // compressed, too many digits43"0:1", // compressed, not enough :44"0:0:0:0:0:x:10.0.0.1", // with embeded ipv4, bad ipv6 digits45"0:0:0:0:0:0:10.0.0.x", // with embeded ipv4, bad ipv4 digits46"0:0:0:0:0::0:10.0.0.1", // with embeded ipv4, adjacent :47"0:0:0:0:0:fffff:10.0.0.1", // with embeded ipv4, too many ipv6 digits48"0:0:0:0:0:0:0:10.0.0.1", // with embeded ipv4, too many :49"0:0:0:0:0:10.0.0.1", // with embeded ipv4, not enough :50"0:0:0:0:0:0:10.0.0.0.1", // with embeded ipv4, too many .51"0:0:0:0:0:0:10.0.1", // with embeded ipv4, not enough .52"0:0:0:0:0:0:10..0.0.1", // with embeded ipv4, adjacent .53"::fffx:192.168.0.1", // with compressed ipv4, bad ipv6 digits54"::ffff:192.168.0.x", // with compressed ipv4, bad ipv4 digits55":::ffff:192.168.0.1", // with compressed ipv4, too many adjacent :56"::fffff:192.168.0.1", // with compressed ipv4, too many ipv6 digits57"::ffff:1923.168.0.1", // with compressed ipv4, too many ipv4 digits58":ffff:192.168.0.1", // with compressed ipv4, not enough :59"::ffff:192.168.0.1.2", // with compressed ipv4, too many .60"::ffff:192.168.0", // with compressed ipv4, not enough .61"::ffff:192.168..0.1" // with compressed ipv4, adjacent .62};6364List<String> failedAddrs = new ArrayList<String>();65for (String addrStr : badAddresses) {66try {67InetAddress addr = InetAddress.getByName(addrStr);6869// it is an error if no exception70failedAddrs.add(addrStr);71} catch (UnknownHostException e) {72// expected73}74}7576if (failedAddrs.size() > 0) {77System.out.println("We should reject following ipv6 addresses, but we didn't:");78for (String addr : failedAddrs) {79System.out.println("\t" + addr);80}81throw new RuntimeException("Test failed.");82}83}84}858687