InetAddress.java (loopbackAddress): Renamed from localhostAddress.
2004-08-13 Bryce McKinlay <mckinlay@redhat.com> * java/net/InetAddress.java (loopbackAddress): Renamed from localhostAddress. (getByName): Return loopback address for null hostname, without security check. Use lookup(), not getAllByName. (getAllByName): Return loopback address for null hostname, without security check. * java/net/natInetAddressPosix.cc (lookup): Don't perform security check here. From-SVN: r85967
This commit is contained in:
parent
1ef02b9de5
commit
d7945fafe3
3 changed files with 33 additions and 18 deletions
|
@ -1,3 +1,14 @@
|
||||||
|
2004-08-13 Bryce McKinlay <mckinlay@redhat.com>
|
||||||
|
|
||||||
|
* java/net/InetAddress.java (loopbackAddress): Renamed from
|
||||||
|
localhostAddress.
|
||||||
|
(getByName): Return loopback address for null hostname, without
|
||||||
|
security check. Use lookup(), not getAllByName.
|
||||||
|
(getAllByName): Return loopback address for null hostname, without
|
||||||
|
security check.
|
||||||
|
* java/net/natInetAddressPosix.cc (lookup): Don't perform security
|
||||||
|
check here.
|
||||||
|
|
||||||
2004-08-13 Bryce McKinlay <mckinlay@redhat.com>
|
2004-08-13 Bryce McKinlay <mckinlay@redhat.com>
|
||||||
|
|
||||||
PR libgcj/17020
|
PR libgcj/17020
|
||||||
|
|
|
@ -68,7 +68,10 @@ public class InetAddress implements Serializable
|
||||||
*/
|
*/
|
||||||
static InetAddress ANY_IF;
|
static InetAddress ANY_IF;
|
||||||
|
|
||||||
private static final byte[] localhostAddress = { 127, 0, 0, 1 };
|
private static final byte[] loopbackAddress = { 127, 0, 0, 1 };
|
||||||
|
|
||||||
|
private static final InetAddress loopback
|
||||||
|
= new InetAddress (loopbackAddress, "localhost");
|
||||||
|
|
||||||
private static InetAddress localhost = null;
|
private static InetAddress localhost = null;
|
||||||
|
|
||||||
|
@ -564,7 +567,8 @@ public class InetAddress implements Serializable
|
||||||
* default. This method is equivalent to returning the first element in
|
* default. This method is equivalent to returning the first element in
|
||||||
* the InetAddress array returned from GetAllByName.
|
* the InetAddress array returned from GetAllByName.
|
||||||
*
|
*
|
||||||
* @param hostname The name of the desired host, or null for the local machine.
|
* @param hostname The name of the desired host, or null for the local
|
||||||
|
* loopback address.
|
||||||
*
|
*
|
||||||
* @return The address of the host as an InetAddress object.
|
* @return The address of the host as an InetAddress object.
|
||||||
*
|
*
|
||||||
|
@ -576,14 +580,15 @@ public class InetAddress implements Serializable
|
||||||
public static InetAddress getByName(String hostname)
|
public static InetAddress getByName(String hostname)
|
||||||
throws UnknownHostException
|
throws UnknownHostException
|
||||||
{
|
{
|
||||||
|
// If null or the empty string is supplied, the loopback address
|
||||||
|
// is returned. Note that this is permitted without a security check.
|
||||||
|
if (hostname == null || hostname.length() == 0)
|
||||||
|
return loopback;
|
||||||
|
|
||||||
SecurityManager s = System.getSecurityManager();
|
SecurityManager s = System.getSecurityManager();
|
||||||
if (s != null)
|
if (s != null)
|
||||||
s.checkConnect(hostname, -1);
|
s.checkConnect(hostname, -1);
|
||||||
|
|
||||||
// Default to current host if necessary
|
|
||||||
if (hostname == null || hostname.length() == 0)
|
|
||||||
return getLocalHost();
|
|
||||||
|
|
||||||
// Assume that the host string is an IP address
|
// Assume that the host string is an IP address
|
||||||
byte[] address = aton(hostname);
|
byte[] address = aton(hostname);
|
||||||
if (address != null)
|
if (address != null)
|
||||||
|
@ -608,8 +613,9 @@ public class InetAddress implements Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to resolve the host by DNS
|
// Try to resolve the host by DNS
|
||||||
InetAddress[] addresses = getAllByName(hostname);
|
InetAddress result = new InetAddress(null, null);
|
||||||
return addresses[0];
|
lookup (hostname, result, false);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -620,7 +626,7 @@ public class InetAddress implements Serializable
|
||||||
* hostname of the local machine is supplied by default.
|
* hostname of the local machine is supplied by default.
|
||||||
*
|
*
|
||||||
* @param hostname The name of the desired host, or null for the
|
* @param hostname The name of the desired host, or null for the
|
||||||
* local machine.
|
* local loopback address.
|
||||||
*
|
*
|
||||||
* @return All addresses of the host as an array of InetAddress objects.
|
* @return All addresses of the host as an array of InetAddress objects.
|
||||||
*
|
*
|
||||||
|
@ -632,6 +638,11 @@ public class InetAddress implements Serializable
|
||||||
public static InetAddress[] getAllByName(String hostname)
|
public static InetAddress[] getAllByName(String hostname)
|
||||||
throws UnknownHostException
|
throws UnknownHostException
|
||||||
{
|
{
|
||||||
|
// If null or the empty string is supplied, the loopback address
|
||||||
|
// is returned. Note that this is permitted without a security check.
|
||||||
|
if (hostname == null || hostname.length() == 0)
|
||||||
|
return new InetAddress[] {loopback};
|
||||||
|
|
||||||
SecurityManager s = System.getSecurityManager();
|
SecurityManager s = System.getSecurityManager();
|
||||||
if (s != null)
|
if (s != null)
|
||||||
s.checkConnect(hostname, -1);
|
s.checkConnect(hostname, -1);
|
||||||
|
@ -676,7 +687,7 @@ public class InetAddress implements Serializable
|
||||||
// However, if there is a security manager, and the cached result
|
// However, if there is a security manager, and the cached result
|
||||||
// is other than "localhost", we need to check again.
|
// is other than "localhost", we need to check again.
|
||||||
if (localhost == null
|
if (localhost == null
|
||||||
|| (s != null && localhost.addr != localhostAddress))
|
|| (s != null && ! localhost.isLoopbackAddress()))
|
||||||
getLocalHost (s);
|
getLocalHost (s);
|
||||||
|
|
||||||
return localhost;
|
return localhost;
|
||||||
|
@ -724,7 +735,7 @@ public class InetAddress implements Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
if (localhost == null)
|
if (localhost == null)
|
||||||
localhost = new InetAddress (localhostAddress, "localhost");
|
localhost = new InetAddress (loopbackAddress, "localhost");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -229,13 +229,6 @@ java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
|
||||||
{
|
{
|
||||||
if (!all)
|
if (!all)
|
||||||
host = JvNewStringUTF (hptr->h_name);
|
host = JvNewStringUTF (hptr->h_name);
|
||||||
java::lang::SecurityException *ex = checkConnect (host);
|
|
||||||
if (ex != NULL)
|
|
||||||
{
|
|
||||||
if (iaddr == NULL || iaddr->addr == NULL)
|
|
||||||
throw ex;
|
|
||||||
hptr = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (hptr == NULL)
|
if (hptr == NULL)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue