diff options
author | Gary Benson <gbenson@redhat.com> | 2006-09-01 13:30:50 +0000 |
---|---|---|
committer | Gary Benson <gbenson@redhat.com> | 2006-09-01 13:30:50 +0000 |
commit | 2e9db9d80796926f1bd8c60e00437d1af35022c8 (patch) | |
tree | 52f344367b501078daeb91eb7f717f7c9c03946a | |
parent | 84156395428228fa8a8376022cb3d40d5512fe5b (diff) |
2006-09-01 Gary Benson <gbenson@redhat.com>
* java/net/InetAddress.java (getByAddress): Create Inet4Address
objects when passed IPv4-mapped IPv6 addresses.
(getByName, getAllByName): Defer to the above to ensure that the
correct Inet*Address objects are returned.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@116622 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | libjava/ChangeLog | 7 | ||||
-rw-r--r-- | libjava/java/net/InetAddress.java | 41 |
2 files changed, 23 insertions, 25 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 833ae3f2f95..65dcba1afd0 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,5 +1,12 @@ 2006-09-01 Gary Benson <gbenson@redhat.com> + * java/net/InetAddress.java (getByAddress): Create Inet4Address + objects when passed IPv4-mapped IPv6 addresses. + (getByName, getAllByName): Defer to the above to ensure that the + correct Inet*Address objects are returned. + +2006-09-01 Gary Benson <gbenson@redhat.com> + * java/net/InetAddress.java (getByName, getAllByName): Only perform security check when DNS lookups are required. diff --git a/libjava/java/net/InetAddress.java b/libjava/java/net/InetAddress.java index 1c312940c83..5bb9c0f6867 100644 --- a/libjava/java/net/InetAddress.java +++ b/libjava/java/net/InetAddress.java @@ -536,7 +536,20 @@ public class InetAddress implements Serializable return new Inet4Address(addr, host); if (addr.length == 16) - return new Inet6Address(addr, host); + { + for (int i = 0; i < 12; i++) + { + if (addr[i] != (i < 10 ? 0 : (byte) 0xFF)) + return new Inet6Address(addr, host); + } + + byte[] ip4addr = new byte[4]; + ip4addr[0] = addr[12]; + ip4addr[1] = addr[13]; + ip4addr[2] = addr[14]; + ip4addr[3] = addr[15]; + return new Inet4Address(ip4addr, host); + } throw new UnknownHostException("IP address has illegal length"); } @@ -599,25 +612,7 @@ public class InetAddress implements Serializable // Assume that the host string is an IP address byte[] address = aton(hostname); if (address != null) - { - if (address.length == 4) - return new Inet4Address (address, null); - else if (address.length == 16) - { - if ((address [10] == 0xFF) && (address [11] == 0xFF)) - { - byte[] ip4addr = new byte [4]; - ip4addr [0] = address [12]; - ip4addr [1] = address [13]; - ip4addr [2] = address [14]; - ip4addr [3] = address [15]; - return new Inet4Address (ip4addr, null); - } - return new Inet6Address (address, null); - } - else - throw new UnknownHostException ("Address has invalid length"); - } + return getByAddress(address); // Perform security check before resolving SecurityManager s = System.getSecurityManager(); @@ -658,11 +653,7 @@ public class InetAddress implements Serializable // Check if hostname is an IP address byte[] address = aton (hostname); if (address != null) - { - InetAddress[] result = new InetAddress [1]; - result [0] = new InetAddress (address, null); - return result; - } + return new InetAddress[] {getByAddress(address)}; // Perform security check before resolving SecurityManager s = System.getSecurityManager(); |