Path: blob/master/test/jdk/java/net/NetworkInterface/SubNetworkInterfaceTest.java
41149 views
/*1* Copyright (c) 2016, 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 816884026* @summary InetAddress.getByName() throws java.net.UnknownHostException no such27* interface when used with virtual interfaces on Solaris28*/29import java.net.InetAddress;30import java.net.NetworkInterface;31import java.net.SocketException;32import java.net.UnknownHostException;33import java.util.Collections;34import java.util.Enumeration;3536public class SubNetworkInterfaceTest {3738public static void main(String args[]) throws SocketException, UnknownHostException {39Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();40for (NetworkInterface netIf : Collections.list(nets)) {41doReverseLookup(netIf);42}43}4445static void doReverseLookup(NetworkInterface netIf) throws SocketException, UnknownHostException {46for (NetworkInterface subIf : Collections.list(netIf.getSubInterfaces())) {47Enumeration<InetAddress> subInetAddresses = subIf.getInetAddresses();48while (subInetAddresses != null && subInetAddresses.hasMoreElements()) {49InetAddress inetAddress = subInetAddresses.nextElement();50String reversalString = inetAddress.getHostAddress();51//should not throw UHE in case of virtual sub interface52InetAddress.getByName(reversalString);53}54}55}56}575859