[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath:
Inet*Address fixes and cleanups
Kaffe CVS
cvs-commits at kaffe.org
Fri Oct 15 15:11:44 PDT 2004
PatchSet 5299
Date: 2004/10/15 19:00:28
Author: robilad
Branch: HEAD
Tag: (none)
Log:
Resynced with GNU Classpath: Inet*Address fixes and cleanups
2004-10-15 Dalibor Topic <robilad at kaffe.org>
* libraries/clib/net/PlainDatagramSocketImpl.c:
(gnu_java_net_PlainDatagramSocketImpl_receive0) Adapted
to use public constructor.
* libraries/javalib/java/net/Inet4Address.java,
libraries/javalib/java/net/Inet6Address.java,
libraries/javalib/java/net/InetAddress.java:
Resynced with GNU Classpath.
2004-10-15 Michael Koch <konqueror at gmx.de>
* java/net/Inet4Address.java
(writeReplace): Use two-argument constructor of InetAddress.
(Inet4Address): Remove unused constructors. Use two-argument
constructor of InetAddress in remaining constructor.
* java/net/Inet6Address.java
(Inet6Address): Use two-argument constructor of InetAddress.
* java/net/InetAddress.java
(LOCALHOST): New static field to store object for localhost.
(static): Initialize LOCALHOST.
(hostname_alias): Removed.
(InetAdress): Removed hostname_alias argument.
(getHostName): Don't handle alias anymore.
(getCanonicalHostName): New method.
(toString): Don't handle alias anymore.
(getByName): Simply call getAllByName() and return its first result
entry.
(getAllByName): Handle null argument properly.
Members:
ChangeLog:1.2851->1.2852
libraries/clib/net/PlainDatagramSocketImpl.c:1.46->1.47
libraries/javalib/java/net/Inet4Address.java:1.7->1.8
libraries/javalib/java/net/Inet6Address.java:1.4->1.5
libraries/javalib/java/net/InetAddress.java:1.23->1.24
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2851 kaffe/ChangeLog:1.2852
--- kaffe/ChangeLog:1.2851 Fri Oct 15 14:38:57 2004
+++ kaffe/ChangeLog Fri Oct 15 19:00:28 2004
@@ -1,5 +1,36 @@
2004-10-15 Dalibor Topic <robilad at kaffe.org>
+ * libraries/clib/net/PlainDatagramSocketImpl.c:
+ (gnu_java_net_PlainDatagramSocketImpl_receive0) Adapted
+ to use public constructor.
+
+ * libraries/javalib/java/net/Inet4Address.java,
+ libraries/javalib/java/net/Inet6Address.java,
+ libraries/javalib/java/net/InetAddress.java:
+ Resynced with GNU Classpath.
+
+ 2004-10-15 Michael Koch <konqueror at gmx.de>
+
+ * java/net/Inet4Address.java
+ (writeReplace): Use two-argument constructor of InetAddress.
+ (Inet4Address): Remove unused constructors. Use two-argument
+ constructor of InetAddress in remaining constructor.
+ * java/net/Inet6Address.java
+ (Inet6Address): Use two-argument constructor of InetAddress.
+ * java/net/InetAddress.java
+ (LOCALHOST): New static field to store object for localhost.
+ (static): Initialize LOCALHOST.
+ (hostname_alias): Removed.
+ (InetAdress): Removed hostname_alias argument.
+ (getHostName): Don't handle alias anymore.
+ (getCanonicalHostName): New method.
+ (toString): Don't handle alias anymore.
+ (getByName): Simply call getAllByName() and return its first result
+ entry.
+ (getAllByName): Handle null argument properly.
+
+2004-10-15 Dalibor Topic <robilad at kaffe.org>
+
* libraries/javalib/gnu/java/nio/charset/UTF_16Encoder.java:
Resynced with GNU Classpath.
Index: kaffe/libraries/clib/net/PlainDatagramSocketImpl.c
diff -u kaffe/libraries/clib/net/PlainDatagramSocketImpl.c:1.46 kaffe/libraries/clib/net/PlainDatagramSocketImpl.c:1.47
--- kaffe/libraries/clib/net/PlainDatagramSocketImpl.c:1.46 Tue Jun 1 19:41:54 2004
+++ kaffe/libraries/clib/net/PlainDatagramSocketImpl.c Fri Oct 15 19:00:30 2004
@@ -376,8 +376,8 @@
memcpy(unhand_byte_array(array_address), &addr.addr4.sin_addr, sizeof(addr.addr4.sin_addr));
unhand(pkt)->address = (struct Hjava_net_InetAddress*)
- execute_java_constructor("java/net/Inet4Address", 0, 0, "([B)V",
- array_address);
+ execute_java_constructor("java/net/Inet4Address", 0, 0, "([BLjava/lang/String;)V",
+ array_address, NULL);
#if defined(HAVE_STRUCT_SOCKADDR_IN6)
} else if (addr.addr6.sin6_family == AF_INET6) {
@@ -386,7 +386,7 @@
unhand(pkt)->address = (struct Hjava_net_InetAddress*)
execute_java_constructor("java/net/Inet6Address", 0, 0, "([BLjava/lang/String;)V",
- array_address);
+ array_address, NULL);
#endif /* defined(HAVE_STRUCT_SOCKADDR_IN6) */
} else {
Index: kaffe/libraries/javalib/java/net/Inet4Address.java
diff -u kaffe/libraries/javalib/java/net/Inet4Address.java:1.7 kaffe/libraries/javalib/java/net/Inet4Address.java:1.8
--- kaffe/libraries/javalib/java/net/Inet4Address.java:1.7 Sun Sep 12 15:11:03 2004
+++ kaffe/libraries/javalib/java/net/Inet4Address.java Fri Oct 15 19:00:30 2004
@@ -1,5 +1,5 @@
-/* Inet4Address.java
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+/* Inet4Address.java --
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,23 +35,20 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
+
package java.net;
import java.io.ObjectStreamException;
import java.util.Arrays;
-
-/**
- * @author Michael Koch
- * @date August 3, 2002.
- */
-
/*
* Written using on-line Java Platform 1.4 API Specification and
* RFC 1884 (http://www.ietf.org/rfc/rfc1884.txt),
* RFC 1918 (http://www.ietf.org/rfc/rfc1918.txt),
* RFC 2365 (http://www.ietf.org/rfc/rfc2365.txt)
- * Status: Believed complete and correct.
+ *
+ * @author Michael Koch
+ * @status Believed complete and correct.
*/
public final class Inet4Address extends InetAddress
{
@@ -65,47 +62,22 @@
*/
private Object writeReplace() throws ObjectStreamException
{
- return new InetAddress(addr, hostName, null);
+ return new InetAddress(addr, hostName);
}
/**
* Initializes this object's addr instance variable from the passed in
- * byte array. Note that this constructor is package-private and is called
- * only by static methods in InetAddress.
- *
- * @param addr
- */
- Inet4Address(byte[] addr)
- {
- this(addr, null, null);
- }
-
- /**
- * Creates a Inet4Address
- *
- * @param addr The IP address
- * @param host The Hostname
- */
- Inet4Address(byte[] addr, String host)
- {
- this(addr, host, null);
- }
-
- /**
- * Initializes this object's addr instance variable from the passed in
* byte array. Note that this constructor is protected and is called
* only by static methods in this class.
*
* @param addr The IP number of this address as an array of bytes
* @param hostname The hostname of this IP address.
- * @param hostname_alias A backup hostname to use if hostname is null to
- * prevent reverse lookup failures
*/
- Inet4Address(byte[] addr, String hostname, String hostname_alias)
+ Inet4Address(byte[] addr, String host)
{
- super(addr, hostname, hostname_alias);
+ super(addr, host);
}
-
+
/**
* Checks if the address is a multicast address
*
Index: kaffe/libraries/javalib/java/net/Inet6Address.java
diff -u kaffe/libraries/javalib/java/net/Inet6Address.java:1.4 kaffe/libraries/javalib/java/net/Inet6Address.java:1.5
--- kaffe/libraries/javalib/java/net/Inet6Address.java:1.4 Mon May 17 22:25:05 2004
+++ kaffe/libraries/javalib/java/net/Inet6Address.java Fri Oct 15 19:00:30 2004
@@ -1,5 +1,5 @@
-/* Inet6Address.java
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+/* Inet6Address.java --
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -35,20 +35,17 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
+
package java.net;
import java.util.Arrays;
-
-/**
- * @author Michael Koch
- * @date August 3, 2002.
- */
-
/*
* Written using on-line Java Platform 1.4 API Specification and
* RFC 1884 (http://www.ietf.org/rfc/rfc1884.txt)
- * Status: Believed complete and correct.
+ *
+ * @author Michael Koch
+ * @status Believed complete and correct.
*/
public final class Inet6Address extends InetAddress
{
@@ -67,7 +64,7 @@
*/
Inet6Address(byte[] addr, String host)
{
- super(addr, host, null);
+ super(addr, host);
this.ipaddress = addr;
}
Index: kaffe/libraries/javalib/java/net/InetAddress.java
diff -u kaffe/libraries/javalib/java/net/InetAddress.java:1.23 kaffe/libraries/javalib/java/net/InetAddress.java:1.24
--- kaffe/libraries/javalib/java/net/InetAddress.java:1.23 Mon Oct 4 13:02:52 2004
+++ kaffe/libraries/javalib/java/net/InetAddress.java Fri Oct 15 19:00:30 2004
@@ -100,6 +100,11 @@
static InetAddress ANY_IF;
/**
+ * Stores static localhost address object.
+ */
+ static InetAddress LOCALHOST;
+
+ /**
* The size of the cache.
*/
private static int cache_size = 0;
@@ -176,12 +181,15 @@
try
{
ANY_IF = getInaddrAny();
+
+ byte[] ip_localhost = { 127, 0, 0, 1 };
+ LOCALHOST = new Inet4Address(ip_localhost, "localhost");
}
catch (UnknownHostException uhe)
{
// Hmmm, make one up and hope that it works.
byte[] zeros = { 0, 0, 0, 0 };
- ANY_IF = new Inet4Address(zeros);
+ ANY_IF = new Inet4Address(zeros, "0.0.0.0");
}
}
@@ -203,11 +211,6 @@
String hostName;
/**
- * Backup hostname alias for this address.
- */
- transient String hostname_alias;
-
- /**
* The time this address was looked up.
*/
transient long lookup_time;
@@ -228,10 +231,8 @@
*
* @param ipaddr The IP number of this address as an array of bytes
* @param hostname The hostname of this IP address.
- * @param hostname_alias A backup hostname to use if hostname is null to
- * prevent reverse lookup failures
*/
- InetAddress(byte[] ipaddr, String hostname, String hostname_alias)
+ InetAddress(byte[] ipaddr, String hostname)
{
addr = new byte[ipaddr.length];
@@ -239,7 +240,6 @@
addr[i] = ipaddr[i];
this.hostName = hostname;
- this.hostname_alias = hostname_alias;
lookup_time = System.currentTimeMillis();
family = 2; /* AF_INET */
@@ -417,14 +417,37 @@
}
catch (UnknownHostException e)
{
- if (hostname_alias != null)
- return hostname_alias;
- else
- return getHostAddress();
+ return getHostAddress();
}
}
/**
+ * Returns the canonical hostname represented by this InetAddress
+ *
+ * @since 1.4
+ */
+ public String getCanonicalHostName()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ {
+ try
+ {
+ sm.checkConnect(hostName, -1);
+ }
+ catch (SecurityException e)
+ {
+ return getHostAddress();
+ }
+ }
+
+ // Try to find the FDQN now
+ // FIXME: This does not work with IPv6.
+ InetAddress address = new Inet4Address(getAddress(), null);
+ return address.getHostName();
+ }
+
+ /**
* Returns the IP address of this object as a byte array.
*
* @return IP address
@@ -532,8 +555,6 @@
if (hostName != null)
host = hostName;
- else if (hostname_alias != null)
- host = hostname_alias;
else
host = address;
@@ -639,22 +660,6 @@
public static InetAddress getByName(String hostname)
throws UnknownHostException
{
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkConnect(hostname, -1);
-
- // Default to current host if necessary
- // !!! THIS SHOULD NOT BE LOCAL HOST !!!
- // LOCALHOST == HOSTNAME and here WE WANT "localhost"
- if (hostname == null || hostname.length() == 0)
- return getByName(LOCALHOST_NAME);
-
- // Assume that the host string is an IP address
- byte[] address = aton(hostname);
- if (address != null)
- return new Inet4Address(address);
-
- // Try to resolve the host by DNS
InetAddress[] addresses = getAllByName(hostname);
return addresses[0];
}
@@ -683,34 +688,32 @@
if (s != null)
s.checkConnect(hostname, -1);
+ InetAddress[] addresses;
+
// Default to current host if necessary
- // !!! SEE getByName FOR THE REMARK !!!
+ // !!! THIS SHOULD NOT BE LOCAL HOST !!!
+ // LOCALHOST == HOSTNAME and here WE WANT "localhost"
if (hostname == null || hostname.equals(""))
hostname = LOCALHOST_NAME;
-
- // Check the cache for this host before doing a lookup
- InetAddress[] addresses = checkCacheFor(hostname);
-
- if (addresses != null)
- return addresses;
-
- byte[][] iplist;
if (hostname.equals(LOCALHOST_NAME))
{
- iplist = new byte[][] {
- new byte[] { 127, 0, 0, 1 }
- };
+ addresses = new InetAddress[1];
+ addresses[0] = LOCALHOST;
+ return addresses;
}
- else
- {
- // Not in cache, try the lookup
- iplist = impl.getHostByName(hostname);
+ // Check the cache for this host before doing a lookup
+ addresses = checkCacheFor(hostname);
+
+ if (addresses != null)
+ return addresses;
+
+ // Not in cache, try the lookup
+ byte[][] iplist = impl.getHostByName(hostname);
- if (iplist.length == 0)
- throw new UnknownHostException(hostname);
- }
+ if (iplist.length == 0)
+ throw new UnknownHostException(hostname);
addresses = new InetAddress[iplist.length];
@@ -719,15 +722,11 @@
if (iplist[i].length != 4 && iplist[i].length != 16)
throw new UnknownHostException (hostname);
- // Don't store the hostname in order to force resolution of the
- // canonical names of these ip's when the user asks for the hostname
- // But do specify the host alias so if the IP returned won't
- // reverse lookup we don't throw an exception.
// If the length is equal to 16 this is an IPv6 address.
if (iplist[i].length == 16)
addresses[i] = new Inet6Address(iplist[i], hostname);
else
- addresses[i] = new Inet4Address(iplist[i], null, hostname);
+ addresses[i] = new Inet4Address(iplist[i], hostname);
}
addToCache(hostname, addresses);
@@ -807,7 +806,7 @@
if (inaddr_any == null)
{
byte[] tmp = lookupInaddrAny();
- inaddr_any = new Inet4Address(tmp);
+ inaddr_any = new Inet4Address(tmp, null);
}
return inaddr_any;
More information about the kaffe
mailing list