Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/InetAddress/getOriginalHostName.java
47182 views
/*1* Copyright (c) 2015, 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 813319626* @summary test functionality of getOriginalHostName(InetAddress)27*/2829import java.io.*;30import java.net.InetAddress;3132import sun.misc.JavaNetAccess;33import sun.misc.SharedSecrets;3435public class getOriginalHostName {3637private static final JavaNetAccess jna = SharedSecrets.getJavaNetAccess();3839public static void main(String[] args) throws Exception {40final String HOST = "dummyserver.java.net";41InetAddress ia = null;42ia = InetAddress.getByName(HOST);43testInetAddress(ia, HOST);44ia = InetAddress.getByName("255.255.255.0");45testInetAddress(ia, null);46ia = InetAddress.getByAddress(new byte[]{1,1,1,1});47testInetAddress(ia, null);48ia = InetAddress.getLocalHost();49testInetAddress(ia, ia.getHostName());50ia = InetAddress.getLoopbackAddress();51testInetAddress(ia, ia.getHostName());52}535455private static void testInetAddress(InetAddress ia, String expected)56throws Exception {5758System.out.println("Testing InetAddress: " + ia);59System.out.println("Expecting original hostname of : " + expected);60String origHostName = jna.getOriginalHostName(ia);61System.out.println("via JavaNetAccess: " + origHostName);62if (origHostName == null && expected != null) {63throw new RuntimeException("Unexpected null. Testing:" + expected);64} else if (expected != null && !origHostName.equals(expected)) {65throw new RuntimeException("Unexpected hostname :" + origHostName);66} else if (expected == null && origHostName != null) {67throw new RuntimeException("Unexpected origHostName: " + origHostName);68}69}70}717273