Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/InetAddress/CheckJNI.java
47182 views
/*1* Copyright (c) 2003, 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/* @test24@bug 4889870 489003325@summary java -Xcheck:jni failing in net code on Solaris / [Datagram]Socket.getLocalAddress() failure26@run main/othervm -Xcheck:jni CheckJNI27*/2829import java.net.*;30import java.util.*;3132public class CheckJNI {33static Socket s;34static ServerSocket server;35static DatagramSocket dg1, dg2;3637public static void main (String[] args) throws Exception {38/* try to invoke as much java.net native code as possible */3940System.out.println ("Testing IPv4 Socket/ServerSocket");41server = new ServerSocket (0);42s = new Socket ("127.0.0.1", server.getLocalPort());43s.close();44server.close();4546System.out.println ("Testing IPv4 DatagramSocket");47dg1 = new DatagramSocket (0, InetAddress.getByName ("127.0.0.1"));48dg2 = new DatagramSocket (0, InetAddress.getByName ("127.0.0.1"));49testDatagrams (dg1, dg2);5051/* Use NetworkInterface to find link local IPv6 addrs to test */5253Enumeration ifs = NetworkInterface.getNetworkInterfaces();54server = new ServerSocket (0);5556while (ifs.hasMoreElements()) {57NetworkInterface nif = (NetworkInterface)ifs.nextElement();58if (!nif.isUp())59continue;60Enumeration addrs = nif.getInetAddresses();61while (addrs.hasMoreElements()) {62InetAddress addr = (InetAddress) addrs.nextElement();63if (addr instanceof Inet6Address) {64Inet6Address ia6 = (Inet6Address) addr;65if (ia6.isLinkLocalAddress()) {66System.out.println ("Testing IPv6 Socket");67s = new Socket (ia6, server.getLocalPort());68s.close();6970System.out.println ("Testing IPv6 DatagramSocket");71dg1 = new DatagramSocket (0, ia6);72dg2 = new DatagramSocket (0, ia6);73testDatagrams (dg1, dg2);74}75}76}77}78server.close();79System.out.println ("OK");80}8182static void testDatagrams (DatagramSocket s1, DatagramSocket s2) throws Exception {83DatagramPacket p1 = new DatagramPacket (84"hello world".getBytes(),850, "hello world".length(), s2.getLocalAddress(),86s2.getLocalPort()87);8889DatagramPacket p2 = new DatagramPacket (new byte[128], 128);90s1.send (p1);91s2.receive (p2);92s1.close ();93s2.close ();94}95}969798