author | chegar |
Thu, 13 Dec 2012 14:33:32 +0000 | |
changeset 14783 | 2ecc993a8e67 |
permissions | -rw-r--r-- |
14783
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
1 |
/* |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
4 |
* |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
8 |
* |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
13 |
* accompanied this code). |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
14 |
* |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
18 |
* |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
21 |
* questions. |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
22 |
*/ |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
23 |
|
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
24 |
/** |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
25 |
* @test |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
26 |
* @bug 8004675 |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
27 |
* @summary Inet6Address.getHostAddress should use string scope |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
28 |
* identifier where available |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
29 |
*/ |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
30 |
|
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
31 |
import java.net.*; |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
32 |
import java.util.Enumeration; |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
33 |
|
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
34 |
public class StringScope { |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
35 |
|
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
36 |
public static void main(String args[]) throws Exception { |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
37 |
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
38 |
while (e.hasMoreElements()) { |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
39 |
NetworkInterface iface = e.nextElement(); |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
40 |
Enumeration<InetAddress> iadrs = iface.getInetAddresses(); |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
41 |
while (iadrs.hasMoreElements()) { |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
42 |
InetAddress iadr = iadrs.nextElement(); |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
43 |
if (iadr instanceof Inet6Address) { |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
44 |
Inet6Address i6adr = (Inet6Address) iadr; |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
45 |
NetworkInterface nif = i6adr.getScopedInterface(); |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
46 |
if (nif == null) |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
47 |
continue; |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
48 |
|
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
49 |
String nifName = nif.getName(); |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
50 |
String i6adrHostAddress = i6adr.getHostAddress(); |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
51 |
int index = i6adrHostAddress.indexOf('%'); |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
52 |
String i6adrScopeName = i6adrHostAddress.substring(index+1); |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
53 |
|
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
54 |
if (!nifName.equals(i6adrScopeName)) |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
55 |
throw new RuntimeException("Expected nifName [" |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
56 |
+ nifName + "], to equal i6adrScopeName [" |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
57 |
+ i6adrScopeName + "] "); |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
58 |
} |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
59 |
} |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
60 |
} |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
61 |
} |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
62 |
} |
2ecc993a8e67
8004675: Inet6Address.getHostAddress should use string scope identifier where available
chegar
parents:
diff
changeset
|
63 |