Path: blob/master/test/jdk/java/net/Inet6Address/StringScope.java
41149 views
/*1* Copyright (c) 2012, 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 800467526* @summary Inet6Address.getHostAddress should use string scope27* identifier where available28*/2930import java.net.*;31import java.util.Enumeration;3233public class StringScope {3435public static void main(String args[]) throws Exception {36Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();37while (e.hasMoreElements()) {38NetworkInterface iface = e.nextElement();39Enumeration<InetAddress> iadrs = iface.getInetAddresses();40while (iadrs.hasMoreElements()) {41InetAddress iadr = iadrs.nextElement();42if (iadr instanceof Inet6Address) {43Inet6Address i6adr = (Inet6Address) iadr;44NetworkInterface nif = i6adr.getScopedInterface();45if (nif == null)46continue;4748String nifName = nif.getName();49String i6adrHostAddress = i6adr.getHostAddress();50int index = i6adrHostAddress.indexOf('%');51String i6adrScopeName = i6adrHostAddress.substring(index+1);5253if (!nifName.equals(i6adrScopeName))54throw new RuntimeException("Expected nifName ["55+ nifName + "], to equal i6adrScopeName ["56+ i6adrScopeName + "] ");57}58}59}60}61}62636465