< prev index next >

src/share/classes/java/net/Inet6AddressImpl.java

Print this page
rev 1564 : 7090158: Networking Libraries don't build with javac -Werror
7125055: ContentHandler.getContent API changed in error
Summary: Minor changes to networking java files to remove warnings
Reviewed-by: chegar, weijun, hawtin, alanb
Contributed-by: kurchi.subhra.hazra@oracle.com, sasha_bu@hotmail.com
   1 /*
   2  * Copyright (c) 2002, 2005, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  37  */
  38 
  39 class Inet6AddressImpl implements InetAddressImpl {
  40     public native String getLocalHostName() throws UnknownHostException;
  41     public native InetAddress[]
  42         lookupAllHostAddr(String hostname) throws UnknownHostException;
  43     public native String getHostByAddr(byte[] addr) throws UnknownHostException;
  44     private native boolean isReachable0(byte[] addr, int scope, int timeout, byte[] inf, int ttl, int if_scope) throws IOException;
  45 
  46     public boolean isReachable(InetAddress addr, int timeout, NetworkInterface netif, int ttl) throws IOException {
  47         byte[] ifaddr = null;
  48         int scope = -1;
  49         int netif_scope = -1;
  50         if (netif != null) {
  51             /*
  52              * Let's make sure we bind to an address of the proper family.
  53              * Which means same family as addr because at this point it could
  54              * be either an IPv6 address or an IPv4 address (case of a dual
  55              * stack system).
  56              */
  57             java.util.Enumeration it = netif.getInetAddresses();
  58             InetAddress inetaddr = null;
  59             while (it.hasMoreElements()) {
  60                 inetaddr = (InetAddress) it.nextElement();
  61                 if (inetaddr.getClass().isInstance(addr)) {
  62                     ifaddr = inetaddr.getAddress();
  63                     if (inetaddr instanceof Inet6Address) {
  64                         netif_scope = ((Inet6Address) inetaddr).getScopeId();
  65                     }
  66                     break;
  67                 }
  68             }
  69             if (ifaddr == null) {
  70                 // Interface doesn't support the address family of
  71                 // the destination
  72                 return false;
  73             }
  74         }
  75         if (addr instanceof Inet6Address)
  76             scope = ((Inet6Address) addr).getScopeId();
  77         return isReachable0(addr.getAddress(), scope, timeout, ifaddr, ttl, netif_scope);
  78     }
  79 
  80     public synchronized InetAddress anyLocalAddress() {


   1 /*
   2  * Copyright (c) 2002, 2011, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  37  */
  38 
  39 class Inet6AddressImpl implements InetAddressImpl {
  40     public native String getLocalHostName() throws UnknownHostException;
  41     public native InetAddress[]
  42         lookupAllHostAddr(String hostname) throws UnknownHostException;
  43     public native String getHostByAddr(byte[] addr) throws UnknownHostException;
  44     private native boolean isReachable0(byte[] addr, int scope, int timeout, byte[] inf, int ttl, int if_scope) throws IOException;
  45 
  46     public boolean isReachable(InetAddress addr, int timeout, NetworkInterface netif, int ttl) throws IOException {
  47         byte[] ifaddr = null;
  48         int scope = -1;
  49         int netif_scope = -1;
  50         if (netif != null) {
  51             /*
  52              * Let's make sure we bind to an address of the proper family.
  53              * Which means same family as addr because at this point it could
  54              * be either an IPv6 address or an IPv4 address (case of a dual
  55              * stack system).
  56              */
  57             java.util.Enumeration<InetAddress> it = netif.getInetAddresses();
  58             InetAddress inetaddr = null;
  59             while (it.hasMoreElements()) {
  60                 inetaddr = it.nextElement();
  61                 if (inetaddr.getClass().isInstance(addr)) {
  62                     ifaddr = inetaddr.getAddress();
  63                     if (inetaddr instanceof Inet6Address) {
  64                         netif_scope = ((Inet6Address) inetaddr).getScopeId();
  65                     }
  66                     break;
  67                 }
  68             }
  69             if (ifaddr == null) {
  70                 // Interface doesn't support the address family of
  71                 // the destination
  72                 return false;
  73             }
  74         }
  75         if (addr instanceof Inet6Address)
  76             scope = ((Inet6Address) addr).getScopeId();
  77         return isReachable0(addr.getAddress(), scope, timeout, ifaddr, ttl, netif_scope);
  78     }
  79 
  80     public synchronized InetAddress anyLocalAddress() {


< prev index next >