Source Code Cross Referenced for Inet6AddressImpl.java in  » 6.0-JDK-Core » net » java » net » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » net » java.net 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 2002-2005 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025        package java.net;
026
027        import java.io.IOException;
028
029        /*
030         * Package private implementation of InetAddressImpl for dual
031         * IPv4/IPv6 stack.
032         * <p>
033         * If InetAddress.preferIPv6Address is true then anyLocalAddress(),
034         * loopbackAddress(), and localHost() will return IPv6 addresses, 
035         * otherwise IPv4 addresses.
036         *
037         * @since 1.4
038         */
039
040        class Inet6AddressImpl implements  InetAddressImpl {
041            public native String getLocalHostName() throws UnknownHostException;
042
043            public native InetAddress[] lookupAllHostAddr(String hostname)
044                    throws UnknownHostException;
045
046            public native String getHostByAddr(byte[] addr)
047                    throws UnknownHostException;
048
049            private native boolean isReachable0(byte[] addr, int scope,
050                    int timeout, byte[] inf, int ttl, int if_scope)
051                    throws IOException;
052
053            public boolean isReachable(InetAddress addr, int timeout,
054                    NetworkInterface netif, int ttl) throws IOException {
055                byte[] ifaddr = null;
056                int scope = -1;
057                int netif_scope = -1;
058                if (netif != null) {
059                    /*
060                     * Let's make sure we bind to an address of the proper family.
061                     * Which means same family as addr because at this point it could
062                     * be either an IPv6 address or an IPv4 address (case of a dual
063                     * stack system).
064                     */
065                    java.util.Enumeration it = netif.getInetAddresses();
066                    InetAddress inetaddr = null;
067                    while (it.hasMoreElements()) {
068                        inetaddr = (InetAddress) it.nextElement();
069                        if (inetaddr.getClass().isInstance(addr)) {
070                            ifaddr = inetaddr.getAddress();
071                            if (inetaddr instanceof  Inet6Address) {
072                                netif_scope = ((Inet6Address) inetaddr)
073                                        .getScopeId();
074                            }
075                            break;
076                        }
077                    }
078                    if (ifaddr == null) {
079                        // Interface doesn't support the address family of 
080                        // the destination
081                        return false;
082                    }
083                }
084                if (addr instanceof  Inet6Address)
085                    scope = ((Inet6Address) addr).getScopeId();
086                return isReachable0(addr.getAddress(), scope, timeout, ifaddr,
087                        ttl, netif_scope);
088            }
089
090            public synchronized InetAddress anyLocalAddress() {
091                if (anyLocalAddress == null) {
092                    if (InetAddress.preferIPv6Address) {
093                        anyLocalAddress = new Inet6Address();
094                        anyLocalAddress.hostName = "::";
095                    } else {
096                        anyLocalAddress = (new Inet4AddressImpl())
097                                .anyLocalAddress();
098                    }
099                }
100                return anyLocalAddress;
101            }
102
103            public synchronized InetAddress loopbackAddress() {
104                if (loopbackAddress == null) {
105                    if (InetAddress.preferIPv6Address) {
106                        byte[] loopback = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
107                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
108                                0x00, 0x01 };
109                        loopbackAddress = new Inet6Address("localhost",
110                                loopback);
111                    } else {
112                        loopbackAddress = (new Inet4AddressImpl())
113                                .loopbackAddress();
114                    }
115                }
116                return loopbackAddress;
117            }
118
119            private InetAddress anyLocalAddress;
120            private InetAddress loopbackAddress;
121        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.