7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /* @test
25 @bug 4889870 4890033
26 @summary java -Xcheck:jni failing in net code on Solaris / [Datagram]Socket.getLocalAddress() failure
27 @run main/othervm -Xcheck:jni CheckJNI
28 */
29
30 import java.net.*;
31 import java.util.*;
32
33 public class CheckJNI {
34 static Socket s;
35 static ServerSocket server;
36 static DatagramSocket dg1, dg2;
37
38 public static void main (String[] args) throws Exception {
39 /* try to invoke as much java.net native code as possible */
40
41 System.out.println ("Testing IPv4 Socket/ServerSocket");
42 server = new ServerSocket (0);
43 s = new Socket ("127.0.0.1", server.getLocalPort());
44 s.close();
45 server.close();
46
47 System.out.println ("Testing IPv4 DatagramSocket");
48 dg1 = new DatagramSocket (0, InetAddress.getByName ("127.0.0.1"));
49 dg2 = new DatagramSocket (0, InetAddress.getByName ("127.0.0.1"));
50 testDatagrams (dg1, dg2);
51
52 /* Use NetworkInterface to find link local IPv6 addrs to test */
53
54 Enumeration ifs = NetworkInterface.getNetworkInterfaces();
55 server = new ServerSocket (0);
56
57 while (ifs.hasMoreElements()) {
58 NetworkInterface nif = (NetworkInterface)ifs.nextElement();
59 if (!nif.isUp())
60 continue;
61 Enumeration addrs = nif.getInetAddresses();
62 while (addrs.hasMoreElements()) {
63 InetAddress addr = (InetAddress) addrs.nextElement();
64 if (addr instanceof Inet6Address) {
65 Inet6Address ia6 = (Inet6Address) addr;
66 if (ia6.isLinkLocalAddress()) {
67 System.out.println ("Testing IPv6 Socket");
68 s = new Socket (ia6, server.getLocalPort());
69 s.close();
70
71 System.out.println ("Testing IPv6 DatagramSocket");
72 dg1 = new DatagramSocket (0, ia6);
73 dg2 = new DatagramSocket (0, ia6);
74 testDatagrams (dg1, dg2);
75 }
76 }
77 }
78 }
79 server.close();
80 System.out.println ("OK");
81 }
82
83 static void testDatagrams (DatagramSocket s1, DatagramSocket s2) throws Exception {
84 DatagramPacket p1 = new DatagramPacket (
85 "hello world".getBytes(),
86 0, "hello world".length(), s2.getLocalAddress(),
87 s2.getLocalPort()
88 );
89
90 DatagramPacket p2 = new DatagramPacket (new byte[128], 128);
91 s1.send (p1);
92 s2.receive (p2);
93 s1.close ();
94 s2.close ();
95 }
96 }
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /* @test
25 @bug 4889870 4890033
26 @summary java -Xcheck:jni failing in net code on Solaris / [Datagram]Socket.getLocalAddress() failure
27 @library /lib/testlibrary
28 @build jdk.testlibrary.NetworkConfiguration
29 @run main/othervm -Xcheck:jni CheckJNI
30 */
31
32 import java.net.*;
33 import java.util.*;
34 import java.util.stream.Collectors;
35 import jdk.testlibrary.NetworkConfiguration;
36
37 public class CheckJNI {
38 static Socket s;
39 static ServerSocket server;
40 static DatagramSocket dg1, dg2;
41
42 public static void main (String[] args) throws Exception {
43 /* try to invoke as much java.net native code as possible */
44
45 System.out.println ("Testing IPv4 Socket/ServerSocket");
46 server = new ServerSocket (0);
47 s = new Socket ("127.0.0.1", server.getLocalPort());
48 s.close();
49 server.close();
50
51 System.out.println ("Testing IPv4 DatagramSocket");
52 dg1 = new DatagramSocket (0, InetAddress.getByName ("127.0.0.1"));
53 dg2 = new DatagramSocket (0, InetAddress.getByName ("127.0.0.1"));
54 testDatagrams (dg1, dg2);
55
56 /* Find link local IPv6 addrs to test */
57 List<Inet6Address> addrs = NetworkConfiguration.probe()
58 .ip6Addresses()
59 .filter(Inet6Address::isLinkLocalAddress)
60 .collect(Collectors.toList());
61
62 server = new ServerSocket(0);
63 for (Inet6Address ia6 : addrs) {
64 System.out.println("Address:" + ia6);
65 System.out.println("Testing IPv6 Socket");
66 s = new Socket(ia6, server.getLocalPort());
67 s.close();
68
69 System.out.println("Testing IPv6 DatagramSocket");
70 dg1 = new DatagramSocket(0, ia6);
71 dg2 = new DatagramSocket(0, ia6);
72 testDatagrams(dg1, dg2);
73 }
74 server.close();
75 System.out.println ("OK");
76 }
77
78 static void testDatagrams (DatagramSocket s1, DatagramSocket s2) throws Exception {
79 DatagramPacket p1 = new DatagramPacket (
80 "hello world".getBytes(),
81 0, "hello world".length(), s2.getLocalAddress(),
82 s2.getLocalPort()
83 );
84
85 DatagramPacket p2 = new DatagramPacket (new byte[128], 128);
86 s1.send (p1);
87 s2.receive (p2);
88 s1.close ();
89 s2.close ();
90 }
91 }
|