Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/Inet6Address/B6558853.java
47126 views
/*1* Copyright (c) 2008, 2010, 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 655885326* @summary getHostAddress() on connections using IPv6 link-local addrs should have zone id27*/28import java.io.IOException;29import java.io.InputStream;30import java.io.OutputStream;31import java.net.*;32import java.util.Enumeration;3334public class B6558853 implements Runnable {35private InetAddress addr = null;36private int port = 0;3738public static void main(String[] args) throws Exception {39ServerSocket ss = new ServerSocket(0);40int port = ss.getLocalPort();41Enumeration<NetworkInterface> l = NetworkInterface.getNetworkInterfaces();42InetAddress dest = null;43while (l.hasMoreElements() && dest == null) {44NetworkInterface nif = l.nextElement();45if (!nif.isUp())46continue;4748for (InterfaceAddress a : nif.getInterfaceAddresses()) {49if (a.getAddress() instanceof Inet6Address) {50Inet6Address a6 = (Inet6Address) a.getAddress();51if (a6.isLinkLocalAddress()) {52dest = a6;53}54break;55}56}57}58System.out.println("Using " + dest);59if (dest != null) {60B6558853 test = new B6558853(dest, port);61Thread thread = new Thread(test);62thread.start();63Socket s = ss.accept();64InetAddress a = s.getInetAddress();65OutputStream out = s.getOutputStream();66out.write(1);67out.close();68if (!(a instanceof Inet6Address) || a.getHostAddress().indexOf("%") == -1) {69// No Scope found in the address String70throw new RuntimeException("Wrong address: " + a.getHostAddress());71}72}73}7475public B6558853(InetAddress a, int port) {76addr = a;77this.port = port;78}7980public void run() {81try {82Socket s = new Socket(addr, port);83InputStream in = s.getInputStream();84int i = in.read();85in.close();86} catch (IOException iOException) {87}88}89}909192