blob: 44c02a12338f72501587b33e06468db04ad0dc1d [file] [log] [blame]
duke6e45e102007-12-01 00:00:00 +00001/*
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/**
25 * @test
26 * @bug 6214234
27 * @summary IPv6 scope_id for local addresses not set in Solaris 10
28 */
29
30import java.net.*;
31import java.util.*;
32
33public class B6214234 {
34
35 public static void main (String[] args) throws Exception {
36 String osname = System.getProperty ("os.name");
37 String version = System.getProperty ("os.version");
38 if (!"SunOS".equals (osname)) {
39 System.out.println ("Test only runs on Solaris");
40 return;
41 }
42 String[] v = version.split("\\.");
43 int verNumber = Integer.parseInt (v[0]) * 100 + Integer.parseInt (v[1]);
44 if (verNumber < 510) {
45 System.out.println ("Test only runs on Solaris versions 10 or higher");
46 return;
47 }
48 Inet6Address addr = getLocalAddr();
49 if (addr == null) {
50 System.out.println ("Could not find a link-local address");
51 return;
52 }
53 if (addr.getScopeId() == 0) {
54 throw new RuntimeException ("Non zero scope_id expected");
55 }
56 }
57
58 public static Inet6Address getLocalAddr () throws Exception {
59 Enumeration e = NetworkInterface.getNetworkInterfaces();
60 while (e.hasMoreElements()) {
61 NetworkInterface ifc = (NetworkInterface) e.nextElement();
62 Enumeration addrs = ifc.getInetAddresses();
63 while (addrs.hasMoreElements()) {
64 InetAddress a = (InetAddress)addrs.nextElement();
65 if (a instanceof Inet6Address) {
66 Inet6Address ia6 = (Inet6Address) a;
67 if (ia6.isLinkLocalAddress()) {
68 return ia6;
69 }
70 }
71 }
72 }
73 return null;
74 }
75}