1 /*
2  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. 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 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 /**
25  * @test
26  * @bug 6214234 6967937
27  * @summary IPv6 scope_id for local addresses not set in Solaris 10
28  */
29 
30 import java.net.*;
31 import java.util.*;
32 
33 public class B6214234 {
34 
main(String[] args)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             System.out.println("addr: "+ addr);
55             throw new RuntimeException ("Non zero scope_id expected");
56         }
57     }
58 
getLocalAddr()59     public static Inet6Address getLocalAddr () throws Exception {
60         Enumeration e = NetworkInterface.getNetworkInterfaces();
61         while (e.hasMoreElements()) {
62             NetworkInterface ifc = (NetworkInterface) e.nextElement();
63             Enumeration addrs = ifc.getInetAddresses();
64             while (addrs.hasMoreElements()) {
65                 InetAddress a = (InetAddress)addrs.nextElement();
66                 if (a instanceof Inet6Address) {
67                     Inet6Address ia6 = (Inet6Address) a;
68                     if (ia6.isLinkLocalAddress()) {
69                         return ia6;
70                     }
71                 }
72             }
73         }
74         return null;
75     }
76 }
77