1 7 package java.net; 8 import java.io.IOException ; 9 10 20 21 class Inet6AddressImpl implements InetAddressImpl { 22 public native String getLocalHostName() throws UnknownHostException ; 23 public native InetAddress [] 24 lookupAllHostAddr(String hostname) throws UnknownHostException ; 25 public native String getHostByAddr(byte[] addr) throws UnknownHostException ; 26 private native boolean isReachable0(byte[] addr, int scope, int timeout, byte[] inf, int ttl, int if_scope) throws IOException ; 27 28 public boolean isReachable(InetAddress addr, int timeout, NetworkInterface netif, int ttl) throws IOException { 29 byte[] ifaddr = null; 30 int scope = -1; 31 int netif_scope = -1; 32 if (netif != null) { 33 39 java.util.Enumeration it = netif.getInetAddresses(); 40 InetAddress inetaddr = null; 41 while (it.hasMoreElements()) { 42 inetaddr = (InetAddress ) it.nextElement(); 43 if (inetaddr.getClass().isInstance(addr)) { 44 ifaddr = inetaddr.getAddress(); 45 if (inetaddr instanceof Inet6Address ) { 46 netif_scope = ((Inet6Address ) inetaddr).getScopeId(); 47 } 48 break; 49 } 50 } 51 if (ifaddr == null) { 52 return false; 55 } 56 } 57 if (addr instanceof Inet6Address ) 58 scope = ((Inet6Address ) addr).getScopeId(); 59 return isReachable0(addr.getAddress(), scope, timeout, ifaddr, ttl, netif_scope); 60 } 61 62 public synchronized InetAddress anyLocalAddress() { 63 if (anyLocalAddress == null) { 64 if (InetAddress.preferIPv6Address) { 65 anyLocalAddress = new Inet6Address (); 66 anyLocalAddress.hostName = "::"; 67 } else { 68 anyLocalAddress = (new Inet4AddressImpl ()).anyLocalAddress(); 69 } 70 } 71 return anyLocalAddress; 72 } 73 74 public synchronized InetAddress loopbackAddress() { 75 if (loopbackAddress == null) { 76 if (InetAddress.preferIPv6Address) { 77 byte[] loopback = 78 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; 80 loopbackAddress = new Inet6Address ("localhost", loopback); 81 } else { 82 loopbackAddress = (new Inet4AddressImpl ()).loopbackAddress(); 83 } 84 } 85 return loopbackAddress; 86 } 87 88 private InetAddress anyLocalAddress; 89 private InetAddress loopbackAddress; 90 } 91 92 | Popular Tags |