author | coleenp |
Wed, 17 Jun 2015 21:44:48 +0000 | |
changeset 31362 | 8957ccbb5821 |
parent 14672 | 7498e72592b5 |
permissions | -rw-r--r-- |
14672
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
1 |
/* |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
4 |
* |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
8 |
* |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
13 |
* accompanied this code). |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
14 |
* |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
18 |
* |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
21 |
* questions. |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
22 |
*/ |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
23 |
|
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
24 |
/** |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
25 |
* @test |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
26 |
* @bug 6210227 |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
27 |
* @summary REGRESSION: Socket.getLocalAddress() returns address of 0.0.0.0 on outbound TCP |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
28 |
*/ |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
29 |
|
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
30 |
import java.util.*; |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
31 |
import java.net.*; |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
32 |
|
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
33 |
public class B6210227 { |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
34 |
public static void main(String[] args) throws Exception |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
35 |
{ |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
36 |
ServerSocket ss = new ServerSocket(0); |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
37 |
int port = ss.getLocalPort(); |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
38 |
|
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
39 |
byte[] bad = {0,0,0,0}; |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
40 |
try { |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
41 |
InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(), port); |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
42 |
Socket s = new Socket(); |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
43 |
s.connect( isa, 1000 ); |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
44 |
InetAddress iaLocal = s.getLocalAddress(); // if this comes back as 0.0. 0.0 this would demonstrate issue |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
45 |
String sLocalHostname = iaLocal.getHostName(); |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
46 |
if (Arrays.equals (iaLocal.getAddress(), bad)) { |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
47 |
throw new RuntimeException ("0.0.0.0 returned"); |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
48 |
} |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
49 |
System.out.println("local hostname is "+sLocalHostname ); |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
50 |
} catch(Exception e) { |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
51 |
System.out.println("Exception happened"); |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
52 |
throw e; |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
53 |
} finally { |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
54 |
ss.close(); |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
55 |
} |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
56 |
} |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
57 |
} |
7498e72592b5
8003597: TEST_BUG: Eliminate dependency on javaweb from closed net tests
robm
parents:
diff
changeset
|
58 |