1 7 package java.net; 8 import java.io.IOException ; 9 10 15 class Inet4AddressImpl implements InetAddressImpl { 16 public native String getLocalHostName() throws UnknownHostException ; 17 public native InetAddress [] 18 lookupAllHostAddr(String hostname) throws UnknownHostException ; 19 public native String getHostByAddr(byte[] addr) throws UnknownHostException ; 20 private native boolean isReachable0(byte[] addr, int timeout, byte[] ifaddr, int ttl) throws IOException ; 21 22 public synchronized InetAddress anyLocalAddress() { 23 if (anyLocalAddress == null) { 24 anyLocalAddress = new Inet4Address (); anyLocalAddress.hostName = "0.0.0.0"; 26 } 27 return anyLocalAddress; 28 } 29 30 public synchronized InetAddress loopbackAddress() { 31 if (loopbackAddress == null) { 32 byte[] loopback = {0x7f,0x00,0x00,0x01}; 33 loopbackAddress = new Inet4Address ("localhost", loopback); 34 } 35 return loopbackAddress; 36 } 37 38 public boolean isReachable(InetAddress addr, int timeout, NetworkInterface netif, int ttl) throws IOException { 39 byte[] ifaddr = null; 40 if (netif != null) { 41 44 java.util.Enumeration it = netif.getInetAddresses(); 45 InetAddress inetaddr = null; 46 while (!(inetaddr instanceof Inet4Address ) && 47 it.hasMoreElements()) 48 inetaddr = (InetAddress ) it.nextElement(); 49 if (inetaddr instanceof Inet4Address ) 50 ifaddr = inetaddr.getAddress(); 51 } 52 return isReachable0(addr.getAddress(), timeout, ifaddr, ttl); 53 } 54 private InetAddress anyLocalAddress; 55 private InetAddress loopbackAddress; 56 } 57 58 | Popular Tags |