38 |
|
|
39 |
package java.net; |
package java.net; |
40 |
|
|
|
import gnu.classpath.Configuration; |
|
|
|
|
41 |
import java.io.IOException; |
import java.io.IOException; |
42 |
import java.io.ObjectInputStream; |
import java.io.ObjectInputStream; |
43 |
import java.io.ObjectOutputStream; |
import java.io.ObjectOutputStream; |
120 |
|
|
121 |
static |
static |
122 |
{ |
{ |
|
// load the shared library needed for name resolution |
|
|
if (Configuration.INIT_LOAD_LIBRARY) |
|
|
System.loadLibrary("javanet"); |
|
|
|
|
123 |
// Look for properties that override default caching behavior |
// Look for properties that override default caching behavior |
124 |
cache_size = |
cache_size = |
125 |
Integer.getInteger("gnu.java.net.dns_cache_size", DEFAULT_CACHE_SIZE) |
Integer.getInteger("gnu.java.net.dns_cache_size", DEFAULT_CACHE_SIZE) |
372 |
|
|
373 |
try |
try |
374 |
{ |
{ |
375 |
hostName = getHostByAddr(addr); |
hostName = VMInetAddress.getHostByAddr(addr); |
376 |
return hostName; |
return hostName; |
377 |
} |
} |
378 |
catch (UnknownHostException e) |
catch (UnknownHostException e) |
665 |
return addresses; |
return addresses; |
666 |
|
|
667 |
// Not in cache, try the lookup |
// Not in cache, try the lookup |
668 |
byte[][] iplist = getHostByName(hostname); |
byte[][] iplist = VMInetAddress.getHostByName(hostname); |
669 |
|
|
670 |
if (iplist.length == 0) |
if (iplist.length == 0) |
671 |
throw new UnknownHostException(hostname); |
throw new UnknownHostException(hostname); |
756 |
{ |
{ |
757 |
if (inaddr_any == null) |
if (inaddr_any == null) |
758 |
{ |
{ |
759 |
byte[] tmp = lookupInaddrAny(); |
byte[] tmp = VMInetAddress.lookupInaddrAny(); |
760 |
inaddr_any = new Inet4Address(tmp, null); |
inaddr_any = new Inet4Address(tmp, null); |
761 |
} |
} |
762 |
|
|
764 |
} |
} |
765 |
|
|
766 |
/** |
/** |
|
* This native method looks up the hostname of the local machine |
|
|
* we are on. If the actual hostname cannot be determined, then the |
|
|
* value "localhost" will be used. This native method wrappers the |
|
|
* "gethostname" function. |
|
|
* |
|
|
* @return The local hostname. |
|
|
*/ |
|
|
private static native String getLocalHostname(); |
|
|
|
|
|
/** |
|
767 |
* Returns an InetAddress object representing the address of the current |
* Returns an InetAddress object representing the address of the current |
768 |
* host. |
* host. |
769 |
* |
* |
774 |
*/ |
*/ |
775 |
public static InetAddress getLocalHost() throws UnknownHostException |
public static InetAddress getLocalHost() throws UnknownHostException |
776 |
{ |
{ |
777 |
String hostname = getLocalHostname(); |
String hostname = VMInetAddress.getLocalHostname(); |
778 |
return getByName(hostname); |
return getByName(hostname); |
779 |
} |
} |
780 |
|
|
|
/** |
|
|
* Returns the value of the special address INADDR_ANY |
|
|
*/ |
|
|
private static native byte[] lookupInaddrAny() throws UnknownHostException; |
|
|
|
|
|
/** |
|
|
* This method returns the hostname for a given IP address. It will |
|
|
* throw an UnknownHostException if the hostname cannot be determined. |
|
|
* |
|
|
* @param ip The IP address as a byte array |
|
|
* |
|
|
* @return The hostname |
|
|
* |
|
|
* @exception UnknownHostException If the reverse lookup fails |
|
|
*/ |
|
|
private static native String getHostByAddr(byte[] ip) |
|
|
throws UnknownHostException; |
|
|
|
|
|
/** |
|
|
* Returns a list of all IP addresses for a given hostname. Will throw |
|
|
* an UnknownHostException if the hostname cannot be resolved. |
|
|
*/ |
|
|
private static native byte[][] getHostByName(String hostname) |
|
|
throws UnknownHostException; |
|
|
|
|
781 |
/* |
/* |
782 |
* Needed for serialization |
* Needed for serialization |
783 |
*/ |
*/ |