0N/A/*
3261N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A @bug 4889870 4890033
0N/A @summary java -Xcheck:jni failing in net code on Solaris / [Datagram]Socket.getLocalAddress() failure
0N/A @run main/othervm -Xcheck:jni CheckJNI
0N/A*/
0N/A
0N/Aimport java.net.*;
0N/Aimport java.util.*;
0N/A
0N/Apublic class CheckJNI {
0N/A static Socket s;
0N/A static ServerSocket server;
0N/A static DatagramSocket dg1, dg2;
0N/A
0N/A public static void main (String[] args) throws Exception {
0N/A /* try to invoke as much java.net native code as possible */
0N/A
0N/A System.out.println ("Testing IPv4 Socket/ServerSocket");
0N/A server = new ServerSocket (0);
0N/A s = new Socket ("127.0.0.1", server.getLocalPort());
0N/A s.close();
0N/A server.close();
0N/A
0N/A System.out.println ("Testing IPv4 DatagramSocket");
0N/A dg1 = new DatagramSocket (0, InetAddress.getByName ("127.0.0.1"));
0N/A dg2 = new DatagramSocket (0, InetAddress.getByName ("127.0.0.1"));
0N/A testDatagrams (dg1, dg2);
0N/A
0N/A /* Use NetworkInterface to find link local IPv6 addrs to test */
0N/A
0N/A Enumeration ifs = NetworkInterface.getNetworkInterfaces();
0N/A server = new ServerSocket (0);
0N/A
0N/A while (ifs.hasMoreElements()) {
0N/A NetworkInterface nif = (NetworkInterface)ifs.nextElement();
2612N/A if (!nif.isUp())
2612N/A continue;
0N/A Enumeration addrs = nif.getInetAddresses();
0N/A while (addrs.hasMoreElements()) {
0N/A InetAddress addr = (InetAddress) addrs.nextElement();
0N/A if (addr instanceof Inet6Address) {
0N/A Inet6Address ia6 = (Inet6Address) addr;
0N/A if (ia6.isLinkLocalAddress()) {
0N/A System.out.println ("Testing IPv6 Socket");
0N/A s = new Socket (ia6, server.getLocalPort());
0N/A s.close();
0N/A
0N/A System.out.println ("Testing IPv6 DatagramSocket");
0N/A dg1 = new DatagramSocket (0, ia6);
0N/A dg2 = new DatagramSocket (0, ia6);
0N/A testDatagrams (dg1, dg2);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A server.close();
0N/A System.out.println ("OK");
0N/A }
0N/A
0N/A static void testDatagrams (DatagramSocket s1, DatagramSocket s2) throws Exception {
0N/A DatagramPacket p1 = new DatagramPacket (
0N/A "hello world".getBytes(),
0N/A 0, "hello world".length(), s2.getLocalAddress(),
0N/A s2.getLocalPort()
0N/A );
0N/A
0N/A DatagramPacket p2 = new DatagramPacket (new byte[128], 128);
0N/A s1.send (p1);
0N/A s2.receive (p2);
0N/A s1.close ();
0N/A s2.close ();
0N/A }
0N/A}