public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* FYI: Partial InetAddress merge
@ 2006-09-20  8:52 Gary Benson
  2006-09-20 12:15 ` RFT: The remainder of the " Gary Benson
  0 siblings, 1 reply; 9+ messages in thread
From: Gary Benson @ 2006-09-20  8:52 UTC (permalink / raw)
  To: java-patches

[-- Attachment #1: Type: text/plain, Size: 1498 bytes --]

Hi all,

Two weeks ago I merged all the good bits of GCJ's InetAddress into
Classpath's, removing some dead code and inconsistent stuff in the
process.  I then updated Classpath's SocketPermission to correctly
check hosts, and updated Classpath's InetAddress to correctly cache
DNS lookups.  This commit merges these changes.

I wanted to get the changes in before the branch, since without these
changes the security manager can provide no meaningful protection for
networking calls.  The reason this is a partial merge is that the full
merge requires Windows-specific changes that I am unable to test, and
the absence of any Windows testers looked to be a showstopper.  This
commit retains all the old native code, and the new "native" methods
are simply Java glue at the moment.

There are some tweaks to Posix-specific code.  These make the Posix
code correct; the corresponding Windows code is therefore wrong, but
no less broken than it was before.

I had to tweak classpath/java/net/Inet[46]Address.java because these
files contain definitions of AF_INET and AF_INET6 which end up in CNI
headers and get trampled by the preprocessor.  This tweak is not
necessary in the full merge as directly accessing these classes (and,
by extension, including their CNI headers) is incorrect.  The Posix
files no longer do this but the Windows ones still do.

This is all ugly and hacky.  I'll shortly be posting a full-merge
patch which I will commit directly after the branch is created.

Cheers,
Gary

[-- Attachment #2: inetaddress-semimerge.patch --]
[-- Type: text/plain, Size: 73483 bytes --]

Index: classpath/ChangeLog.gcj
===================================================================
--- classpath/ChangeLog.gcj	(revision 117073)
+++ classpath/ChangeLog.gcj	(working copy)
@@ -1,3 +1,18 @@
+2006-09-20  Gary Benson  <gbenson@redhat.com>
+
+	* classpath/java/net/InetAddress.java: Updated to latest.
+	* classpath/java/net/Inet4Address.java: Likewise.
+	* classpath/java/net/Inet6Address.java: Likewise.
+	* classpath/java/net/ResolverCache.java: Likewise.
+	* classpath/java/net/SocketPermission.java: Likewise.
+
+	* classpath/java/net/Inet4Address.java
+	(AF_INET): Renamed to FAMILY.
+	(<init>, writeReplace): Reflect the above.
+	* classpath/java/net/Inet6Address.java
+	(AF_INET6): Renamed to FAMILY.
+	(<init>): Reflect the above.
+
 2006-09-18  Tom Tromey  <tromey@redhat.com>
 
 	* gnu/javax/net/ssl/provider/SSLSocket.java (isBound, isClosed,
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 117073)
+++ ChangeLog	(working copy)
@@ -1,3 +1,17 @@
+2006-09-20  Gary Benson  <gbenson@redhat.com>
+
+	* java/net/InetAddress.java: Mostly merged with Classpath.
+	* java/net/VMInetAddress.java: New file.
+	* sources.am, Makefile.in: Rebuilt.
+
+	* java/net/natVMNetworkInterfacePosix.cc
+	(getInterfaces): Create InetAddress objects using
+	InetAddress.getByAddress.
+	* gnu/java/net/natPlainSocketImplPosix.cc
+	(accept, getOption): Likewise.
+	* gnu/java/net/natPlainDatagramSocketImplPosix.cc
+	(peekData, receive, getLocalAddress): Likewise.
+
 2006-09-19  Keith Seitz  <keiths@redhat.com>
 
 	* testsuite/libjava.jvmti/jvmti.exp: New file.
Index: classpath/java/net/InetAddress.java
===================================================================
--- classpath/java/net/InetAddress.java	(revision 117073)
+++ classpath/java/net/InetAddress.java	(working copy)
@@ -1,5 +1,6 @@
 /* InetAddress.java -- Class to model an Internet address
-   Copyright (C) 1998, 1999, 2002, 2004, 2005  Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2002, 2004, 2005, 2006
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -43,7 +44,6 @@
 import java.io.ObjectOutputStream;
 import java.io.ObjectStreamException;
 import java.io.Serializable;
-import java.util.StringTokenizer;
 
 /**
  * This class models an Internet address.  It does not have a public
@@ -57,6 +57,7 @@
  *
  * @author Aaron M. Renn (arenn@urbanophile.com)
  * @author Per Bothner
+ * @author Gary Benson (gbenson@redhat.com)
  *
  * @specnote This class is not final since JK 1.4
  */
@@ -65,37 +66,47 @@
   private static final long serialVersionUID = 3286316764910316507L;
 
   /**
-   * The special IP address INADDR_ANY.
-   */
-  private static InetAddress inaddr_any;
-
-  /**
    * Dummy InetAddress, used to bind socket to any (all) network interfaces.
    */
   static InetAddress ANY_IF;
-
+  static
+  {
+    byte[] addr;
+    try
+      {
+	addr = VMInetAddress.lookupInaddrAny();
+      }
+    catch (UnknownHostException e)
+      {
+	// Make one up and hope it works.
+	addr = new byte[] {0, 0, 0, 0};
+      }
+    try
+      {
+	ANY_IF = getByAddress(addr);
+      }
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
+    ANY_IF.hostName = ANY_IF.getHostName();
+  }
+  
   /**
    * Stores static localhost address object.
    */
   static InetAddress LOCALHOST;
-
   static
   {
-    // precompute the ANY_IF address
     try
       {
-        ANY_IF = getInaddrAny();
-
-	byte[] ip_localhost = { 127, 0, 0, 1 };
-	LOCALHOST = new Inet4Address(ip_localhost, "localhost");
+	LOCALHOST = getByAddress("localhost", new byte[] {127, 0, 0, 1});
       }
-    catch (UnknownHostException uhe)
+    catch (UnknownHostException e)
       {
-        // Hmmm, make one up and hope that it works.
-        byte[] zeros = { 0, 0, 0, 0 };
-        ANY_IF = new Inet4Address(zeros, "0.0.0.0");
+	throw new RuntimeException("should never happen", e);
       }
-  }
+  }    
 
   /**
    * The Serialized Form specifies that an int 'address' is saved/restored.
@@ -115,28 +126,28 @@
   String hostName;
 
   /**
-   * The field 'family' seems to be the AF_ value.
-   * FIXME: Much of the code in the other java.net classes does not make
-   * use of this family field.  A better implementation would be to make
-   * use of getaddrinfo() and have other methods just check the family
-   * field rather than examining the length of the address each time.
+   * Needed for serialization.
    */
-  int family;
+  private int family;
 
   /**
-   * 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.
+   * Constructor.  Prior to the introduction of IPv6 support in 1.4,
+   * methods such as InetAddress.getByName() would return InetAddress
+   * objects.  From 1.4 such methods returned either Inet4Address or
+   * Inet6Address objects, but for compatibility Inet4Address objects
+   * are serialized as InetAddresses.  As such, there are only two
+   * places where it is appropriate to invoke this constructor: within
+   * subclasses constructors and within Inet4Address.writeReplace().
    *
    * @param ipaddr The IP number of this address as an array of bytes
    * @param hostname The hostname of this IP address.
+   * @param family The address family of this IP address.
    */
-  InetAddress(byte[] ipaddr, String hostname)
+  InetAddress(byte[] ipaddr, String hostname, int family)
   {
     addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone();
     hostName = hostname;
-    
-    family = 2; /* AF_INET */
+    this.family = family;
   }
 
   /**
@@ -144,150 +155,144 @@
    * An address is multicast if the high four bits are "1110".  These are
    * also known as "Class D" addresses.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @return true if mulitcast, false if not
    *
    * @since 1.1
    */
   public boolean isMulticastAddress()
   {
-    // Mask against high order bits of 1110
-    if (addr.length == 4)
-      return (addr[0] & 0xf0) == 0xe0;
-
-    return false;
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if the InetAddress in a wildcard address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isAnyLocalAddress()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    return equals(ANY_IF);
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if the InetAddress is a loopback address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isLoopbackAddress()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    return (addr[0] & 0xff) == 0x7f;
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if InetAddress is a link local address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isLinkLocalAddress()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if InetAddress is a site local address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isSiteLocalAddress()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-
-    // 10.0.0.0/8
-    if ((addr[0] & 0xff) == 0x0a)
-      return true;
-
-    // 172.16.0.0/12
-    if ((addr[0] & 0xff) == 0xac && (addr[1] & 0xf0) == 0x10)
-      return true;
-
-    // 192.168.0.0/16
-    if ((addr[0] & 0xff) == 0xc0 && (addr[1] & 0xff) == 0xa8)
-      return true;
-
-    // XXX: Do we need to check more addresses here ?
-    return false;
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if InetAddress is a global multicast address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCGlobal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if InetAddress is a node local multicast address.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCNodeLocal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if InetAddress is a link local multicast address.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCLinkLocal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    if (! isMulticastAddress())
-      return false;
-
-    return ((addr[0] & 0xff) == 0xe0
-	    && (addr[1] & 0xff)  == 0x00
-	    && (addr[2] & 0xff)  == 0x00);
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if InetAddress is a site local multicast address.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCSiteLocal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    throw new UnsupportedOperationException();
   }
 
   /**
    * Utility routine to check if InetAddress is a organization local
    * multicast address.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCOrgLocal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    throw new UnsupportedOperationException();
   }
 
   /**
@@ -298,13 +303,20 @@
    */
   public String getHostName()
   {
-    if (hostName != null)
-      return hostName;
+    if (hostName == null)
+      hostName = getCanonicalHostName();
 
+    return hostName;
+  }
+
+  /**
+   * Returns the canonical hostname represented by this InetAddress
+   */
+  String internalGetCanonicalHostName()
+  {
     try
       {
-	hostName = VMInetAddress.getHostByAddr(addr);
-	return hostName;
+	return ResolverCache.getHostByAddr(addr);
       }
     catch (UnknownHostException e)
       {
@@ -319,12 +331,14 @@
    */
   public String getCanonicalHostName()
   {
+    String hostname = internalGetCanonicalHostName();
+
     SecurityManager sm = System.getSecurityManager();
     if (sm != null)
       {
         try
 	  {
-            sm.checkConnect(hostName, -1);
+            sm.checkConnect(hostname, -1);
 	  }
 	catch (SecurityException e)
 	  {
@@ -332,16 +346,7 @@
 	  }
       }
 
-    // Try to find the FDQN now
-    InetAddress address;
-    byte[] ipaddr = getAddress();
-
-    if (ipaddr.length == 16)
-      address = new Inet6Address(getAddress(), null);
-    else
-      address = new Inet4Address(getAddress(), null);
-
-    return address.getHostName();
+    return hostname;
   }
 
   /**
@@ -357,32 +362,19 @@
   }
 
   /**
-   * Returns the IP address of this object as a String.  The address is in
-   * the dotted octet notation, for example, "127.0.0.1".
+   * Returns the IP address of this object as a String.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @return The IP address of this object in String form
    *
    * @since 1.0.2
    */
   public String getHostAddress()
   {
-    StringBuffer sb = new StringBuffer(40);
-
-    int len = addr.length;
-    int i = 0;
-    
-    for ( ; ; )
-      {
-        sb.append(addr[i] & 0xff);
-        i++;
-	
-        if (i == len)
-          break;
-	
-        sb.append('.');
-      }
-
-    return sb.toString();
+    throw new UnsupportedOperationException();
   }
 
   /**
@@ -488,48 +480,50 @@
       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");
   }
 
   /**
-   * If hostname is a valid numeric IP address, return the numeric address.
-   * Otherwise, return null.
+   * Returns an InetAddress object representing the IP address of
+   * the given literal IP address in dotted decimal format such as
+   * "127.0.0.1".  This is used by SocketPermission.setHostPort()
+   * to parse literal IP addresses without performing a DNS lookup.
    *
-   * @param hostname the name of the host
+   * @param literal The literal IP address to create the InetAddress
+   * object from
+   *
+   * @return The address of the host as an InetAddress object, or
+   * null if the IP address is invalid.
    */
-  private static byte[] aton(String hostname)
+  static InetAddress getByLiteral(String literal)
   {
-    StringTokenizer st = new StringTokenizer(hostname, ".");
-
-    if (st.countTokens() == 4)
+    byte[] address = VMInetAddress.aton(literal);
+    if (address == null)
+      return null;
+    
+    try
       {
-	int index;
-	byte[] address = new byte[4];
-
-	for (index = 0; index < 4; index++)
-	  {
-	    try
-	      {
-		short n = Short.parseShort(st.nextToken());
-
-		if ((n < 0) || (n > 255))
-		  break;
-
-		address[index] = (byte) n;
-	      }
-	    catch (NumberFormatException e)
-	      {
-		break;
-	      }
-	  }
-
-	if (index == 4)
-	  return address;
+	return getByAddress(address);
       }
-
-    return null;
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
   }
 
   /**
@@ -577,63 +571,34 @@
   public static InetAddress[] getAllByName(String hostname)
     throws UnknownHostException
   {
-    SecurityManager s = System.getSecurityManager();
-    if (s != null)
-      s.checkConnect(hostname, -1);
+    // If null or the empty string is supplied, the loopback address
+    // is returned.
+    if (hostname == null || hostname.length() == 0)
+      return new InetAddress[] {LOCALHOST};
 
-    InetAddress[] addresses;
+    // Check if hostname is an IP address
+    InetAddress address = getByLiteral(hostname);
+    if (address != null)
+      return new InetAddress[] {address};
 
-    if (hostname != null)
-      hostname = hostname.trim();
+    // Perform security check before resolving
+    SecurityManager sm = System.getSecurityManager();
+    if (sm != null)
+      sm.checkConnect(hostname, -1);
 
-    // Default to current host if necessary
-    if (hostname == null || hostname.equals(""))
-      {
-	addresses = new InetAddress[1];
-	addresses[0] = LOCALHOST;
-	return addresses;
-      }
-
-    // Not in cache, try the lookup
-    byte[][] iplist = VMInetAddress.getHostByName(hostname);
-
+    // Resolve the hostname
+    byte[][] iplist = ResolverCache.getHostByName(hostname);
     if (iplist.length == 0)
       throw new UnknownHostException(hostname);
 
-    addresses = new InetAddress[iplist.length];
-
+    InetAddress[] addresses = new InetAddress[iplist.length];
     for (int i = 0; i < iplist.length; i++)
-      {
-	if (iplist[i].length != 4)
-	  throw new UnknownHostException(hostname);
+      addresses[i] = getByAddress(hostname, iplist[i]);
 
-	addresses[i] = new Inet4Address(iplist[i], hostname);
-      }
-
     return addresses;
   }
 
   /**
-   * Returns the special address INADDR_ANY used for binding to a local
-   * port on all IP addresses hosted by a the local host.
-   *
-   * @return An InetAddress object representing INDADDR_ANY
-   *
-   * @exception UnknownHostException If an error occurs
-   */
-  static InetAddress getInaddrAny() throws UnknownHostException
-  {
-    if (inaddr_any == null)
-      {
-	byte[] tmp = VMInetAddress.lookupInaddrAny();
-	inaddr_any = new Inet4Address(tmp, null);
-	inaddr_any.hostName = inaddr_any.getHostName();
-      }
-
-    return inaddr_any;
-  }
-
-  /**
    * Returns an InetAddress object representing the address of the current
    * host.
    *
@@ -645,11 +610,19 @@
   public static InetAddress getLocalHost() throws UnknownHostException
   {
     String hostname = VMInetAddress.getLocalHostname();
-    return getByName(hostname);
+    try
+      {
+	return getByName(hostname);
+      }
+    catch (SecurityException e)
+      {
+	return LOCALHOST;
+      }
   }
 
-  /*
-   * Needed for serialization
+  /**
+   * Inet4Address objects are serialized as InetAddress objects.
+   * This deserializes them back into Inet4Address objects.
    */
   private Object readResolve() throws ObjectStreamException
   {
@@ -665,8 +638,6 @@
 
     for (int i = 2; i >= 0; --i)
       addr[i] = (byte) (address >>= 8);
-
-    family = 2; /* AF_INET  */
   }
 
   private void writeObject(ObjectOutputStream oos) throws IOException
Index: classpath/java/net/Inet4Address.java
===================================================================
--- classpath/java/net/Inet4Address.java	(revision 117073)
+++ classpath/java/net/Inet4Address.java	(working copy)
@@ -1,5 +1,5 @@
 /* Inet4Address.java --
-   Copyright (C) 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -57,11 +57,16 @@
   static final long serialVersionUID = 3286316764910316507L;
 
   /**
-   * needed for serialization
+   * The address family of these addresses (used for serialization).
    */
+  private static final int FAMILY = 2; // AF_INET
+
+  /**
+   * Inet4Address objects are serialized as InetAddress objects.
+   */
   private Object writeReplace() throws ObjectStreamException
   {
-    return new InetAddress(addr, hostName);
+    return new InetAddress(addr, hostName, FAMILY);
   }
   
   /**
@@ -74,7 +79,7 @@
    */
   Inet4Address(byte[] addr, String host)
   {
-    super(addr, host);
+    super(addr, host, FAMILY);
   }
 
   /**
@@ -84,7 +89,7 @@
    */
   public boolean isMulticastAddress()
   {
-    return super.isMulticastAddress();
+    return (addr[0] & 0xf0) == 0xe0;
   }
 
   /**
@@ -92,7 +97,7 @@
    */
   public boolean isLoopbackAddress()
   {
-    return super.isLoopbackAddress();
+    return (addr[0] & 0xff) == 0x7f;
   }
 
   /**
@@ -102,7 +107,7 @@
    */
   public boolean isAnyLocalAddress()
   {
-    return super.isAnyLocalAddress();
+    return equals(InetAddress.ANY_IF);
   }
 
   /**
@@ -112,7 +117,7 @@
    */
   public boolean isLinkLocalAddress()
   {
-    return super.isLinkLocalAddress();
+    return false;
   }
 
   /**
@@ -122,7 +127,19 @@
    */
   public boolean isSiteLocalAddress()
   {
-    return super.isSiteLocalAddress();
+    // 10.0.0.0/8
+    if ((addr[0] & 0xff) == 0x0a)
+      return true;
+
+    // 172.16.0.0/12
+    if ((addr[0] & 0xff) == 0xac && (addr[1] & 0xf0) == 0x10)
+      return true;
+
+    // 192.168.0.0/16
+    if ((addr[0] & 0xff) == 0xc0 && (addr[1] & 0xff) == 0xa8)
+      return true;
+
+    return false;
   }
 
   /**
@@ -132,7 +149,7 @@
    */
   public boolean isMCGlobal()
   {
-    return super.isMCGlobal();
+    return false;
   }
 
   /**
@@ -142,7 +159,7 @@
    */
   public boolean isMCNodeLocal()
   {
-    return super.isMCNodeLocal();
+    return false;
   }
 
   /**
@@ -152,7 +169,12 @@
    */
   public boolean isMCLinkLocal()
   {
-    return super.isMCLinkLocal();
+    if (! isMulticastAddress())
+      return false;
+
+    return ((addr[0] & 0xff) == 0xe0
+	    && (addr[1] & 0xff)  == 0x00
+	    && (addr[2] & 0xff)  == 0x00);
   }
 
   /**
@@ -162,7 +184,7 @@
    */
   public boolean isMCSiteLocal()
   {
-    return super.isMCSiteLocal();
+    return false;
   }
 
   /**
@@ -172,7 +194,7 @@
    */
   public boolean isMCOrgLocal()
   {
-    return super.isMCOrgLocal();
+    return false;
   }
 
   /**
@@ -190,7 +212,23 @@
    */
   public String getHostAddress()
   {
-    return super.getHostAddress();
+    StringBuffer sb = new StringBuffer(40);
+
+    int len = addr.length;
+    int i = 0;
+    
+    for ( ; ; )
+      {
+        sb.append(addr[i] & 0xff);
+        i++;
+	
+        if (i == len)
+          break;
+	
+        sb.append('.');
+      }
+
+    return sb.toString();
   }
 
   /**
Index: classpath/java/net/Inet6Address.java
===================================================================
--- classpath/java/net/Inet6Address.java	(revision 117073)
+++ classpath/java/net/Inet6Address.java	(working copy)
@@ -1,5 +1,5 @@
 /* Inet6Address.java --
-   Copyright (C) 2002, 2003, 2004  Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -93,6 +93,11 @@
   private transient NetworkInterface nif; 
 
   /**
+   * The address family of these addresses (used for serialization).
+   */
+  private static final int FAMILY = 10; // AF_INET6
+
+  /**
    * Create an Inet6Address object
    *
    * @param addr The IP address
@@ -100,7 +105,7 @@
    */
   Inet6Address(byte[] addr, String host)
   {
-    super(addr, host);
+    super(addr, host, FAMILY);
     // Super constructor clones the addr.  Get a reference to the clone.
     this.ipaddress = this.addr;
     ifname = null;
Index: classpath/java/net/ResolverCache.java
===================================================================
--- classpath/java/net/ResolverCache.java	(revision 0)
+++ classpath/java/net/ResolverCache.java	(revision 0)
@@ -0,0 +1,269 @@
+/* ResolverCache.java -- A cache of resolver lookups for InetAddress.
+   Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.net;
+
+import java.security.Security;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+/**
+ * This class provides a cache of name service resolutions.  By
+ * default successful resolutions are cached forever to guard
+ * against DNS spoofing attacks and failed resolutions are cached
+ * for 10 seconds to improve performance.  The length of time that
+ * results remain in the cache is determined by the following
+ * security properties:
+ * <dl>
+ *   <dt><code>networkaddress.cache.ttl</code></dt>
+ *   <dd>
+ *     This property specifies the length of time in seconds that
+ *     successful resolutions remain in the cache.  The default is
+ *     -1, indicating to cache forever.
+ *   </dd>
+ *   <dt><code>networkaddress.cache.negative.ttl</code></dt>
+ *   <dd>
+ *     This property specifies the length of time in seconds that
+ *     unsuccessful resolutions remain in the cache.  The default
+ *     is 10, indicating to cache for 10 seconds.
+ *   </dd>
+ * In both cases, a value of -1 indicates to cache forever and a
+ * value of 0 indicates not to cache.
+ *
+ * @author Gary Benson (gbenson@redhat.com)
+ */
+class ResolverCache
+{
+  /**
+   * The time in seconds for which successful lookups are cached.
+   */
+  private static final int POSITIVE_TTL =
+    getTTL("networkaddress.cache.ttl", -1);
+
+  /**
+   * The time in seconds for which unsuccessful lookups are cached.
+   */
+  private static final int NEGATIVE_TTL =
+    getTTL("networkaddress.cache.negative.ttl", 10);
+
+  /**
+   * Helper function to set the TTLs.
+   */
+  private static int getTTL(String propName, int defaultValue)
+  {
+    String propValue = Security.getProperty(propName);
+    if (propValue == null)
+      return defaultValue;
+
+    return Integer.parseInt(propValue);
+  }
+
+  /**
+   * The cache itself.
+   */
+  private static HashMap cache = new HashMap();
+
+  /**
+   * List of entries which may expire.
+   */
+  private static LinkedList killqueue = new LinkedList();
+
+  /**
+   * Return the hostname for the specified IP address.
+   *
+   * @param ip The IP address as a byte array
+   *
+   * @return The hostname
+   *
+   * @exception UnknownHostException If the reverse lookup fails
+   */
+  public static String getHostByAddr(byte[] addr) throws UnknownHostException
+  {
+    Object key = makeHashableAddress(addr);
+    Entry entry = (Entry) get(key);
+    if (entry != null)
+      {
+	if (entry.value == null)
+	  throw new UnknownHostException();
+	return (String) entry.value;
+      }
+
+    try
+      {
+	String hostname = VMInetAddress.getHostByAddr(addr);
+	put(new Entry(key, hostname));
+	return hostname;
+      }
+    catch (UnknownHostException e)
+      {
+	put(new Entry(key, null));
+	throw e;
+      }
+  }
+
+  /**
+   * Return a list of all IP addresses for the specified hostname.
+   *
+   * @param hostname The hostname
+   *
+   * @return An list of IP addresses as byte arrays
+   *
+   * @exception UnknownHostException If the lookup fails
+   */
+  public static byte[][] getHostByName(String hostname)
+    throws UnknownHostException
+  {
+    Entry entry = (Entry) get(hostname);
+    if (entry != null)
+      {
+	if (entry.value == null)
+	  throw new UnknownHostException();
+	return (byte[][]) entry.value;
+      }
+
+    try
+      {
+	byte[][] addrs = VMInetAddress.getHostByName(hostname);
+	put(new Entry(hostname, addrs));
+	return addrs;
+      }
+    catch (UnknownHostException e)
+      {
+	put(new Entry(hostname, null));
+	throw e;
+      }
+  }
+
+  /**
+   * Convert an IP address expressed as a byte array into something
+   * we can use as a hashtable key.
+   */
+  private static Object makeHashableAddress(byte[] addr)
+  {
+    char[] chars = new char[addr.length];
+    for (int i = 0; i < addr.length; i++)
+      chars[i] = (char) addr[i];
+    return new String(chars);
+  }
+
+  /**
+   * Return the entry in the cache associated with the supplied key,
+   * or <code>null</code> if the cache does not contain an entry
+   * associated with this key.
+   */
+  private static synchronized Entry get(Object key)
+  {
+    reap();
+    return (Entry) cache.get(key);
+  }
+
+  /**
+   * Insert the supplied entry into the cache.
+   */
+  private static synchronized void put(Entry entry)
+  {
+    reap();
+    if (entry.expires != 0)
+      {
+	if (entry.expires != -1)
+	  killqueue.add(entry);
+	cache.put(entry.key, entry);
+      }
+  }
+
+  /**
+   * Clear expired entries.  This method is not synchronized, so
+   * it must only be called by methods that are.
+   */
+  private static void reap()
+  {
+    if (!killqueue.isEmpty())
+      {
+	long now = System.currentTimeMillis();
+
+	Iterator iter = killqueue.iterator();
+	while (iter.hasNext())
+	  {
+	    Entry entry = (Entry) iter.next();
+	    if (entry.expires > now)
+	      break;
+	    cache.remove(entry.key);
+	    iter.remove();
+	  }
+      }
+  }
+  
+  /**
+   * An entry in the cache.
+   */
+  private static class Entry
+  {
+    /**
+     * The key by which this entry is referenced.
+     */
+    public final Object key;
+
+    /**
+     * The entry itself.  A null value indicates a failed lookup.
+     */
+    public final Object value;
+    
+    /**
+     * The time when this cache entry expires.  If set to -1 then
+     * this entry will never expire.  If set to 0 then this entry
+     * expires immediately and will not be inserted into the cache.
+     */
+    public final long expires;
+
+    /**
+     * Constructor.
+     */
+    public Entry(Object key, Object value)
+    {
+      this.key = key;
+      this.value = value;
+
+      int ttl = value != null ? POSITIVE_TTL : NEGATIVE_TTL;
+      if (ttl < 1)
+	expires = ttl;
+      else
+	expires = System.currentTimeMillis() + ttl * 1000;
+    }
+  }
+}
Index: classpath/java/net/SocketPermission.java
===================================================================
--- classpath/java/net/SocketPermission.java	(revision 117073)
+++ classpath/java/net/SocketPermission.java	(working copy)
@@ -117,11 +117,18 @@
   static final long serialVersionUID = -7204263841984476862L;
 
   /**
-   * A hostname (possibly wildcarded) or IP address (IPv4 or IPv6).
+   * A hostname (possibly wildcarded).  Will be set if and only if
+   * this object was initialized with a hostname.
    */
-  private transient String host;
+  private transient String hostname = null;
 
   /**
+   * An IP address (IPv4 or IPv6).  Will be set if and only if this
+   * object was initialized with a single literal IP address.
+   */  
+  private transient InetAddress address = null;
+  
+  /**
    * A range of ports.
    */
   private transient int minport;
@@ -225,7 +232,7 @@
   private void setHostPort(String hostport)
   {
     // Split into host and ports
-    String ports;
+    String host, ports;
     if (hostport.charAt(0) == '[')
       {
 	// host is a bracketed IPv6 address
@@ -234,6 +241,10 @@
 	  throw new IllegalArgumentException("Unmatched '['");
 	host = hostport.substring(1, end);
 
+	address = InetAddress.getByLiteral(host);
+	if (address == null)
+	  throw new IllegalArgumentException("Bad IPv6 address");
+
 	if (end == hostport.length() - 1)
 	  ports = "";
 	else if (hostport.charAt(end + 1) == ':')
@@ -255,6 +266,15 @@
 	    host = hostport.substring(0, sep);
 	    ports = hostport.substring(sep + 1);
 	  }
+
+	address = InetAddress.getByLiteral(host);
+	if (address == null)
+	  {
+	    if (host.lastIndexOf('*') > 0)
+	      throw new IllegalArgumentException("Bad hostname");
+
+	    hostname = host;
+	  }
       }
 
     // Parse and validate the ports
@@ -362,10 +382,25 @@
     else
       return false;
 
-    return p.actionmask == actionmask &&
-      p.minport == minport &&
-      p.maxport == maxport &&
-      p.host.equals(host);
+    if (p.actionmask != actionmask ||
+	p.minport != minport ||
+	p.maxport != maxport)
+      return false;
+
+    if (address != null)
+      {
+	if (p.address == null)
+	  return false;
+	else
+	  return p.address.equals(address);
+      }
+    else
+      {
+	if (p.hostname == null)
+	  return false;
+	else
+	  return p.hostname.equals(hostname);
+      }
   }
 
   /**
@@ -376,7 +411,12 @@
    */
   public int hashCode()
   {
-    return actionmask + minport + maxport + host.hashCode();
+    int code = actionmask + minport + maxport;
+    if (address != null)
+      code += address.hashCode();
+    else
+      code += hostname.hashCode();
+    return code;
   }
 
   /**
@@ -416,6 +456,44 @@
   }
 
   /**
+   * Returns an array of all IP addresses represented by this object.
+   */
+  private InetAddress[] getAddresses()
+  {
+    if (address != null)
+      return new InetAddress[] {address};
+
+    try
+      {
+	return InetAddress.getAllByName(hostname);
+      }
+    catch (UnknownHostException e)
+      {
+	return new InetAddress[0];
+      }
+  }
+
+  /**
+   * Returns the canonical hostname represented by this object,
+   * or null if this object represents a wildcarded domain.
+   */
+  private String getCanonicalHostName()
+  {
+    if (address != null)
+      return address.internalGetCanonicalHostName();
+    if (hostname.charAt(0) == '*')
+      return null;
+    try
+      {
+	return InetAddress.getByName(hostname).internalGetCanonicalHostName();
+      }
+    catch (UnknownHostException e)
+      {
+	return null;
+      }
+  }
+  
+  /**
    * Returns true if the permission object passed it is implied by the
    * this permission.  This will be true if:
    * 
@@ -450,6 +528,11 @@
     else
       return false;
 
+    // If p was initialised with an empty hostname then we do not
+    // imply it. This is not part of the spec, but it seems necessary.
+    if (p.hostname != null && p.hostname.length() == 0)
+      return false;
+    
     // Next check the actions
     if ((p.actionmask & actionmask) != p.actionmask)
 	return false;
@@ -459,36 +542,54 @@
       return false;
 
     // Finally check the hosts
-    if (host.equals(p.host))
-      return true;
+    String p_canon = null;
 
-    // Try the canonical names
-    String ourcanonical = null;
-    String theircanonical = null;
-    try
+    // Return true if this object was initialized with a single
+    // IP address which one of p's IP addresses is equal to.
+    if (address != null)
       {
-	ourcanonical = InetAddress.getByName(host).getHostName();
-	theircanonical = InetAddress.getByName(p.host).getHostName();
+	InetAddress[] addrs = p.getAddresses();
+	for (int i = 0; i < addrs.length; i++)
+	  {
+	    if (address.equals(addrs[i]))
+	      return true;
+	  }
       }
-    catch (UnknownHostException e)
+
+    // Return true if this object is a wildcarded domain that
+    // p's canonical name matches.
+    if (hostname != null && hostname.charAt(0) == '*')
       {
-	// Who didn't resolve?  Just assume current address is canonical enough
-	// Is this ok to do?
-	if (ourcanonical == null)
-	  ourcanonical = host;
-	if (theircanonical == null)
-	  theircanonical = p.host;
+	p_canon = p.getCanonicalHostName();
+	if (p_canon != null && p_canon.endsWith(hostname.substring(1)))
+	  return true;
+	
       }
 
-    if (ourcanonical.equals(theircanonical))
-      return true;
+    // Return true if this one of this object's IP addresses
+    // is equal to one of p's.
+    if (address == null)
+      {
+	InetAddress[] addrs = p.getAddresses();
+	InetAddress[] p_addrs = p.getAddresses();
 
-    // Well, last chance.  Try for a wildcard
-    if (host.indexOf("*.") != -1)
+	for (int i = 0; i < addrs.length; i++)
+	  {
+	    for (int j = 0; j < p_addrs.length; j++)
+	      {
+		if (addrs[i].equals(p_addrs[j]))
+		  return true;
+	      }
+	  }
+      }
+
+    // Return true if this object's canonical name equals p's.
+    String canon = getCanonicalHostName();
+    if (canon != null)
       {
-	String wild_domain =
-	  host.substring(host.indexOf("*" + 1));
-	if (theircanonical.endsWith(wild_domain))
+	if (p_canon == null)
+	  p_canon = p.getCanonicalHostName();
+	if (p_canon != null && canon.equals(p_canon))
 	  return true;
       }
 
Index: java/net/InetAddress.java
===================================================================
--- java/net/InetAddress.java	(revision 117073)
+++ java/net/InetAddress.java	(working copy)
@@ -1,5 +1,6 @@
 /* InetAddress.java -- Class to model an Internet address
-   Copyright (C) 1998, 1999, 2002, 2004, 2005  Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2002, 2004, 2005, 2006
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -38,8 +39,6 @@
 
 package java.net;
 
-import gnu.classpath.Configuration;
-
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
@@ -58,6 +57,7 @@
  *
  * @author Aaron M. Renn (arenn@urbanophile.com)
  * @author Per Bothner
+ * @author Gary Benson (gbenson@redhat.com)
  *
  * @specnote This class is not final since JK 1.4
  */
@@ -69,23 +69,44 @@
    * Dummy InetAddress, used to bind socket to any (all) network interfaces.
    */
   static InetAddress ANY_IF;
-    
-  private static final byte[] loopbackAddress = { 127, 0, 0, 1 };
-
-  private static final InetAddress loopback 
-    = new Inet4Address(loopbackAddress, "localhost");
-
-  private static InetAddress localhost = null;
-
   static
   {
-    // load the shared library needed for name resolution
-    if (Configuration.INIT_LOAD_LIBRARY)
-      System.loadLibrary("javanet");
-    
-    byte[] zeros = { 0, 0, 0, 0 };
-    ANY_IF = new Inet4Address(zeros, "0.0.0.0");
+    byte[] addr;
+    try
+      {
+	addr = VMInetAddress.lookupInaddrAny();
+      }
+    catch (UnknownHostException e)
+      {
+	// Make one up and hope it works.
+	addr = new byte[] {0, 0, 0, 0};
+      }
+    try
+      {
+	ANY_IF = getByAddress(addr);
+      }
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
+    ANY_IF.hostName = ANY_IF.getHostName();
   }
+  
+  /**
+   * Stores static localhost address object.
+   */
+  static InetAddress LOCALHOST;
+  static
+  {
+    try
+      {
+	LOCALHOST = getByAddress("localhost", new byte[] {127, 0, 0, 1});
+      }
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
+  }    
 
   /**
    * The Serialized Form specifies that an int 'address' is saved/restored.
@@ -105,29 +126,28 @@
   String hostName;
 
   /**
-   * The field 'family' seems to be the AF_ value.
-   * FIXME: Much of the code in the other java.net classes does not make
-   * use of this family field.  A better implementation would be to make
-   * use of getaddrinfo() and have other methods just check the family
-   * field rather than examining the length of the address each time.
+   * Needed for serialization.
    */
-  int family;
+  private int family;
 
   /**
-   * 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.
+   * Constructor.  Prior to the introduction of IPv6 support in 1.4,
+   * methods such as InetAddress.getByName() would return InetAddress
+   * objects.  From 1.4 such methods returned either Inet4Address or
+   * Inet6Address objects, but for compatibility Inet4Address objects
+   * are serialized as InetAddresses.  As such, there are only two
+   * places where it is appropriate to invoke this constructor: within
+   * subclasses constructors and within Inet4Address.writeReplace().
    *
    * @param ipaddr The IP number of this address as an array of bytes
    * @param hostname The hostname of this IP address.
+   * @param family The address family of this IP address.
    */
-  InetAddress(byte[] ipaddr, String hostname)
+  InetAddress(byte[] ipaddr, String hostname, int family)
   {
     addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone();
     hostName = hostname;
-    
-    if (ipaddr != null)
-      family = getFamily(ipaddr);
+    this.family = family;
   }
 
   /**
@@ -135,154 +155,263 @@
    * An address is multicast if the high four bits are "1110".  These are
    * also known as "Class D" addresses.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @return true if mulitcast, false if not
    *
    * @since 1.1
    */
   public boolean isMulticastAddress()
   {
-    // Mask against high order bits of 1110
-    if (addr.length == 4)
-      return (addr[0] & 0xf0) == 0xe0;
-
-    // Mask against high order bits of 11111111
-    if (addr.length == 16)
-      return addr [0] == (byte) 0xFF;
-    
-    return false;
+    // This method is masked on Posix systems, where all InetAddress
+    // objects are created using InetAddress.getByAddress() which 
+    // returns either Inet4Address or Inet6Address objects.  Certain
+    // native methods on Win32 use "new InetAddress" in which case
+    // this method will be visible.
+    try
+      {
+	return getByAddress(hostName, addr).isMulticastAddress();
+      }
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
   }
 
   /**
    * Utility routine to check if the InetAddress in a wildcard address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isAnyLocalAddress()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    return equals(ANY_IF);
+    // This is inefficient, but certain methods on Win32 create
+    // InetAddress objects using "new InetAddress" rather than
+    // "InetAddress.getByAddress" so we provide a method body.
+    // This code is never executed on Posix systems.
+    try
+      {
+	return getByAddress(hostName, addr).isAnyLocalAddress();
+      }
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
   }
 
   /**
    * Utility routine to check if the InetAddress is a loopback address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isLoopbackAddress()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    return (addr[0] & 0xff) == 0x7f;
+    // This method is masked on Posix systems, where all InetAddress
+    // objects are created using InetAddress.getByAddress() which 
+    // returns either Inet4Address or Inet6Address objects.  Certain
+    // native methods on Win32 use "new InetAddress" in which case
+    // this method will be visible.
+    try
+      {
+	return getByAddress(hostName, addr).isLoopbackAddress();
+      }
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
   }
 
   /**
    * Utility routine to check if InetAddress is a link local address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isLinkLocalAddress()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    // This method is masked on Posix systems, where all InetAddress
+    // objects are created using InetAddress.getByAddress() which 
+    // returns either Inet4Address or Inet6Address objects.  Certain
+    // native methods on Win32 use "new InetAddress" in which case
+    // this method will be visible.
+    try
+      {
+	return getByAddress(hostName, addr).isLinkLocalAddress();
+      }
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
   }
 
   /**
    * Utility routine to check if InetAddress is a site local address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isSiteLocalAddress()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-
-    // 10.0.0.0/8
-    if ((addr[0] & 0xff) == 0x0a)
-      return true;
-
-    // 172.16.0.0/12
-    if ((addr[0] & 0xff) == 0xac && (addr[1] & 0xf0) == 0x10)
-      return true;
-
-    // 192.168.0.0/16
-    if ((addr[0] & 0xff) == 0xc0 && (addr[1] & 0xff) == 0xa8)
-      return true;
-
-    // XXX: Do we need to check more addresses here ?
-    return false;
+    // This method is masked on Posix systems, where all InetAddress
+    // objects are created using InetAddress.getByAddress() which 
+    // returns either Inet4Address or Inet6Address objects.  Certain
+    // native methods on Win32 use "new InetAddress" in which case
+    // this method will be visible.
+    try
+      {
+	return getByAddress(hostName, addr).isSiteLocalAddress();
+      }
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
   }
 
   /**
    * Utility routine to check if InetAddress is a global multicast address
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCGlobal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    // This method is masked on Posix systems, where all InetAddress
+    // objects are created using InetAddress.getByAddress() which 
+    // returns either Inet4Address or Inet6Address objects.  Certain
+    // native methods on Win32 use "new InetAddress" in which case
+    // this method will be visible.
+    try
+      {
+	return getByAddress(hostName, addr).isMCGlobal();
+      }
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
   }
 
   /**
    * Utility routine to check if InetAddress is a node local multicast address.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCNodeLocal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    // This method is masked on Posix systems, where all InetAddress
+    // objects are created using InetAddress.getByAddress() which 
+    // returns either Inet4Address or Inet6Address objects.  Certain
+    // native methods on Win32 use "new InetAddress" in which case
+    // this method will be visible.
+    try
+      {
+	return getByAddress(hostName, addr).isMCNodeLocal();
+      }
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
   }
 
   /**
    * Utility routine to check if InetAddress is a link local multicast address.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCLinkLocal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    if (! isMulticastAddress())
-      return false;
-
-    return ((addr[0] & 0xff) == 0xe0
-	    && (addr[1] & 0xff)  == 0x00
-	    && (addr[2] & 0xff)  == 0x00);
+    // This method is masked on Posix systems, where all InetAddress
+    // objects are created using InetAddress.getByAddress() which 
+    // returns either Inet4Address or Inet6Address objects.  Certain
+    // native methods on Win32 use "new InetAddress" in which case
+    // this method will be visible.
+    try
+      {
+	return getByAddress(hostName, addr).isMCLinkLocal();
+      }
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
   }
 
   /**
    * Utility routine to check if InetAddress is a site local multicast address.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCSiteLocal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    // This method is masked on Posix systems, where all InetAddress
+    // objects are created using InetAddress.getByAddress() which 
+    // returns either Inet4Address or Inet6Address objects.  Certain
+    // native methods on Win32 use "new InetAddress" in which case
+    // this method will be visible.
+    try
+      {
+	return getByAddress(hostName, addr).isMCSiteLocal();
+      }
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
   }
 
   /**
    * Utility routine to check if InetAddress is a organization local
    * multicast address.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @since 1.4
    */
   public boolean isMCOrgLocal()
   {
-    // This is the IPv4 implementation.
-    // Any class derived from InetAddress should override this.
-    // XXX: This seems to not exist with IPv4 addresses
-    return false;
+    // This method is masked on Posix systems, where all InetAddress
+    // objects are created using InetAddress.getByAddress() which 
+    // returns either Inet4Address or Inet6Address objects.  Certain
+    // native methods on Win32 use "new InetAddress" in which case
+    // this method will be visible.
+    try
+      {
+	return getByAddress(hostName, addr).isMCOrgLocal();
+      }
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
   }
 
   /**
@@ -293,28 +422,42 @@
    */
   public String getHostName()
   {
-    if (hostName != null)
-      return hostName;
+    if (hostName == null)
+      hostName = getCanonicalHostName();
 
-    // Lookup hostname and set field.
-    lookup (null, this, false);
-    
     return hostName;
   }
 
   /**
    * Returns the canonical hostname represented by this InetAddress
+   */
+  String internalGetCanonicalHostName()
+  {
+    try
+      {
+	return ResolverCache.getHostByAddr(addr);
+      }
+    catch (UnknownHostException e)
+      {
+	return getHostAddress();
+      }
+  }
+
+  /**
+   * Returns the canonical hostname represented by this InetAddress
    * 
    * @since 1.4
    */
   public String getCanonicalHostName()
   {
+    String hostname = internalGetCanonicalHostName();
+
     SecurityManager sm = System.getSecurityManager();
     if (sm != null)
       {
         try
 	  {
-            sm.checkConnect(hostName, -1);
+            sm.checkConnect(hostname, -1);
 	  }
 	catch (SecurityException e)
 	  {
@@ -322,16 +465,7 @@
 	  }
       }
 
-    // Try to find the FDQN now
-    InetAddress address;
-    byte[] ipaddr = getAddress();
-
-    if (ipaddr.length == 16)
-      address = new Inet6Address(getAddress(), null);
-    else
-      address = new Inet4Address(getAddress(), null);
-
-    return address.getHostName();
+    return hostname;
   }
 
   /**
@@ -346,91 +480,32 @@
     return (byte[]) addr.clone();
   }
 
-  /* Helper function due to a CNI limitation.  */
-  private static InetAddress[] allocArray (int count)
-  {
-    return new InetAddress [count];
-  }
-
-  /* Helper function due to a CNI limitation.  */
-  private static SecurityException checkConnect (String hostname)
-  {
-    SecurityManager s = System.getSecurityManager();
-    
-    if (s == null)
-      return null;
-    
-    try
-      {
-	s.checkConnect (hostname, -1);
-	return null;
-      }
-    catch (SecurityException ex)
-      {
-	return ex;
-      }
-  }
-
   /**
-   * Returns the IP address of this object as a String.  The address is in
-   * the dotted octet notation, for example, "127.0.0.1".
+   * Returns the IP address of this object as a String.
    *
+   * <p>This method cannot be abstract for backward compatibility reasons. By
+   * default it always throws {@link UnsupportedOperationException} unless
+   * overridden.</p>
+   * 
    * @return The IP address of this object in String form
    *
    * @since 1.0.2
    */
   public String getHostAddress()
   {
-    StringBuffer sb = new StringBuffer(40);
-
-    int len = addr.length;
-    int i = 0;
-    
-    if (len == 16)
-      { // An IPv6 address.
-	for ( ; ; i += 2)
-	  {
-	    if (i >= 16)
-	      return sb.toString();
-	    
-	    int x = ((addr [i] & 0xFF) << 8) | (addr [i + 1] & 0xFF);
-	    boolean empty = sb.length() == 0;
-	    
-	    if (empty)
-	      {
-		if (i == 10 && x == 0xFFFF)
-		  { // IPv4-mapped IPv6 address.
-		    sb.append (":FFFF:");
-		    break;  // Continue as IPv4 address;
-		  }
-		else if (i == 12)
-		  { // IPv4-compatible IPv6 address.
-		    sb.append (':');
-		    break;  // Continue as IPv4 address.
-		  }
-		else if (i > 0)
-		  sb.append ("::");
-	      }
-	    else
-	      sb.append (':');
-	    
-	    if (x != 0 || i >= 14)
-	      sb.append (Integer.toHexString (x).toUpperCase());
-	  }
+    // This method is masked on Posix systems, where all InetAddress
+    // objects are created using InetAddress.getByAddress() which 
+    // returns either Inet4Address or Inet6Address objects.  Certain
+    // native methods on Win32 use "new InetAddress" in which case
+    // this method will be visible.
+    try
+      {
+	return getByAddress(hostName, addr).getHostAddress();
       }
-    
-    for ( ; ; )
+    catch (UnknownHostException e)
       {
-        sb.append(addr[i] & 0xff);
-        i++;
-	
-        if (i == len)
-          break;
-	
-        sb.append('.');
+	throw new RuntimeException("should never happen", e);
       }
-
-    return sb.toString();
   }
 
   /**
@@ -555,35 +630,34 @@
   }
 
   /**
-   * If hostname is a valid numeric IP address, return the numeric address.
-   * Otherwise, return null.
+   * Returns an InetAddress object representing the IP address of
+   * the given literal IP address in dotted decimal format such as
+   * "127.0.0.1".  This is used by SocketPermission.setHostPort()
+   * to parse literal IP addresses without performing a DNS lookup.
    *
-   * @param hostname the name of the host
-   */
-  private static native byte[] aton(String hostname);
-
-  /**
-   * Looks up all addresses of a given host.
+   * @param literal The literal IP address to create the InetAddress
+   * object from
    *
-   * @param hostname the host to lookup
-   * @param ipaddr the IP address to lookup
-   * @param all return all known addresses for one host
-   *
-   * @return an array with all found addresses
+   * @return The address of the host as an InetAddress object, or
+   * null if the IP address is invalid.
    */
-  private static native InetAddress[] lookup (String hostname,
-		                              InetAddress ipaddr, boolean all);
+  static InetAddress getByLiteral(String literal)
+  {
+    byte[] address = VMInetAddress.aton(literal);
+    if (address == null)
+      return null;
+    
+    try
+      {
+	return getByAddress(address);
+      }
+    catch (UnknownHostException e)
+      {
+	throw new RuntimeException("should never happen", e);
+      }
+  }
 
   /**
-   * Returns tha family type of an IP address.
-   *
-   * @param addr the IP address
-   *
-   * @return the family
-   */
-  private static native int getFamily (byte[] ipaddr);
-
-  /**
    * Returns an InetAddress object representing the IP address of the given
    * hostname.  This name can be either a hostname such as "www.urbanophile.com"
    * or an IP address in dotted decimal format such as "127.0.0.1".  If the
@@ -604,25 +678,8 @@
   public static InetAddress getByName(String hostname)
     throws UnknownHostException
   {
-    // If null or the empty string is supplied, the loopback address
-    // is returned.
-    if (hostname == null || hostname.length() == 0)
-      return loopback;
-
-    // Assume that the host string is an IP address
-    byte[] address = aton(hostname);
-    if (address != null)
-      return getByAddress(address);
-
-    // Perform security check before resolving
-    SecurityManager s = System.getSecurityManager();
-    if (s != null)
-      s.checkConnect(hostname, -1);
-
-    // Try to resolve the host by DNS
-    InetAddress result = new InetAddress(null, null);
-    lookup (hostname, result, false);
-    return result;
+    InetAddress[] addresses = getAllByName(hostname);
+    return addresses[0];
   }
 
   /**
@@ -648,33 +705,31 @@
     // If null or the empty string is supplied, the loopback address
     // is returned.
     if (hostname == null || hostname.length() == 0)
-      return new InetAddress[] {loopback};
+      return new InetAddress[] {LOCALHOST};
 
     // Check if hostname is an IP address
-    byte[] address = aton (hostname);
+    InetAddress address = getByLiteral(hostname);
     if (address != null)
-      return new InetAddress[] {getByAddress(address)};
+      return new InetAddress[] {address};
 
     // Perform security check before resolving
-    SecurityManager s = System.getSecurityManager();
-    if (s != null)
-      s.checkConnect(hostname, -1);
+    SecurityManager sm = System.getSecurityManager();
+    if (sm != null)
+      sm.checkConnect(hostname, -1);
 
-    // Try to resolve the hostname by DNS
-    return lookup (hostname, null, true);
+    // Resolve the hostname
+    byte[][] iplist = ResolverCache.getHostByName(hostname);
+    if (iplist.length == 0)
+      throw new UnknownHostException(hostname);
+
+    InetAddress[] addresses = new InetAddress[iplist.length];
+    for (int i = 0; i < iplist.length; i++)
+      addresses[i] = getByAddress(hostname, iplist[i]);
+
+    return addresses;
   }
 
   /**
-   * 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();
-
-  /**
    * Returns an InetAddress object representing the address of the current
    * host.
    *
@@ -685,62 +740,24 @@
    */
   public static InetAddress getLocalHost() throws UnknownHostException
   {
-    SecurityManager s = System.getSecurityManager();
-    
-    // Experimentation shows that JDK1.2 does cache the result.
-    // However, if there is a security manager, and the cached result
-    // is other than "localhost", we need to check again.
-    if (localhost == null
-	|| (s != null && ! localhost.isLoopbackAddress()))
-      getLocalHost (s);
-    
-    return localhost;
-  }
-
-  private static synchronized void getLocalHost (SecurityManager s)
-    throws UnknownHostException
-  {
-    // Check the localhost cache again, now that we've synchronized.
-    if (s == null && localhost != null)
-      return;
-    
-    String hostname = getLocalHostname();
-    
-    if (hostname == null || hostname.length() == 0)
-      throw new UnknownHostException();
-
+    String hostname = VMInetAddress.getLocalHostname();
     try
       {
-	// "The Java Class Libraries" suggests that if the security
-	// manager disallows getting the local host name, then
-	// we use the loopback host.
-	// However, the JDK 1.2 API claims to throw SecurityException,
-	// which seems to suggest SecurityException is *not* caught.
-	// In this case, experimentation shows that former is correct.
-	if (s != null)
-	  {
-	    // This is wrong, if the name returned from getLocalHostname()
-	    // is not a fully qualified name.  FIXME.
-	    s.checkConnect (hostname, -1);
-	  }
-
-	localhost = new InetAddress (null, null);
-	lookup (hostname, localhost, false);
+	return getByName(hostname);
       }
-    catch (Exception ex)
+    catch (SecurityException e)
       {
-	UnknownHostException failure = new UnknownHostException(hostname);
-	failure.initCause(ex);
-	throw failure;
+	return LOCALHOST;
       }
   }
 
   /**
-   * Needed for serialization
+   * Inet4Address objects are serialized as InetAddress objects.
+   * This deserializes them back into Inet4Address objects.
    */
-  private void readResolve() throws ObjectStreamException
+  private Object readResolve() throws ObjectStreamException
   {
-    // FIXME: implement this
+    return new Inet4Address(addr, hostName);
   }
 
   private void readObject(ObjectInputStream ois)
@@ -752,13 +769,6 @@
 
     for (int i = 2; i >= 0; --i)
       addr[i] = (byte) (address >>= 8);
-
-    // Ignore family from serialized data.  Since the saved address is 32 bits
-    // the deserialized object will have an IPv4 address i.e. AF_INET family.
-    // FIXME: An alternative is to call the aton method on the deserialized
-    // hostname to get a new address.  The Serialized Form doc is silent
-    // on how these fields are used.
-    family = getFamily (addr);
   }
 
   private void writeObject(ObjectOutputStream oos) throws IOException
@@ -769,8 +779,35 @@
     int i = len - 4;
 
     for (; i < len; i++)
-      address = address << 8 | (((int) addr[i]) & 0xFF);
+      address = address << 8 | (addr[i] & 0xff);
 
     oos.defaultWriteObject();
   }
+
+  // The native methods remain here for now;
+  // methods in VMInetAddress map onto them.
+  static native byte[] aton(String hostname);
+  static native InetAddress[] lookup (String hostname,
+				      InetAddress ipaddr, boolean all);
+  static native int getFamily (byte[] ipaddr);
+  static native String getLocalHostname();
+
+  // Some soon-to-be-removed native code synchronizes on this.
+  static InetAddress loopbackAddress = LOCALHOST;
+  
+  // Some soon-to-be-removed code uses this old and broken method.
+  InetAddress(byte[] ipaddr, String hostname)
+  {
+    addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone();
+    hostName = hostname;
+
+    if (ipaddr != null)
+      family = getFamily(ipaddr);
+  }
+
+  // Some soon-to-be-removed native code uses this old method.
+  private static InetAddress[] allocArray (int count)
+  {
+    return new InetAddress [count];
+  }  
 }
Index: java/net/VMInetAddress.java
===================================================================
--- java/net/VMInetAddress.java	(revision 0)
+++ java/net/VMInetAddress.java	(revision 0)
@@ -0,0 +1,117 @@
+/* VMInetAddress.java -- Class to model an Internet address
+   Copyright (C) 2005  Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.net;
+
+import gnu.classpath.Configuration;
+
+import java.io.Serializable;
+
+class VMInetAddress implements Serializable
+{
+  static
+  {
+    if (Configuration.INIT_LOAD_LIBRARY)
+      System.loadLibrary("javanet");
+  }
+
+  /**
+   * This 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.
+   */
+  public static String getLocalHostname()
+  {
+    return InetAddress.getLocalHostname();
+  }
+
+  /**
+   * Returns the value of the special address INADDR_ANY
+   */
+  public static byte[] lookupInaddrAny() throws UnknownHostException
+  {
+    return new byte[] {0, 0, 0, 0};
+  }
+
+  /**
+   * 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
+   */
+  public static String getHostByAddr(byte[] ip) throws UnknownHostException
+  {
+    InetAddress addr = InetAddress.getByAddress(ip);
+    InetAddress.lookup(null, addr, false);
+    return addr.getHostName();
+  }
+
+  /**
+   * Returns a list of all IP addresses for a given hostname.  Will throw
+   * an UnknownHostException if the hostname cannot be resolved.
+   */
+  public static byte[][] getHostByName(String hostname)
+    throws UnknownHostException
+  {
+    InetAddress[] iaddrs = InetAddress.lookup(hostname, null, true);
+    byte[][] addrs = new byte[iaddrs.length][];
+    for (int i = 0; i < iaddrs.length; i++)
+      addrs[i] = iaddrs[i].getAddress();
+    return addrs;
+  }
+
+  /**
+   * Return the IP address represented by a literal address.
+   * Will return null if the literal address is not valid.
+   *
+   * @param address the name of the host
+   *
+   * @return The IP address as a byte array
+   */
+  public static byte[] aton(String address)
+  {
+    return InetAddress.aton(address);
+  }
+}
Index: sources.am
===================================================================
--- sources.am	(revision 117073)
+++ sources.am	(working copy)
@@ -5223,6 +5223,7 @@
 classpath/java/net/PasswordAuthentication.java \
 classpath/java/net/PortUnreachableException.java \
 classpath/java/net/ProtocolException.java \
+classpath/java/net/ResolverCache.java \
 classpath/java/net/ServerSocket.java \
 classpath/java/net/Socket.java \
 classpath/java/net/SocketAddress.java \
@@ -5243,6 +5244,7 @@
 classpath/java/net/URLStreamHandlerFactory.java \
 classpath/java/net/UnknownHostException.java \
 classpath/java/net/UnknownServiceException.java \
+java/net/VMInetAddress.java \
 java/net/VMNetworkInterface.java \
 java/net/VMURLConnection.java
 
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 117073)
+++ Makefile.in	(working copy)
@@ -4136,6 +4136,7 @@
 classpath/java/net/PasswordAuthentication.java \
 classpath/java/net/PortUnreachableException.java \
 classpath/java/net/ProtocolException.java \
+classpath/java/net/ResolverCache.java \
 classpath/java/net/ServerSocket.java \
 classpath/java/net/Socket.java \
 classpath/java/net/SocketAddress.java \
@@ -4156,6 +4157,7 @@
 classpath/java/net/URLStreamHandlerFactory.java \
 classpath/java/net/UnknownHostException.java \
 classpath/java/net/UnknownServiceException.java \
+java/net/VMInetAddress.java \
 java/net/VMNetworkInterface.java \
 java/net/VMURLConnection.java
 
Index: java/net/natVMNetworkInterfacePosix.cc
===================================================================
--- java/net/natVMNetworkInterfacePosix.cc	(revision 117073)
+++ java/net/natVMNetworkInterfacePosix.cc	(working copy)
@@ -40,7 +40,7 @@
 
 #include <gcj/cni.h>
 #include <jvm.h>
-#include <java/net/Inet4Address.h>
+#include <java/net/InetAddress.h>
 #include <java/net/NetworkInterface.h>
 #include <java/net/SocketException.h>
 #include <java/net/VMNetworkInterface.h>
@@ -148,8 +148,7 @@
       jbyteArray baddr = JvNewByteArray (len);
       memcpy (elements (baddr), &(sa.sin_addr), len);
       jstring if_name = JvNewStringLatin1 (if_record->ifr_name);
-      Inet4Address* address =
-        new java::net::Inet4Address (baddr, JvNewStringLatin1 (""));
+      InetAddress* address = java::net::InetAddress::getByAddress (baddr);
       ht->add (new NetworkInterface (if_name, address));
       if_record++;
     }
Index: gnu/java/net/natPlainSocketImplPosix.cc
===================================================================
--- gnu/java/net/natPlainSocketImplPosix.cc	(revision 117073)
+++ gnu/java/net/natPlainSocketImplPosix.cc	(working copy)
@@ -308,7 +308,7 @@
 
   s->native_fd = new_socket;
   s->localport = localport;
-  s->address = new ::java::net::InetAddress (raddr, NULL);
+  s->address = ::java::net::InetAddress::getByAddress (raddr);
   s->port = rport;
   return;
 
@@ -808,7 +808,7 @@
           else
             throw new ::java::net::SocketException
               (JvNewStringUTF ("invalid family"));
-          localAddress = new ::java::net::InetAddress (laddr, NULL);
+          localAddress = ::java::net::InetAddress::getByAddress (laddr);
         }
 
       return localAddress;
Index: gnu/java/net/natPlainDatagramSocketImplPosix.cc
===================================================================
--- gnu/java/net/natPlainDatagramSocketImplPosix.cc	(revision 117073)
+++ gnu/java/net/natPlainDatagramSocketImplPosix.cc	(working copy)
@@ -290,7 +290,7 @@
   else
     throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
 
-  p->setAddress (new ::java::net::InetAddress (raddr, NULL));
+  p->setAddress (::java::net::InetAddress::getByAddress (raddr));
   p->setPort (rport);
   p->length = (int) retlen;
   return rport;
@@ -430,7 +430,7 @@
   else
     throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
 
-  p->setAddress (new ::java::net::InetAddress (raddr, NULL));
+  p->setAddress (::java::net::InetAddress::getByAddress (raddr));
   p->setPort (rport);
   p->length = (jint) retlen;
   return;
@@ -564,7 +564,7 @@
   else
     throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
 
-  return new ::java::net::InetAddress (laddr, NULL);
+  return ::java::net::InetAddress::getByAddress (laddr);
 }
 
 void

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RFT: The remainder of the InetAddress merge
  2006-09-20  8:52 FYI: Partial InetAddress merge Gary Benson
@ 2006-09-20 12:15 ` Gary Benson
  2006-09-23 14:20   ` Mohan Embar
  2006-09-25 14:58   ` RFC: Updated " Gary Benson
  0 siblings, 2 replies; 9+ messages in thread
From: Gary Benson @ 2006-09-20 12:15 UTC (permalink / raw)
  To: java-patches

[-- Attachment #1: Type: text/plain, Size: 741 bytes --]

Hi again,

This patch is the second half of the InetAddress merge whose first
half I committed earlier today.  It removes GCJ's custom InetAddress,
and replaces the glue methods in VMInetAddress with real native code.

This passes make check and the latest Mauve InetAddress tests on my
Fedora Core 5 box, but while the native code is simply a rearrangement
of the old code there's a lot of conditional stuff in there so I'd
appreciate if people using older systems would check that it doesn't
break anything.  And the Win32 part is completely untested, so again
I'd appreciate if someone could test it for me.

Hopefully this can be tested and committed before 4.2 branches.
If not I'll just commit it immediately afterwards.

Cheers,
Gary

[-- Attachment #2: inetaddress-merge-rest.patch --]
[-- Type: text/plain, Size: 67429 bytes --]

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 117075)
+++ ChangeLog	(working copy)
@@ -1,3 +1,26 @@
+2006-09-20  Gary Benson  <gbenson@redhat.com>
+
+	* java/net/InetAddress.java: Removed.
+	* java/net/natInetAddressNoNet.cc: Likewise.
+	* java/net/natInetAddressPosix.cc: Likewise.
+	* java/net/natInetAddressWin32.cc: Likewise.
+	* java/net/VMInetAddress.java (getLocalHostname,
+	lookupInaddrAny, getHostByAddr, getHostByName,
+	aton): Replace glue methods with native ones.
+	* java/net/natVMInetAddressNoNet.cc: New file.
+	* java/net/natVMInetAddressPosix.cc: Likewise.
+	* java/net/natVMInetAddressWin32.cc: Likewise.
+	* Makefile.am, configure.ac: Reflect the above.
+	* sources.am, Makefile.in, configure: Rebuilt.
+
+	* java/net/natVMNetworkInterfaceWin32.cc
+	(winsock2GetRealNetworkInterfaces): Create InetAddress
+	objects using InetAddress.getByAddress.
+	* gnu/java/net/natPlainSocketImplWin32.cc
+	(accept, getOption): Likewise.
+	* gnu/java/net/natPlainDatagramSocketImplWin32.cc
+	(peekData, receive, getOption): Likewise.
+
 2006-09-20  Gary Benson  <gbenson@redhat.com>
 
 	* java/net/InetAddress.java: Mostly merged with Classpath.
Index: classpath/ChangeLog.gcj
===================================================================
--- classpath/ChangeLog.gcj	(revision 117080)
+++ classpath/ChangeLog.gcj	(working copy)
@@ -1,3 +1,12 @@
+2006-09-20  Gary Benson  <gbenson@redhat.com>
+
+	* java/net/Inet4Address.java
+	(FAMILY): Renamed to AF_INET.
+	(<init>, writeReplace): Reflect the above.
+	* java/net/Inet6Address.java
+	(FAMILY): Renamed to AF_INET6.
+	(<init>): Reflect the above.	
+
 2006-09-20  Gary Benson  <gbenson@redhat.com>
 
 	* java/net/InetAddress.java: Updated to latest.
Index: java/net/InetAddress.java
===================================================================
--- java/net/InetAddress.java	(revision 117075)
+++ java/net/InetAddress.java	(working copy)
@@ -1,813 +0,0 @@
-/* InetAddress.java -- Class to model an Internet address
-   Copyright (C) 1998, 1999, 2002, 2004, 2005, 2006
-   Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING.  If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library.  Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module.  An independent module is a module which is not derived from
-or based on this library.  If you modify this library, you may extend
-this exception to your version of the library, but you are not
-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.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamException;
-import java.io.Serializable;
-
-/**
- * This class models an Internet address.  It does not have a public
- * constructor.  Instead, new instances of this objects are created
- * using the static methods getLocalHost(), getByName(), and
- * getAllByName().
- *
- * <p>This class fulfills the function of the C style functions gethostname(),
- * gethostbyname(), and gethostbyaddr().  It resolves Internet DNS names
- * into their corresponding numeric addresses and vice versa.</p>
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- * @author Per Bothner
- * @author Gary Benson (gbenson@redhat.com)
- *
- * @specnote This class is not final since JK 1.4
- */
-public class InetAddress implements Serializable
-{
-  private static final long serialVersionUID = 3286316764910316507L;
-
-  /**
-   * Dummy InetAddress, used to bind socket to any (all) network interfaces.
-   */
-  static InetAddress ANY_IF;
-  static
-  {
-    byte[] addr;
-    try
-      {
-	addr = VMInetAddress.lookupInaddrAny();
-      }
-    catch (UnknownHostException e)
-      {
-	// Make one up and hope it works.
-	addr = new byte[] {0, 0, 0, 0};
-      }
-    try
-      {
-	ANY_IF = getByAddress(addr);
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-    ANY_IF.hostName = ANY_IF.getHostName();
-  }
-  
-  /**
-   * Stores static localhost address object.
-   */
-  static InetAddress LOCALHOST;
-  static
-  {
-    try
-      {
-	LOCALHOST = getByAddress("localhost", new byte[] {127, 0, 0, 1});
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }    
-
-  /**
-   * The Serialized Form specifies that an int 'address' is saved/restored.
-   * This class uses a byte array internally so we'll just do the conversion
-   * at serialization time and leave the rest of the algorithm as is.
-   */
-  private int address;
-
-  /**
-   * An array of octets representing an IP address.
-   */
-  transient byte[] addr;
-
-  /**
-   * The name of the host for this address.
-   */
-  String hostName;
-
-  /**
-   * Needed for serialization.
-   */
-  private int family;
-
-  /**
-   * Constructor.  Prior to the introduction of IPv6 support in 1.4,
-   * methods such as InetAddress.getByName() would return InetAddress
-   * objects.  From 1.4 such methods returned either Inet4Address or
-   * Inet6Address objects, but for compatibility Inet4Address objects
-   * are serialized as InetAddresses.  As such, there are only two
-   * places where it is appropriate to invoke this constructor: within
-   * subclasses constructors and within Inet4Address.writeReplace().
-   *
-   * @param ipaddr The IP number of this address as an array of bytes
-   * @param hostname The hostname of this IP address.
-   * @param family The address family of this IP address.
-   */
-  InetAddress(byte[] ipaddr, String hostname, int family)
-  {
-    addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone();
-    hostName = hostname;
-    this.family = family;
-  }
-
-  /**
-   * Returns true if this address is a multicast address, false otherwise.
-   * An address is multicast if the high four bits are "1110".  These are
-   * also known as "Class D" addresses.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @return true if mulitcast, false if not
-   *
-   * @since 1.1
-   */
-  public boolean isMulticastAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMulticastAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if the InetAddress in a wildcard address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isAnyLocalAddress()
-  {
-    // This is inefficient, but certain methods on Win32 create
-    // InetAddress objects using "new InetAddress" rather than
-    // "InetAddress.getByAddress" so we provide a method body.
-    // This code is never executed on Posix systems.
-    try
-      {
-	return getByAddress(hostName, addr).isAnyLocalAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if the InetAddress is a loopback address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isLoopbackAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isLoopbackAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a link local address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isLinkLocalAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isLinkLocalAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a site local address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isSiteLocalAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isSiteLocalAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a global multicast address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCGlobal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCGlobal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a node local multicast address.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCNodeLocal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCNodeLocal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a link local multicast address.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCLinkLocal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCLinkLocal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a site local multicast address.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCSiteLocal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCSiteLocal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a organization local
-   * multicast address.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCOrgLocal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCOrgLocal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Returns the hostname for this address.  This will return the IP address
-   * as a String if there is no hostname available for this address
-   *
-   * @return The hostname for this address
-   */
-  public String getHostName()
-  {
-    if (hostName == null)
-      hostName = getCanonicalHostName();
-
-    return hostName;
-  }
-
-  /**
-   * Returns the canonical hostname represented by this InetAddress
-   */
-  String internalGetCanonicalHostName()
-  {
-    try
-      {
-	return ResolverCache.getHostByAddr(addr);
-      }
-    catch (UnknownHostException e)
-      {
-	return getHostAddress();
-      }
-  }
-
-  /**
-   * Returns the canonical hostname represented by this InetAddress
-   * 
-   * @since 1.4
-   */
-  public String getCanonicalHostName()
-  {
-    String hostname = internalGetCanonicalHostName();
-
-    SecurityManager sm = System.getSecurityManager();
-    if (sm != null)
-      {
-        try
-	  {
-            sm.checkConnect(hostname, -1);
-	  }
-	catch (SecurityException e)
-	  {
-	    return getHostAddress();
-	  }
-      }
-
-    return hostname;
-  }
-
-  /**
-   * Returns the IP address of this object as a byte array.
-   *
-   * @return IP address
-   */
-  public byte[] getAddress()
-  {
-    // An experiment shows that JDK1.2 returns a different byte array each
-    // time.  This makes sense, in terms of security.
-    return (byte[]) addr.clone();
-  }
-
-  /**
-   * Returns the IP address of this object as a String.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @return The IP address of this object in String form
-   *
-   * @since 1.0.2
-   */
-  public String getHostAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).getHostAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Returns a hash value for this address.  Useful for creating hash
-   * tables.  Overrides Object.hashCode()
-   *
-   * @return A hash value for this address.
-   */
-  public int hashCode()
-  {
-    // There hashing algorithm is not specified, but a simple experiment
-    // shows that it is equal to the address, as a 32-bit big-endian integer.
-    int hash = 0;
-    int len = addr.length;
-    int i = len > 4 ? len - 4 : 0;
-
-    for (; i < len; i++)
-      hash = (hash << 8) | (addr[i] & 0xff);
-
-    return hash;
-  }
-
-  /**
-   * Tests this address for equality against another InetAddress.  The two
-   * addresses are considered equal if they contain the exact same octets.
-   * This implementation overrides Object.equals()
-   *
-   * @param obj The address to test for equality
-   *
-   * @return true if the passed in object's address is equal to this one's,
-   * false otherwise
-   */
-  public boolean equals(Object obj)
-  {
-    if (! (obj instanceof InetAddress))
-      return false;
-
-    // "The Java Class Libraries" 2nd edition says "If a machine has
-    // multiple names instances of InetAddress for different name of
-    // that same machine are not equal.  This is because they have
-    // different host names."  This violates the description in the
-    // JDK 1.2 API documentation.  A little experimentation
-    // shows that the latter is correct.
-    byte[] addr2 = ((InetAddress) obj).addr;
-
-    if (addr.length != addr2.length)
-      return false;
-
-    for (int i = 0; i < addr.length; i++)
-      if (addr[i] != addr2[i])
-	return false;
-
-    return true;
-  }
-
-  /**
-   * Converts this address to a String.  This string contains the IP in
-   * dotted decimal form. For example: "127.0.0.1"  This method is equivalent
-   * to getHostAddress() and overrides Object.toString()
-   *
-   * @return This address in String form
-   */
-  public String toString()
-  {
-    String addr = getHostAddress();
-    String host = (hostName != null) ? hostName : "";
-    return host + "/" + addr;
-  }
-
-  /**
-   * Returns an InetAddress object given the raw IP address.
-   *
-   * The argument is in network byte order: the highest order byte of the
-   * address is in getAddress()[0].
-   *
-   * @param addr The IP address to create the InetAddress object from
-   *
-   * @exception UnknownHostException If IP address has illegal length
-   *
-   * @since 1.4
-   */
-  public static InetAddress getByAddress(byte[] addr)
-    throws UnknownHostException
-  {
-    return getByAddress(null, addr);
-  }
-
-  /**
-   * Creates an InetAddress based on the provided host name and IP address.
-   * No name service is checked for the validity of the address.
-   *
-   * @param host The hostname of the InetAddress object to create
-   * @param addr The IP address to create the InetAddress object from
-   *
-   * @exception UnknownHostException If IP address is of illegal length
-   *
-   * @since 1.4
-   */
-  public static InetAddress getByAddress(String host, byte[] addr)
-    throws UnknownHostException
-  {
-    if (addr.length == 4)
-      return new Inet4Address(addr, host);
-
-    if (addr.length == 16)
-      {
-	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");
-  }
-
-  /**
-   * Returns an InetAddress object representing the IP address of
-   * the given literal IP address in dotted decimal format such as
-   * "127.0.0.1".  This is used by SocketPermission.setHostPort()
-   * to parse literal IP addresses without performing a DNS lookup.
-   *
-   * @param literal The literal IP address to create the InetAddress
-   * object from
-   *
-   * @return The address of the host as an InetAddress object, or
-   * null if the IP address is invalid.
-   */
-  static InetAddress getByLiteral(String literal)
-  {
-    byte[] address = VMInetAddress.aton(literal);
-    if (address == null)
-      return null;
-    
-    try
-      {
-	return getByAddress(address);
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Returns an InetAddress object representing the IP address of the given
-   * hostname.  This name can be either a hostname such as "www.urbanophile.com"
-   * or an IP address in dotted decimal format such as "127.0.0.1".  If the
-   * hostname is null or "", the hostname of the local machine is supplied by
-   * default.  This method is equivalent to returning the first element in
-   * the InetAddress array returned from GetAllByName.
-   *
-   * @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.
-   *
-   * @exception UnknownHostException If no IP address for the host could
-   * be found
-   * @exception SecurityException If a security manager exists and its
-   * checkConnect method doesn't allow the operation
-   */
-  public static InetAddress getByName(String hostname)
-    throws UnknownHostException
-  {
-    InetAddress[] addresses = getAllByName(hostname);
-    return addresses[0];
-  }
-
-  /**
-   * Returns an array of InetAddress objects representing all the host/ip
-   * addresses of a given host, given the host's name.  This name can be
-   * either a hostname such as "www.urbanophile.com" or an IP address in
-   * dotted decimal format such as "127.0.0.1".  If the value is null, the
-   * hostname of the local machine is supplied by default.
-   *
-   * @param hostname The name of the desired host, or null for the
-   * local loopback address.
-   *
-   * @return All addresses of the host as an array of InetAddress objects.
-   *
-   * @exception UnknownHostException If no IP address for the host could
-   * be found
-   * @exception SecurityException If a security manager exists and its
-   * checkConnect method doesn't allow the operation
-   */
-  public static InetAddress[] getAllByName(String hostname)
-    throws UnknownHostException
-  {
-    // If null or the empty string is supplied, the loopback address
-    // is returned.
-    if (hostname == null || hostname.length() == 0)
-      return new InetAddress[] {LOCALHOST};
-
-    // Check if hostname is an IP address
-    InetAddress address = getByLiteral(hostname);
-    if (address != null)
-      return new InetAddress[] {address};
-
-    // Perform security check before resolving
-    SecurityManager sm = System.getSecurityManager();
-    if (sm != null)
-      sm.checkConnect(hostname, -1);
-
-    // Resolve the hostname
-    byte[][] iplist = ResolverCache.getHostByName(hostname);
-    if (iplist.length == 0)
-      throw new UnknownHostException(hostname);
-
-    InetAddress[] addresses = new InetAddress[iplist.length];
-    for (int i = 0; i < iplist.length; i++)
-      addresses[i] = getByAddress(hostname, iplist[i]);
-
-    return addresses;
-  }
-
-  /**
-   * Returns an InetAddress object representing the address of the current
-   * host.
-   *
-   * @return The local host's address
-   *
-   * @exception UnknownHostException If no IP address for the host could
-   * be found
-   */
-  public static InetAddress getLocalHost() throws UnknownHostException
-  {
-    String hostname = VMInetAddress.getLocalHostname();
-    try
-      {
-	return getByName(hostname);
-      }
-    catch (SecurityException e)
-      {
-	return LOCALHOST;
-      }
-  }
-
-  /**
-   * Inet4Address objects are serialized as InetAddress objects.
-   * This deserializes them back into Inet4Address objects.
-   */
-  private Object readResolve() throws ObjectStreamException
-  {
-    return new Inet4Address(addr, hostName);
-  }
-
-  private void readObject(ObjectInputStream ois)
-    throws IOException, ClassNotFoundException
-  {
-    ois.defaultReadObject();
-    addr = new byte[4];
-    addr[3] = (byte) address;
-
-    for (int i = 2; i >= 0; --i)
-      addr[i] = (byte) (address >>= 8);
-  }
-
-  private void writeObject(ObjectOutputStream oos) throws IOException
-  {
-    // Build a 32 bit address from the last 4 bytes of a 4 byte IPv4 address
-    // or a 16 byte IPv6 address.
-    int len = addr.length;
-    int i = len - 4;
-
-    for (; i < len; i++)
-      address = address << 8 | (addr[i] & 0xff);
-
-    oos.defaultWriteObject();
-  }
-
-  // The native methods remain here for now;
-  // methods in VMInetAddress map onto them.
-  static native byte[] aton(String hostname);
-  static native InetAddress[] lookup (String hostname,
-				      InetAddress ipaddr, boolean all);
-  static native int getFamily (byte[] ipaddr);
-  static native String getLocalHostname();
-
-  // Some soon-to-be-removed native code synchronizes on this.
-  static InetAddress loopbackAddress = LOCALHOST;
-  
-  // Some soon-to-be-removed code uses this old and broken method.
-  InetAddress(byte[] ipaddr, String hostname)
-  {
-    addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone();
-    hostName = hostname;
-
-    if (ipaddr != null)
-      family = getFamily(ipaddr);
-  }
-
-  // Some soon-to-be-removed native code uses this old method.
-  private static InetAddress[] allocArray (int count)
-  {
-    return new InetAddress [count];
-  }  
-}
Index: java/net/natInetAddressNoNet.cc
===================================================================
--- java/net/natInetAddressNoNet.cc	(revision 117074)
+++ java/net/natInetAddressNoNet.cc	(working copy)
@@ -1,36 +0,0 @@
-/* Copyright (C) 2003  Free Software Foundation
-
-   This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
-
-#include <config.h>
-#include <stddef.h>
-
-#include <java/net/InetAddress.h>
-
-jbyteArray
-java::net::InetAddress::aton (jstring)
-{
-  return NULL;
-}
-
-jint
-java::net::InetAddress::getFamily (jbyteArray bytes)
-{
-  return 0;
-}
-
-JArray<java::net::InetAddress*> *
-java::net::InetAddress::lookup (jstring, java::net::InetAddress *, jboolean)
-{
-  return NULL;
-}
-
-jstring
-java::net::InetAddress::getLocalHostname ()
-{
-  return NULL;
-}
Index: java/net/natInetAddressPosix.cc
===================================================================
--- java/net/natInetAddressPosix.cc	(revision 117074)
+++ java/net/natInetAddressPosix.cc	(working copy)
@@ -1,304 +0,0 @@
-/* Copyright (C) 2003  Free Software Foundation
-
-   This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
-
-#include <config.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <string.h>
-#include <errno.h>
-
-#include <sys/param.h>
-#include <sys/types.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-
-#include <gcj/cni.h>
-#include <jvm.h>
-#include <java/net/InetAddress.h>
-#include <java/net/UnknownHostException.h>
-#include <java/lang/SecurityException.h>
-
-#if defined(HAVE_UNAME) && ! defined(HAVE_GETHOSTNAME)
-#include <sys/utsname.h>
-#endif
-
-#ifndef HAVE_GETHOSTNAME_DECL
-extern "C" int gethostname (char *name, int namelen);
-#endif
-
-jbyteArray
-java::net::InetAddress::aton (jstring host)
-{
-  char *hostname;
-  char buf[100];
-  int len = JvGetStringUTFLength(host);
-  if (len < 100)
-    hostname = buf;
-  else
-    hostname = (char*) _Jv_AllocBytes (len+1);
-  JvGetStringUTFRegion (host, 0, host->length(), hostname);
-  buf[len] = '\0';
-  char* bytes = NULL;
-  int blen = 0;
-#ifdef HAVE_INET_ATON
-  struct in_addr laddr;
-  if (inet_aton (hostname, &laddr))
-    {
-      bytes = (char*) &laddr;
-      blen = 4;
-    }
-#elif defined(HAVE_INET_ADDR)
-#if ! HAVE_IN_ADDR_T
-  typedef jint in_addr_t;
-#endif
-  in_addr_t laddr = inet_addr (hostname);
-  if (laddr != (in_addr_t)(-1))
-    {
-      bytes = (char*) &laddr;
-      blen = 4;
-    }
-#endif
-#if defined (HAVE_INET_PTON) && defined (HAVE_INET6)
-  char inet6_addr[16];
-  if (len != 0 && inet_pton (AF_INET6, hostname, inet6_addr) > 0)
-    {
-      bytes = inet6_addr;
-      blen = 16;
-    }
-#endif
-  if (blen == 0)
-    return NULL;
-  jbyteArray result = JvNewByteArray (blen);
-  memcpy (elements (result), bytes, blen);
-  return result;
-}
-
-jint
-java::net::InetAddress::getFamily (jbyteArray bytes)
-{
-  int len = bytes->length;
-  if (len == 4)
-    return AF_INET;
-#ifdef HAVE_INET6
-  else if (len == 16)
-    return AF_INET6;
-#endif /* HAVE_INET6 */
-  else
-    JvFail ("unrecognized size");
-}
-
-
-JArray<java::net::InetAddress*> *
-java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
-				jboolean all)
-{
-  struct hostent *hptr = NULL;
-#if defined (HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYADDR_R)
-  struct hostent hent_r;
-#if HAVE_STRUCT_HOSTENT_DATA
-  struct hostent_data fixed_buffer, *buffer_r = &fixed_buffer;
-#else
-#if defined (__GLIBC__) 
-  // FIXME: in glibc, gethostbyname_r returns NETDB_INTERNAL to herr and
-  // ERANGE to errno if the buffer size is too small, rather than what is 
-  // expected here. We work around this by setting a bigger buffer size and 
-  // hoping that it is big enough.
-  char fixed_buffer[1024];
-#else
-  char fixed_buffer[200];
-#endif
-  char *buffer_r = fixed_buffer;
-  int size_r = sizeof (fixed_buffer);
-#endif
-#endif
-
-  if (host != NULL)
-    {
-      char *hostname;
-      char buf[100];
-      int len = JvGetStringUTFLength(host);
-      if (len < 100)
-	hostname = buf;
-      else
-	hostname = (char*) _Jv_AllocBytes (len+1);
-      JvGetStringUTFRegion (host, 0, host->length(), hostname);
-      buf[len] = '\0';
-#ifdef HAVE_GETHOSTBYNAME_R
-      while (true)
-	{
-	  int ok;
-#if HAVE_STRUCT_HOSTENT_DATA
-	  ok = ! gethostbyname_r (hostname, &hent_r, buffer_r);
-#else
-	  int herr = 0;
-#ifdef GETHOSTBYNAME_R_RETURNS_INT
-	  ok = ! gethostbyname_r (hostname, &hent_r, buffer_r, size_r,
-				  &hptr, &herr);
-#else
-	  hptr = gethostbyname_r (hostname, &hent_r, buffer_r, size_r, &herr);
-	  ok = hptr != NULL;
-#endif /* GETHOSTNAME_R_RETURNS_INT */
-	  if (! ok && herr == ERANGE)
-	    {
-	      size_r *= 2;
-	      buffer_r = (char *) _Jv_AllocBytes (size_r);
-	    }
-	  else
-#endif /* HAVE_STRUCT_HOSTENT_DATA */
-	    break;
-	}
-#else
-      // FIXME: this is insufficient if some other piece of code calls
-      // this gethostbyname.
-      JvSynchronize sync (java::net::InetAddress::loopbackAddress);
-      hptr = gethostbyname (hostname);
-#endif /* HAVE_GETHOSTBYNAME_R */
-    }
-  else
-    {
-      jbyteArray bytes = iaddr->addr;
-      char *chars = (char*) elements (bytes);
-      int len = bytes->length;
-      int type;
-      char *val;
-      if (len == 4)
-	{
-	  val = chars;
-	  type = iaddr->family = AF_INET;
-	}
-#ifdef HAVE_INET6
-      else if (len == 16)
-	{
-	  val = (char *) &chars;
-	  type = iaddr->family = AF_INET6;
-	}
-#endif /* HAVE_INET6 */
-      else
-	JvFail ("unrecognized size");
-
-#ifdef HAVE_GETHOSTBYADDR_R
-      while (true)
-	{
-	  int ok;
-#if HAVE_STRUCT_HOSTENT_DATA
-	  ok = ! gethostbyaddr_r (val, len, type, &hent_r, buffer_r);
-#else
-	  int herr = 0;
-#ifdef GETHOSTBYADDR_R_RETURNS_INT
-	  ok = ! gethostbyaddr_r (val, len, type, &hent_r,
-				  buffer_r, size_r, &hptr, &herr);
-#else
-	  hptr = gethostbyaddr_r (val, len, type, &hent_r,
-				  buffer_r, size_r, &herr);
-	  ok = hptr != NULL;
-#endif /* GETHOSTBYADDR_R_RETURNS_INT */
-	  if (! ok && herr == ERANGE)
-	    {
-	      size_r *= 2;
-	      buffer_r = (char *) _Jv_AllocBytes (size_r);
-	    }
-	  else 
-#endif /* HAVE_STRUCT_HOSTENT_DATA */
-	    break;
-	}
-#else /* HAVE_GETHOSTBYADDR_R */
-      // FIXME: this is insufficient if some other piece of code calls
-      // this gethostbyaddr.
-      JvSynchronize sync (java::net::InetAddress::loopbackAddress);
-      hptr = gethostbyaddr (val, len, type);
-#endif /* HAVE_GETHOSTBYADDR_R */
-    }
-  if (hptr != NULL)
-    {
-      if (!all)
-        host = JvNewStringUTF (hptr->h_name);
-    }
-  if (hptr == NULL)
-    {
-      if (iaddr != NULL && iaddr->addr != NULL)
-	{
-	  iaddr->hostName = iaddr->getHostAddress();
-	  return NULL;
-	}
-      else
-	throw new java::net::UnknownHostException(host);
-    }
-  int count;
-  if (all)
-    {
-      char** ptr = hptr->h_addr_list;
-      count = 0;
-      while (*ptr++)  count++;
-    }
-  else
-    count = 1;
-  JArray<java::net::InetAddress*> *result;
-  java::net::InetAddress** iaddrs;
-  if (all)
-    {
-      result = java::net::InetAddress::allocArray (count);
-      iaddrs = elements (result);
-    }
-  else
-    {
-      result = NULL;
-      iaddrs = &iaddr;
-    }
-
-  for (int i = 0;  i < count;  i++)
-    {
-      if (iaddrs[i] == NULL)
-	iaddrs[i] = new java::net::InetAddress (NULL, NULL);
-      if (iaddrs[i]->hostName == NULL)
-        iaddrs[i]->hostName = host;
-      if (iaddrs[i]->addr == NULL)
-	{
-	  char *bytes = hptr->h_addr_list[i];
-	  iaddrs[i]->addr = JvNewByteArray (hptr->h_length);
-	  iaddrs[i]->family = getFamily (iaddrs[i]->addr);
-	  memcpy (elements (iaddrs[i]->addr), bytes, hptr->h_length);
-	}
-    }
-  return result;
-}
-
-jstring
-java::net::InetAddress::getLocalHostname ()
-{
-  char *chars;
-#ifdef HAVE_GETHOSTNAME
-  char buffer[MAXHOSTNAMELEN];
-  if (gethostname (buffer, MAXHOSTNAMELEN))
-    return NULL;
-  chars = buffer;
-#elif HAVE_UNAME
-  struct utsname stuff;
-  if (uname (&stuff) != 0)
-    return NULL;
-  chars = stuff.nodename;
-#else
-  return NULL;
-#endif
-  // It is admittedly non-optimal to convert the hostname to Unicode
-  // only to convert it back in getByName, but simplicity wins.  Note
-  // that unless there is a SecurityManager, we only get called once
-  // anyway, thanks to the InetAddress.localhost cache.
-  return JvNewStringUTF (chars);
-}
Index: java/net/natInetAddressWin32.cc
===================================================================
--- java/net/natInetAddressWin32.cc	(revision 117074)
+++ java/net/natInetAddressWin32.cc	(working copy)
@@ -1,168 +0,0 @@
-/* Copyright (C) 2003  Free Software Foundation
-
-   This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
-
-#include <config.h>
-#include <platform.h>
-
-#undef STRICT
-
-#include <java/net/InetAddress.h>
-#include <java/net/UnknownHostException.h>
-#include <java/lang/SecurityException.h>
-
-jbyteArray
-java::net::InetAddress::aton (jstring host)
-{
-  JV_TEMP_UTF_STRING (hostname, host);
-  char* bytes = NULL;
-  int blen = 0;
-  unsigned long laddr = inet_addr (hostname);
-  if (laddr != INADDR_NONE)
-    {
-      bytes = (char*) &laddr;
-      blen = 4;
-    }
-  if (blen == 0)
-    return NULL;
-  jbyteArray result = JvNewByteArray (blen);
-  memcpy (elements (result), bytes, blen);
-  return result;
-}
-
-jint
-java::net::InetAddress::getFamily (jbyteArray bytes)
-{
-  int len = bytes->length;
-  if (len == 4)
-    return AF_INET;
-#ifdef HAVE_INET6
-  else if (len == 16)
-    return AF_INET6;
-#endif /* HAVE_INET6 */
-  else
-    JvFail ("unrecognized size");
-}
-
-
-JArray<java::net::InetAddress*> *
-java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
-        jboolean all)
-{
-  struct hostent *hptr = NULL;
-  if (host != NULL)
-    {
-      JV_TEMP_UTF_STRING (hostname, host);
-
-      // FIXME: this is insufficient if some other piece of code calls
-      // this gethostbyname.
-      JvSynchronize sync (java::net::InetAddress::loopbackAddress);
-      hptr = gethostbyname (hostname);
-    }
-  else
-    {
-      jbyteArray bytes = iaddr->addr;
-      char *chars = (char*) elements (bytes);
-      int len = bytes->length;
-      int type;
-      char *val;
-      if (len == 4)
-        {
-          val = chars;
-          type = iaddr->family = AF_INET;
-        }
-#ifdef HAVE_INET6
-      else if (len == 16)
-      {
-        val = (char *) &chars;
-        type = iaddr->family = AF_INET6;
-      }
-#endif /* HAVE_INET6 */
-      else
-        JvFail ("unrecognized size");
-
-      // FIXME: this is insufficient if some other piece of code calls
-      // this gethostbyaddr.
-      JvSynchronize sync (java::net::InetAddress::loopbackAddress);
-      hptr = gethostbyaddr (val, len, type);
-    }
-  if (hptr != NULL)
-    {
-      if (!all)
-        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 (iaddr != NULL && iaddr->addr != NULL)
-        {
-          iaddr->hostName = iaddr->getHostAddress();
-          return NULL;
-        }
-      else
-        throw new java::net::UnknownHostException(host);
-    }
-
-  int count;
-  if (all)
-    {
-      char** ptr = hptr->h_addr_list;
-      count = 0;
-      while (*ptr++)  count++;
-    }
-  else
-    count = 1;
-
-  JArray<java::net::InetAddress*> *result;
-  java::net::InetAddress** iaddrs;
-  if (all)
-    {
-      result = java::net::InetAddress::allocArray (count);
-      iaddrs = elements (result);
-    }
-  else
-    {
-      result = NULL;
-      iaddrs = &iaddr;
-    }
-
-  for (int i = 0;  i < count;  i++)
-    {
-      if (iaddrs[i] == NULL)
-        iaddrs[i] = new java::net::InetAddress (NULL, NULL);
-      if (iaddrs[i]->hostName == NULL)
-        iaddrs[i]->hostName = host;
-      if (iaddrs[i]->addr == NULL)
-        {
-          char *bytes = hptr->h_addr_list[i];
-          iaddrs[i]->addr = JvNewByteArray (hptr->h_length);
-          iaddrs[i]->family = getFamily (iaddrs[i]->addr);
-          memcpy (elements (iaddrs[i]->addr), bytes, hptr->h_length);
-        }
-    }
-    
-  return result;
-}
-
-jstring
-java::net::InetAddress::getLocalHostname ()
-{
-  char buffer[400];
-  if (gethostname (buffer, sizeof(buffer)))
-    return NULL;
-  // It is admittedly non-optimal to convert the hostname to Unicode
-  // only to convert it back in getByName, but simplicity wins.  Note
-  // that unless there is a SecurityManager, we only get called once
-  // anyway, thanks to the InetAddress.localhost cache.
-  return JvNewStringUTF (buffer);
-}
Index: java/net/VMInetAddress.java
===================================================================
--- java/net/VMInetAddress.java	(revision 117075)
+++ java/net/VMInetAddress.java	(working copy)
@@ -58,18 +58,12 @@
    *
    * @return The local hostname.
    */
-  public static String getLocalHostname()
-  {
-    return InetAddress.getLocalHostname();
-  }
+  public static native String getLocalHostname();
 
   /**
    * Returns the value of the special address INADDR_ANY
    */
-  public static byte[] lookupInaddrAny() throws UnknownHostException
-  {
-    return new byte[] {0, 0, 0, 0};
-  }
+  public static native byte[] lookupInaddrAny() throws UnknownHostException;
 
   /**
    * This method returns the hostname for a given IP address.  It will
@@ -81,26 +75,15 @@
    *
    * @exception UnknownHostException If the reverse lookup fails
    */
-  public static String getHostByAddr(byte[] ip) throws UnknownHostException
-  {
-    InetAddress addr = InetAddress.getByAddress(ip);
-    InetAddress.lookup(null, addr, false);
-    return addr.getHostName();
-  }
+  public 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.
    */
-  public static byte[][] getHostByName(String hostname)
-    throws UnknownHostException
-  {
-    InetAddress[] iaddrs = InetAddress.lookup(hostname, null, true);
-    byte[][] addrs = new byte[iaddrs.length][];
-    for (int i = 0; i < iaddrs.length; i++)
-      addrs[i] = iaddrs[i].getAddress();
-    return addrs;
-  }
+  public static native byte[][] getHostByName(String hostname)
+    throws UnknownHostException;
 
   /**
    * Return the IP address represented by a literal address.
@@ -110,8 +93,5 @@
    *
    * @return The IP address as a byte array
    */
-  public static byte[] aton(String address)
-  {
-    return InetAddress.aton(address);
-  }
+  public static native byte[] aton(String address);
 }
Index: java/net/natVMInetAddressNoNet.cc
===================================================================
--- java/net/natVMInetAddressNoNet.cc	(revision 0)
+++ java/net/natVMInetAddressNoNet.cc	(revision 0)
@@ -0,0 +1,40 @@
+/* Copyright (C) 2003, 2006  Free Software Foundation
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+#include <config.h>
+#include <stddef.h>
+
+jstring
+java::net::VMInetAddress::getLocalHostname ()
+{
+  return NULL;
+}
+
+jbyteArray
+java::net::VMInetAddress::lookupInaddrAny ()
+{
+  return NULL;
+}
+
+jstring
+java::net::VMInetAddress::getHostByAddr (jbyteArray addr)
+{
+  return NULL;
+}
+
+JArray<jbyteArray> *
+java::net::VMInetAddress::getHostByName (jstring host)
+{
+  return NULL;
+}
+
+jbyteArray
+java::net::VMInetAddress::aton (jstring host)
+{
+  return NULL;
+}
Index: java/net/natVMInetAddressPosix.cc
===================================================================
--- java/net/natVMInetAddressPosix.cc	(revision 0)
+++ java/net/natVMInetAddressPosix.cc	(revision 0)
@@ -0,0 +1,289 @@
+/* Copyright (C) 2003, 2006  Free Software Foundation
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+#include <config.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <string.h>
+#include <errno.h>
+
+#include <sys/param.h>
+#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
+#include <gcj/cni.h>
+#include <jvm.h>
+#include <java/net/VMInetAddress.h>
+#include <java/net/UnknownHostException.h>
+
+#if defined(HAVE_UNAME) && ! defined(HAVE_GETHOSTNAME)
+#include <sys/utsname.h>
+#endif
+
+#ifndef HAVE_GETHOSTNAME_DECL
+extern "C" int gethostname (char *name, int namelen);
+#endif
+
+jstring
+java::net::VMInetAddress::getLocalHostname ()
+{
+  char *chars;
+#ifdef HAVE_GETHOSTNAME
+  char buffer[MAXHOSTNAMELEN];
+  if (gethostname (buffer, MAXHOSTNAMELEN))
+    return NULL;
+  chars = buffer;
+#elif HAVE_UNAME
+  struct utsname stuff;
+  if (uname (&stuff) != 0)
+    return NULL;
+  chars = stuff.nodename;
+#else
+  return NULL;
+#endif
+  // It is admittedly non-optimal to convert the hostname to Unicode
+  // only to convert it back in getByName, but simplicity wins.
+  return JvNewStringUTF (chars);
+}
+
+jbyteArray
+java::net::VMInetAddress::lookupInaddrAny ()
+{
+#if ! HAVE_IN_ADDR_T
+  typedef jint in_addr_t;
+#endif
+  in_addr_t laddr = INADDR_ANY;
+  char *bytes = (char *) &laddr;
+  int blen = sizeof (laddr);
+  jbyteArray result = JvNewByteArray (blen);
+  memcpy (elements (result), bytes, blen);
+  return result;
+}
+
+jstring
+java::net::VMInetAddress::getHostByAddr (jbyteArray addr)
+{
+  struct hostent *hptr = NULL;
+#ifdef HAVE_GETHOSTBYADDR_R
+  struct hostent hent_r;
+#if HAVE_STRUCT_HOSTENT_DATA
+  struct hostent_data fixed_buffer, *buffer_r = &fixed_buffer;
+#else
+#ifdef __GLIBC__
+  // FIXME: in glibc, gethostbyname_r returns NETDB_INTERNAL to herr and
+  // ERANGE to errno if the buffer size is too small, rather than what is 
+  // expected here. We work around this by setting a bigger buffer size and 
+  // hoping that it is big enough.
+  char fixed_buffer[1024];
+#else
+  char fixed_buffer[200];
+#endif /* __GLIBC__ */
+  char *buffer_r = fixed_buffer;
+  int size_r = sizeof (fixed_buffer);
+#endif /* HAVE_STRUCT_HOSTENT_DATA */
+#endif /* HAVE_GETHOSTBYADDR_R */
+
+  char *bytes = (char*) elements (addr);
+  int len = addr->length;
+  int type;
+  char *val;
+  if (len == 4)
+    {
+      val = bytes;
+      type = AF_INET;
+    }
+#ifdef HAVE_INET6
+  else if (len == 16)
+    {
+      val = (char *) &bytes;
+      type = AF_INET6;
+    }
+#endif /* HAVE_INET6 */
+  else
+    JvFail ("unrecognized size");
+
+#ifdef HAVE_GETHOSTBYADDR_R
+  while (true)
+    {
+      int ok;
+#if HAVE_STRUCT_HOSTENT_DATA
+      ok = ! gethostbyaddr_r (val, len, type, &hent_r, buffer_r);
+#else
+      int herr = 0;
+#ifdef GETHOSTBYADDR_R_RETURNS_INT
+      ok = ! gethostbyaddr_r (val, len, type, &hent_r,
+			      buffer_r, size_r, &hptr, &herr);
+#else
+      hptr = gethostbyaddr_r (val, len, type, &hent_r,
+			      buffer_r, size_r, &herr);
+      ok = hptr != NULL;
+#endif /* GETHOSTBYADDR_R_RETURNS_INT */
+      if (! ok && herr == ERANGE)
+	{
+	  size_r *= 2;
+	  buffer_r = (char *) _Jv_AllocBytes (size_r);
+	}
+      else 
+#endif /* HAVE_STRUCT_HOSTENT_DATA */
+	break;
+    }
+#else /* HAVE_GETHOSTBYADDR_R */
+  // FIXME: this is insufficient if some other piece of code calls
+  // this gethostbyaddr.
+  JvSynchronize sync (java::net::VMInetAddress::class$);
+  hptr = gethostbyaddr (val, len, type);
+#endif /* HAVE_GETHOSTBYADDR_R */
+
+  if (hptr == NULL)
+    throw new java::net::UnknownHostException ();
+
+  return JvNewStringUTF (hptr->h_name);
+}
+
+JArray<jbyteArray> *
+java::net::VMInetAddress::getHostByName (jstring host)
+{
+  struct hostent *hptr = NULL;
+#ifdef HAVE_GETHOSTBYNAME_R
+  struct hostent hent_r;
+#if HAVE_STRUCT_HOSTENT_DATA
+  struct hostent_data fixed_buffer, *buffer_r = &fixed_buffer;
+#else
+#ifdef __GLIBC__
+  // FIXME: in glibc, gethostbyname_r returns NETDB_INTERNAL to herr and
+  // ERANGE to errno if the buffer size is too small, rather than what is 
+  // expected here. We work around this by setting a bigger buffer size and 
+  // hoping that it is big enough.
+  char fixed_buffer[1024];
+#else
+  char fixed_buffer[200];
+#endif /* __GLIBC__ */
+  char *buffer_r = fixed_buffer;
+  int size_r = sizeof (fixed_buffer);
+#endif /* HAVE_STRUCT_HOSTENT_DATA */
+#endif /* HAVE_GETHOSTBYNAME_R */
+
+  char *hostname;
+  char buf[100];
+  int len = JvGetStringUTFLength(host);
+  if (len < 100)
+    hostname = buf;
+  else
+    hostname = (char *) _Jv_AllocBytes (len + 1);
+  JvGetStringUTFRegion (host, 0, host->length(), hostname);
+  buf[len] = '\0';
+#ifdef HAVE_GETHOSTBYNAME_R
+  while (true)
+    {
+      int ok;
+#if HAVE_STRUCT_HOSTENT_DATA
+      ok = ! gethostbyname_r (hostname, &hent_r, buffer_r);
+#else
+      int herr = 0;
+#ifdef GETHOSTBYNAME_R_RETURNS_INT
+      ok = ! gethostbyname_r (hostname, &hent_r, buffer_r, size_r,
+			      &hptr, &herr);
+#else
+      hptr = gethostbyname_r (hostname, &hent_r, buffer_r, size_r, &herr);
+      ok = hptr != NULL;
+#endif /* GETHOSTNAME_R_RETURNS_INT */
+      if (! ok && herr == ERANGE)
+	{
+	  size_r *= 2;
+	  buffer_r = (char *) _Jv_AllocBytes (size_r);
+	}
+      else
+#endif /* HAVE_STRUCT_HOSTENT_DATA */
+	break;
+    }
+#else /* HAVE_GETHOSTBYNAME_R */
+  // FIXME: this is insufficient if some other piece of code calls
+  // this gethostbyname.
+  JvSynchronize sync (java::net::VMInetAddress::class$);
+  hptr = gethostbyname (hostname);
+#endif /* HAVE_GETHOSTBYNAME_R */
+
+  if (hptr == NULL)
+    throw new java::net::UnknownHostException (host);
+
+  int count = 0;
+  char ** ptr = hptr->h_addr_list;
+  while (*ptr++)  count++;
+
+  JArray<jbyteArray> *result =
+    (JArray<jbyteArray> *) _Jv_NewObjectArray (
+      count, _Jv_GetArrayClass(JvPrimClass(byte), NULL), NULL);
+  jbyteArray* addrs = elements (result);
+
+  for (int i = 0; i < count; i++)
+    {
+      addrs[i] = JvNewByteArray (hptr->h_length);
+      memcpy (elements (addrs[i]), hptr->h_addr_list[i], hptr->h_length);
+    }
+  return result;
+}
+
+jbyteArray
+java::net::VMInetAddress::aton (jstring host)
+{
+  char *hostname;
+  char buf[100];
+  int len = JvGetStringUTFLength(host);
+  if (len < 100)
+    hostname = buf;
+  else
+    hostname = (char *) _Jv_AllocBytes (len+1);
+  JvGetStringUTFRegion (host, 0, host->length(), hostname);
+  buf[len] = '\0';
+  char *bytes = NULL;
+  int blen = 0;
+#ifdef HAVE_INET_ATON
+  struct in_addr laddr;
+  if (inet_aton (hostname, &laddr))
+    {
+      bytes = (char *) &laddr;
+      blen = 4;
+    }
+#elif defined(HAVE_INET_ADDR)
+#if ! HAVE_IN_ADDR_T
+  typedef jint in_addr_t;
+#endif
+  in_addr_t laddr = inet_addr (hostname);
+  if (laddr != (in_addr_t)(-1))
+    {
+      bytes = (char *) &laddr;
+      blen = 4;
+    }
+#endif
+#if defined (HAVE_INET_PTON) && defined (HAVE_INET6)
+  char inet6_addr[16];
+  if (len != 0 && inet_pton (AF_INET6, hostname, inet6_addr) > 0)
+    {
+      bytes = inet6_addr;
+      blen = 16;
+    }
+#endif
+  if (blen == 0)
+    return NULL;
+  jbyteArray result = JvNewByteArray (blen);
+  memcpy (elements (result), bytes, blen);
+  return result;
+}
Index: java/net/natVMInetAddressWin32.cc
===================================================================
--- java/net/natVMInetAddressWin32.cc	(revision 0)
+++ java/net/natVMInetAddressWin32.cc	(revision 0)
@@ -0,0 +1,121 @@
+/* Copyright (C) 2003, 2006 Free Software Foundation
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+#include <config.h>
+#include <platform.h>
+
+#undef STRICT
+
+#include <java/net/VMInetAddress.h>
+#include <java/net/UnknownHostException.h>
+
+jstring
+java::net::VMInetAddress::getLocalHostname ()
+{
+  char buffer[400];
+  if (gethostname (buffer, sizeof(buffer)))
+    return NULL;
+  // It is admittedly non-optimal to convert the hostname to Unicode
+  // only to convert it back in getByName, but simplicity wins.
+  return JvNewStringUTF (buffer);
+}
+
+jbyteArray
+java::net::VMInetAddress::lookupInaddrAny ()
+{
+  unsigned long laddr = INADDR_ANY;
+  char *bytes = (char *) &laddr;
+  int blen = sizeof (laddr);
+  jbyteArray result = JvNewByteArray (blen);
+  memcpy (elements (result), bytes, blen);
+  return result;
+}
+
+jstring
+java::net::VMInetAddress::getHostByAddr (jbyteArray addr)
+{
+  struct hostent *hptr = NULL;
+  char *bytes = (char*) elements (addr);
+  int len = addr->length;
+  int type;
+  char *val;
+  if (len == 4)
+    {
+      val = bytes;
+      type = AF_INET;
+    }
+#ifdef HAVE_INET6
+  else if (len == 16)
+    {
+      val = (char *) &bytes;
+      type = AF_INET6;
+    }
+#endif /* HAVE_INET6 */
+  else
+    JvFail ("unrecognized size");
+
+  // FIXME: this is insufficient if some other piece of code calls
+  // this gethostbyaddr.
+  JvSynchronize sync (java::net::VMInetAddress::class$);
+  hptr = gethostbyaddr (val, len, type);
+
+  if (hptr == NULL)
+    throw new java::net::UnknownHostException ();
+
+  return JvNewStringUTF (hptr->h_name);
+}
+
+JArray<jbyteArray> *
+java::net::VMInetAddress::getHostByName (jstring host)
+{
+  struct hostent *hptr = NULL;
+  JV_TEMP_UTF_STRING (hostname, host);
+
+  // FIXME: this is insufficient if some other piece of code calls
+  // this gethostbyname.
+  JvSynchronize sync (java::net::VMInetAddress::class$);
+  hptr = gethostbyname (hostname);
+
+  if (hptr == NULL)
+    throw new java::net::UnknownHostException (host);
+
+  int count = 0;
+  char ** ptr = hptr->h_addr_list;
+  while (*ptr++)  count++;
+
+  JArray<jbyteArray> *result =
+    (JArray<jbyteArray> *) _Jv_NewObjectArray (
+      count, _Jv_GetArrayClass(JvPrimClass(byte), NULL), NULL);
+  jbyteArray* addrs = elements (result);
+
+  for (int i = 0; i < count; i++)
+    {
+      addrs[i] = JvNewByteArray (hptr->h_length);
+      memcpy (elements (addrs[i]), hptr->h_addr_list[i], hptr->h_length);
+    }
+  return result;
+}
+
+jbyteArray
+java::net::VMInetAddress::aton (jstring host)
+{
+  JV_TEMP_UTF_STRING (hostname, host);
+  char* bytes = NULL;
+  int blen = 0;
+  unsigned long laddr = inet_addr (hostname);
+  if (laddr != INADDR_NONE)
+    {
+      bytes = (char *) &laddr;
+      blen = 4;
+    }
+  if (blen == 0)
+    return NULL;
+  jbyteArray result = JvNewByteArray (blen);
+  memcpy (elements (result), bytes, blen);
+  return result;
+}
Index: Makefile.am
===================================================================
--- Makefile.am	(revision 117074)
+++ Makefile.am	(working copy)
@@ -852,7 +852,7 @@
 java/lang/reflect/natField.cc \
 java/lang/reflect/natMethod.cc \
 java/net/natVMNetworkInterface.cc \
-java/net/natInetAddress.cc \
+java/net/natVMInetAddress.cc \
 java/net/natURLClassLoader.cc \
 java/nio/channels/natVMChannels.cc \
 java/nio/natDirectByteBufferImpl.cc \
Index: configure.ac
===================================================================
--- configure.ac	(revision 117074)
+++ configure.ac	(working copy)
@@ -663,9 +663,9 @@
 AC_CONFIG_LINKS(java/lang/ConcreteProcess.java:java/lang/${PLATFORM}Process.java)
 AC_CONFIG_LINKS(java/lang/natConcreteProcess.cc:java/lang/nat${PLATFORM}Process.cc)
 
-# Likewise for natInetAddress.cc and natVMNetworkInterface.cc.
+# Likewise for natVMInetAddress.cc and natVMNetworkInterface.cc.
 test -d java/net || mkdir java/net
-AC_CONFIG_LINKS(java/net/natInetAddress.cc:java/net/natInetAddress${PLATFORMNET}.cc)
+AC_CONFIG_LINKS(java/net/natVMInetAddress.cc:java/net/natVMInetAddress${PLATFORMNET}.cc)
 AC_CONFIG_LINKS(java/net/natVMNetworkInterface.cc:java/net/natVMNetworkInterface${PLATFORMNET}.cc)
 
 # Likewise for natPlainSocketImpl.cc and natPlainDatagramSocketImpl.cc.
Index: sources.am
===================================================================
--- sources.am	(revision 117075)
+++ sources.am	(working copy)
@@ -5211,7 +5211,7 @@
 classpath/java/net/HttpURLConnection.java \
 classpath/java/net/Inet4Address.java \
 classpath/java/net/Inet6Address.java \
-java/net/InetAddress.java \
+classpath/java/net/InetAddress.java \
 classpath/java/net/InetSocketAddress.java \
 classpath/java/net/JarURLConnection.java \
 classpath/java/net/MalformedURLException.java \
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 117075)
+++ Makefile.in	(working copy)
@@ -93,7 +93,7 @@
 	$(top_builddir)/gcj/libgcj-config.h
 CONFIG_CLEAN_FILES = libgcj.pc libgcj.spec libgcj-test.spec \
 	scripts/jar java/io/natFile.cc java/lang/ConcreteProcess.java \
-	java/lang/natConcreteProcess.cc java/net/natInetAddress.cc \
+	java/lang/natConcreteProcess.cc java/net/natVMInetAddress.cc \
 	java/net/natVMNetworkInterface.cc \
 	gnu/java/net/natPlainSocketImpl.cc \
 	gnu/java/net/natPlainDatagramSocketImpl.cc \
@@ -298,7 +298,7 @@
 	java/lang/ref/natReference.cc java/lang/reflect/natArray.cc \
 	java/lang/reflect/natConstructor.cc \
 	java/lang/reflect/natField.cc java/lang/reflect/natMethod.cc \
-	java/net/natVMNetworkInterface.cc java/net/natInetAddress.cc \
+	java/net/natVMNetworkInterface.cc java/net/natVMInetAddress.cc \
 	java/net/natURLClassLoader.cc \
 	java/nio/channels/natVMChannels.cc \
 	java/nio/natDirectByteBufferImpl.cc \
@@ -345,7 +345,7 @@
 	java/lang/ref/natReference.lo java/lang/reflect/natArray.lo \
 	java/lang/reflect/natConstructor.lo \
 	java/lang/reflect/natField.lo java/lang/reflect/natMethod.lo \
-	java/net/natVMNetworkInterface.lo java/net/natInetAddress.lo \
+	java/net/natVMNetworkInterface.lo java/net/natVMInetAddress.lo \
 	java/net/natURLClassLoader.lo \
 	java/nio/channels/natVMChannels.lo \
 	java/nio/natDirectByteBufferImpl.lo \
@@ -4124,7 +4124,7 @@
 classpath/java/net/HttpURLConnection.java \
 classpath/java/net/Inet4Address.java \
 classpath/java/net/Inet6Address.java \
-java/net/InetAddress.java \
+classpath/java/net/InetAddress.java \
 classpath/java/net/InetSocketAddress.java \
 classpath/java/net/JarURLConnection.java \
 classpath/java/net/MalformedURLException.java \
@@ -7422,7 +7422,7 @@
 java/lang/reflect/natField.cc \
 java/lang/reflect/natMethod.cc \
 java/net/natVMNetworkInterface.cc \
-java/net/natInetAddress.cc \
+java/net/natVMInetAddress.cc \
 java/net/natURLClassLoader.cc \
 java/nio/channels/natVMChannels.cc \
 java/nio/natDirectByteBufferImpl.cc \
@@ -7912,7 +7912,7 @@
 	@: > java/net/$(DEPDIR)/$(am__dirstamp)
 java/net/natVMNetworkInterface.lo: java/net/$(am__dirstamp) \
 	java/net/$(DEPDIR)/$(am__dirstamp)
-java/net/natInetAddress.lo: java/net/$(am__dirstamp) \
+java/net/natVMInetAddress.lo: java/net/$(am__dirstamp) \
 	java/net/$(DEPDIR)/$(am__dirstamp)
 java/net/natURLClassLoader.lo: java/net/$(am__dirstamp) \
 	java/net/$(DEPDIR)/$(am__dirstamp)
@@ -8242,10 +8242,10 @@
 	-rm -f java/lang/reflect/natField.lo
 	-rm -f java/lang/reflect/natMethod.$(OBJEXT)
 	-rm -f java/lang/reflect/natMethod.lo
-	-rm -f java/net/natInetAddress.$(OBJEXT)
-	-rm -f java/net/natInetAddress.lo
 	-rm -f java/net/natURLClassLoader.$(OBJEXT)
 	-rm -f java/net/natURLClassLoader.lo
+	-rm -f java/net/natVMInetAddress.$(OBJEXT)
+	-rm -f java/net/natVMInetAddress.lo
 	-rm -f java/net/natVMNetworkInterface.$(OBJEXT)
 	-rm -f java/net/natVMNetworkInterface.lo
 	-rm -f java/nio/channels/natVMChannels.$(OBJEXT)
@@ -8372,8 +8372,8 @@
 @AMDEP_TRUE@@am__include@ @am__quote@java/lang/reflect/$(DEPDIR)/natConstructor.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/lang/reflect/$(DEPDIR)/natField.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/lang/reflect/$(DEPDIR)/natMethod.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natInetAddress.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natURLClassLoader.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natVMInetAddress.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natVMNetworkInterface.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/nio/$(DEPDIR)/natDirectByteBufferImpl.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/nio/channels/$(DEPDIR)/natVMChannels.Plo@am__quote@
Index: configure
===================================================================
--- configure	(revision 117074)
+++ configure	(working copy)
@@ -7486,9 +7486,9 @@
           ac_config_links="$ac_config_links java/lang/natConcreteProcess.cc:java/lang/nat${PLATFORM}Process.cc"
 
 
-# Likewise for natInetAddress.cc and natVMNetworkInterface.cc.
+# Likewise for natVMInetAddress.cc and natVMNetworkInterface.cc.
 test -d java/net || mkdir java/net
-          ac_config_links="$ac_config_links java/net/natInetAddress.cc:java/net/natInetAddress${PLATFORMNET}.cc"
+          ac_config_links="$ac_config_links java/net/natVMInetAddress.cc:java/net/natVMInetAddress${PLATFORMNET}.cc"
 
           ac_config_links="$ac_config_links java/net/natVMNetworkInterface.cc:java/net/natVMNetworkInterface${PLATFORMNET}.cc"
 
@@ -17389,7 +17389,7 @@
   "java/io/natFile.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/io/natFile.cc:java/io/natFile${FILE-${PLATFORM}}.cc" ;;
   "java/lang/ConcreteProcess.java" ) CONFIG_LINKS="$CONFIG_LINKS java/lang/ConcreteProcess.java:java/lang/${PLATFORM}Process.java" ;;
   "java/lang/natConcreteProcess.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/lang/natConcreteProcess.cc:java/lang/nat${PLATFORM}Process.cc" ;;
-  "java/net/natInetAddress.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/net/natInetAddress.cc:java/net/natInetAddress${PLATFORMNET}.cc" ;;
+  "java/net/natVMInetAddress.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/net/natVMInetAddress.cc:java/net/natVMInetAddress${PLATFORMNET}.cc" ;;
   "java/net/natVMNetworkInterface.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/net/natVMNetworkInterface.cc:java/net/natVMNetworkInterface${PLATFORMNET}.cc" ;;
   "gnu/java/net/natPlainSocketImpl.cc" ) CONFIG_LINKS="$CONFIG_LINKS gnu/java/net/natPlainSocketImpl.cc:gnu/java/net/natPlainSocketImpl${PLATFORMNET}.cc" ;;
   "gnu/java/net/natPlainDatagramSocketImpl.cc" ) CONFIG_LINKS="$CONFIG_LINKS gnu/java/net/natPlainDatagramSocketImpl.cc:gnu/java/net/natPlainDatagramSocketImpl${PLATFORMNET}.cc" ;;
Index: java/net/natVMNetworkInterfaceWin32.cc
===================================================================
--- java/net/natVMNetworkInterfaceWin32.cc	(revision 117074)
+++ java/net/natVMNetworkInterfaceWin32.cc	(working copy)
@@ -12,7 +12,7 @@
 #undef STRICT
 
 #include <java/net/NetworkInterface.h>
-#include <java/net/Inet4Address.h>
+#include <java/net/InetAddress.h>
 #include <java/net/SocketException.h>
 #include <java/net/VMNetworkInterface.h>
 #include <java/util/Vector.h>
@@ -83,8 +83,8 @@
         }
 
       jstring if_name = _Jv_Win32NewString (szName);
-      java::net::Inet4Address* address =
-        new java::net::Inet4Address (baddr, JvNewStringLatin1 (""));
+      java::net::InetAddress* address =
+        java::net::InetAddress::getByAddress (baddr);
       pjstrName[i] = if_name;
       ppAddress[i] = address;
     }
Index: gnu/java/net/natPlainSocketImplWin32.cc
===================================================================
--- gnu/java/net/natPlainSocketImplWin32.cc	(revision 117074)
+++ gnu/java/net/natPlainSocketImplWin32.cc	(working copy)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003, 2004, 2005 Free Software Foundation
+/* Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
 
    This file is part of libgcj.
 
@@ -328,7 +328,7 @@
 
   s->native_fd = (jint) hSocket;
   s->localport = localport;
-  s->address = new ::java::net::InetAddress (raddr, NULL);
+  s->address = ::java::net::InetAddress::getByAddress (raddr);
   s->port = rport;
   return;
 
@@ -735,7 +735,7 @@
           else
             throw new ::java::net::SocketException
               (JvNewStringUTF ("invalid family"));
-          localAddress = new ::java::net::InetAddress (laddr, NULL);
+          localAddress = ::java::net::InetAddress::getByAddress (laddr);
         }
 
       return localAddress;
Index: gnu/java/net/natPlainDatagramSocketImplWin32.cc
===================================================================
--- gnu/java/net/natPlainDatagramSocketImplWin32.cc	(revision 117074)
+++ gnu/java/net/natPlainDatagramSocketImplWin32.cc	(working copy)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003  Free Software Foundation
+/* Copyright (C) 2003, 2006 Free Software Foundation
 
    This file is part of libgcj.
 
@@ -238,7 +238,7 @@
   else
     throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
 
-  p->setAddress (new ::java::net::InetAddress (raddr, NULL));
+  p->setAddress (::java::net::InetAddress::getByAddress (raddr));
   p->setPort (rport);
   p->length = (jint) retlen;
   return rport;
@@ -360,7 +360,7 @@
   else
     throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
 
-  p->setAddress (new ::java::net::InetAddress (raddr, NULL));
+  p->setAddress (::java::net::InetAddress::getByAddress (raddr));
   p->setPort (rport);
   p->length = (jint) retlen;
   return;
@@ -656,7 +656,7 @@
       else
         throw new ::java::net::SocketException (
             JvNewStringUTF ("invalid family"));
-      localAddress = new ::java::net::InetAddress (laddr, NULL);
+      localAddress = ::java::net::InetAddress::getByAddress (laddr);
     }
   return localAddress;
   break;
Index: classpath/java/net/Inet4Address.java
===================================================================
--- classpath/java/net/Inet4Address.java	(revision 117074)
+++ classpath/java/net/Inet4Address.java	(working copy)
@@ -59,14 +59,14 @@
   /**
    * The address family of these addresses (used for serialization).
    */
-  private static final int FAMILY = 2; // AF_INET
+  private static final int AF_INET = 2;
 
   /**
    * Inet4Address objects are serialized as InetAddress objects.
    */
   private Object writeReplace() throws ObjectStreamException
   {
-    return new InetAddress(addr, hostName, FAMILY);
+    return new InetAddress(addr, hostName, AF_INET);
   }
   
   /**
@@ -79,7 +79,7 @@
    */
   Inet4Address(byte[] addr, String host)
   {
-    super(addr, host, FAMILY);
+    super(addr, host, AF_INET);
   }
 
   /**
Index: classpath/java/net/Inet6Address.java
===================================================================
--- classpath/java/net/Inet6Address.java	(revision 117074)
+++ classpath/java/net/Inet6Address.java	(working copy)
@@ -95,7 +95,7 @@
   /**
    * The address family of these addresses (used for serialization).
    */
-  private static final int FAMILY = 10; // AF_INET6
+  private static final int AF_INET6 = 10;
 
   /**
    * Create an Inet6Address object
@@ -105,7 +105,7 @@
    */
   Inet6Address(byte[] addr, String host)
   {
-    super(addr, host, FAMILY);
+    super(addr, host, AF_INET6);
     // Super constructor clones the addr.  Get a reference to the clone.
     this.ipaddress = this.addr;
     ifname = null;

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFT: The remainder of the InetAddress merge
  2006-09-20 12:15 ` RFT: The remainder of the " Gary Benson
@ 2006-09-23 14:20   ` Mohan Embar
  2006-09-24  2:29     ` Mohan Embar
  2006-09-25 14:58   ` RFC: Updated " Gary Benson
  1 sibling, 1 reply; 9+ messages in thread
From: Mohan Embar @ 2006-09-23 14:20 UTC (permalink / raw)
  To: Gary Benson; +Cc: java-patches

Hi Gary,

>This patch is the second half of the InetAddress merge whose first
>half I committed earlier today.  It removes GCJ's custom InetAddress,
>and replaces the glue methods in VMInetAddress with real native code.

I am trying to build on Win32 with the patch you sent me off list on
21 Sep and am getting this. Probably something simple like a conflicting
declaration but I won't be able to look into this more until at least
tonight:

java/net/natVMInetAddress.cc: In static member function 'static java::lang::String* java::net::VMInetAddress::getHostByAddr(JArray<__java_byte>*)':
java/net/natVMInetAddress.cc:64: error: no matching function for call to 'JvSynchronize::JvSynchronize(java::lang::Class&)'
/datal/gcc/gcc/libjava/gcj/cni.h:98: note: candidates are: JvSynchronize::JvSynchronize(java::lang::Object* const&)
/datal/gcc/gcc/libjava/gcj/cni.h:94: note:                 JvSynchronize::JvSynchronize(const JvSynchronize&)
java/net/natVMInetAddress.cc: In static member function 'static JArray<JArray<__java_byte>*>* java::net::VMInetAddress::getHostByName(java::lang::String*)':
java/net/natVMInetAddress.cc:81: error: no matching function for call to 'JvSynchronize::JvSynchronize(java::lang::Class&)'
/datal/gcc/gcc/libjava/gcj/cni.h:98: note: candidates are: JvSynchronize::JvSynchronize(java::lang::Object* const&)
/datal/gcc/gcc/libjava/gcj/cni.h:94: note:                 JvSynchronize::JvSynchronize(const JvSynchronize&)

-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFT: The remainder of the InetAddress merge
  2006-09-23 14:20   ` Mohan Embar
@ 2006-09-24  2:29     ` Mohan Embar
  2006-09-25 12:21       ` Gary Benson
  0 siblings, 1 reply; 9+ messages in thread
From: Mohan Embar @ 2006-09-24  2:29 UTC (permalink / raw)
  To: Gary Benson; +Cc: java-patches

[-- Attachment #1: Type: text/plain, Size: 1053 bytes --]

Hi Gary,

>>This patch is the second half of the InetAddress merge whose first
>>half I committed earlier today.  It removes GCJ's custom InetAddress,
>>and replaces the glue methods in VMInetAddress with real native code.
>
>I am trying to build on Win32 with the patch you sent me off list on
>21 Sep and am getting this. Probably something simple like a conflicting
>declaration but I won't be able to look into this more until at least
>tonight: ...

I was able to work around the build errors by changing the offending lines
(64 & 81) of natVMInetAddressWin32.cc to:

  JvSynchronize sync (&java::net::VMInetAddress::class$);

(added address-of operator (&) - don't why the POSIX stuff builds okay without
it). The build worked and passed the attached test, which is more testing than
this class has probably ever offically gotten on Win32. Your patch gets my
thumbs-up for the Win32 portion. I haven't tested the security portion of this.
Let me know if you think that's necessary.

-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/


[-- Attachment #2: Haha.java --]
[-- Type: application/octet-stream, Size: 500 bytes --]

import java.net.*;

class Haha
{
public static void main(String[] args) throws Exception
{
    InetAddress[] addr = InetAddress.getAllByName(null);
    System.out.println(addr[0]);

    InetAddress addr1 = InetAddress.getByName("savannah.gnu.org");
    System.out.println(addr1);

    byte[] ipaddr = { 0x10, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x00, 0x20, 0x20, 0x0, 0x0, 0x0, 0x1 };
    InetAddress addr2 = InetAddress.getByAddress(ipaddr);
    System.out.println(addr2);
}
}

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: RFT: The remainder of the InetAddress merge
  2006-09-24  2:29     ` Mohan Embar
@ 2006-09-25 12:21       ` Gary Benson
  0 siblings, 0 replies; 9+ messages in thread
From: Gary Benson @ 2006-09-25 12:21 UTC (permalink / raw)
  To: java-patches

Mohan Embar wrote:
> Mohan Embar wrote:
> > Gary Benson wrote:
> > > This patch is the second half of the InetAddress merge whose
> > > first half I committed earlier today.  It removes GCJ's custom
> > > InetAddress, and replaces the glue methods in VMInetAddress
> > > with real native code.
> > 
> > I am trying to build on Win32 with the patch you sent me off list
> > on 21 Sep and am getting this. Probably something simple like a
> > conflicting declaration but I won't be able to look into this more
> > until at least tonight: ...
> 
> I was able to work around the build errors by changing the offending
> lines (64 & 81) of natVMInetAddressWin32.cc to:
> 
>   JvSynchronize sync (&java::net::VMInetAddress::class$);
> 
> (added address-of operator (&) - don't why the POSIX stuff builds
> okay without it).

Hmmm, no idea :)  But I added it to the Posix methods too...

> The build worked and passed the attached test, which is more testing
> than this class has probably ever offically gotten on Win32. Your
> patch gets my thumbs-up for the Win32 portion.

Thank you.  I'll post an updated patch shortly.  With luck we can get
this into 4.2.

> I haven't tested the security portion of this.  Let me know if you
> think that's necessary.

It shouldn't be.  The security checks are all in Java now, shared
across all platforms, so testing on any one of them should be
sufficient.

Thanks again,
Gary

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RFC: Updated InetAddress merge
  2006-09-20 12:15 ` RFT: The remainder of the " Gary Benson
  2006-09-23 14:20   ` Mohan Embar
@ 2006-09-25 14:58   ` Gary Benson
  2006-11-03 10:23     ` FYI: " Gary Benson
  1 sibling, 1 reply; 9+ messages in thread
From: Gary Benson @ 2006-09-25 14:58 UTC (permalink / raw)
  To: java-patches

[-- Attachment #1: Type: text/plain, Size: 287 bytes --]

Hi all,

This patch is an updated version of the InetAddress merge patch I
mailed last week.  It's been tested on Fedora Core 5 and on Windows,
but it's possible some of the conditional code for older Posix systems
is broken.  Should I commit it, or await further testers?

Cheers,
Gary

[-- Attachment #2: inetaddress-merge-rest-take2.patch --]
[-- Type: text/plain, Size: 67407 bytes --]

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 117194)
+++ ChangeLog	(working copy)
@@ -1,3 +1,26 @@
+2006-09-25  Gary Benson  <gbenson@redhat.com>
+
+	* java/net/InetAddress.java: Removed.
+	* java/net/natInetAddressNoNet.cc: Likewise.
+	* java/net/natInetAddressPosix.cc: Likewise.
+	* java/net/natInetAddressWin32.cc: Likewise.
+	* java/net/VMInetAddress.java (getLocalHostname,
+	lookupInaddrAny, getHostByAddr, getHostByName,
+	aton): Replace glue methods with native ones.
+	* java/net/natVMInetAddressNoNet.cc: New file.
+	* java/net/natVMInetAddressPosix.cc: Likewise.
+	* java/net/natVMInetAddressWin32.cc: Likewise.
+	* Makefile.am, configure.ac: Reflect the above.
+	* sources.am, Makefile.in, configure: Rebuilt.
+
+	* java/net/natVMNetworkInterfaceWin32.cc
+	(winsock2GetRealNetworkInterfaces): Create InetAddress
+	objects using InetAddress.getByAddress.
+	* gnu/java/net/natPlainSocketImplWin32.cc
+	(accept, getOption): Likewise.
+	* gnu/java/net/natPlainDatagramSocketImplWin32.cc
+	(peekData, receive, getOption): Likewise.
+
 2006-09-22  Marco Trudel  <mtrudel@gmx.ch>
 
 	* jvmti.cc (_Jv_JVMTI_GetErrorName): Now static.  Marked JNICALL.
Index: classpath/ChangeLog.gcj
===================================================================
--- classpath/ChangeLog.gcj	(revision 117194)
+++ classpath/ChangeLog.gcj	(working copy)
@@ -1,3 +1,12 @@
+2006-09-25  Gary Benson  <gbenson@redhat.com>
+
+	* java/net/Inet4Address.java
+	(FAMILY): Renamed to AF_INET.
+	(<init>, writeReplace): Reflect the above.
+	* java/net/Inet6Address.java
+	(FAMILY): Renamed to AF_INET6.
+	(<init>): Reflect the above.	
+
 2006-09-22  David Daney  <ddaney@avtrex.com>
 
 	PR classpath/28661
Index: java/net/InetAddress.java
===================================================================
--- java/net/InetAddress.java	(revision 117194)
+++ java/net/InetAddress.java	(working copy)
@@ -1,813 +0,0 @@
-/* InetAddress.java -- Class to model an Internet address
-   Copyright (C) 1998, 1999, 2002, 2004, 2005, 2006
-   Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING.  If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library.  Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module.  An independent module is a module which is not derived from
-or based on this library.  If you modify this library, you may extend
-this exception to your version of the library, but you are not
-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.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamException;
-import java.io.Serializable;
-
-/**
- * This class models an Internet address.  It does not have a public
- * constructor.  Instead, new instances of this objects are created
- * using the static methods getLocalHost(), getByName(), and
- * getAllByName().
- *
- * <p>This class fulfills the function of the C style functions gethostname(),
- * gethostbyname(), and gethostbyaddr().  It resolves Internet DNS names
- * into their corresponding numeric addresses and vice versa.</p>
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- * @author Per Bothner
- * @author Gary Benson (gbenson@redhat.com)
- *
- * @specnote This class is not final since JK 1.4
- */
-public class InetAddress implements Serializable
-{
-  private static final long serialVersionUID = 3286316764910316507L;
-
-  /**
-   * Dummy InetAddress, used to bind socket to any (all) network interfaces.
-   */
-  static InetAddress ANY_IF;
-  static
-  {
-    byte[] addr;
-    try
-      {
-	addr = VMInetAddress.lookupInaddrAny();
-      }
-    catch (UnknownHostException e)
-      {
-	// Make one up and hope it works.
-	addr = new byte[] {0, 0, 0, 0};
-      }
-    try
-      {
-	ANY_IF = getByAddress(addr);
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-    ANY_IF.hostName = ANY_IF.getHostName();
-  }
-  
-  /**
-   * Stores static localhost address object.
-   */
-  static InetAddress LOCALHOST;
-  static
-  {
-    try
-      {
-	LOCALHOST = getByAddress("localhost", new byte[] {127, 0, 0, 1});
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }    
-
-  /**
-   * The Serialized Form specifies that an int 'address' is saved/restored.
-   * This class uses a byte array internally so we'll just do the conversion
-   * at serialization time and leave the rest of the algorithm as is.
-   */
-  private int address;
-
-  /**
-   * An array of octets representing an IP address.
-   */
-  transient byte[] addr;
-
-  /**
-   * The name of the host for this address.
-   */
-  String hostName;
-
-  /**
-   * Needed for serialization.
-   */
-  private int family;
-
-  /**
-   * Constructor.  Prior to the introduction of IPv6 support in 1.4,
-   * methods such as InetAddress.getByName() would return InetAddress
-   * objects.  From 1.4 such methods returned either Inet4Address or
-   * Inet6Address objects, but for compatibility Inet4Address objects
-   * are serialized as InetAddresses.  As such, there are only two
-   * places where it is appropriate to invoke this constructor: within
-   * subclasses constructors and within Inet4Address.writeReplace().
-   *
-   * @param ipaddr The IP number of this address as an array of bytes
-   * @param hostname The hostname of this IP address.
-   * @param family The address family of this IP address.
-   */
-  InetAddress(byte[] ipaddr, String hostname, int family)
-  {
-    addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone();
-    hostName = hostname;
-    this.family = family;
-  }
-
-  /**
-   * Returns true if this address is a multicast address, false otherwise.
-   * An address is multicast if the high four bits are "1110".  These are
-   * also known as "Class D" addresses.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @return true if mulitcast, false if not
-   *
-   * @since 1.1
-   */
-  public boolean isMulticastAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMulticastAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if the InetAddress in a wildcard address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isAnyLocalAddress()
-  {
-    // This is inefficient, but certain methods on Win32 create
-    // InetAddress objects using "new InetAddress" rather than
-    // "InetAddress.getByAddress" so we provide a method body.
-    // This code is never executed on Posix systems.
-    try
-      {
-	return getByAddress(hostName, addr).isAnyLocalAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if the InetAddress is a loopback address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isLoopbackAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isLoopbackAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a link local address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isLinkLocalAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isLinkLocalAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a site local address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isSiteLocalAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isSiteLocalAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a global multicast address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCGlobal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCGlobal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a node local multicast address.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCNodeLocal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCNodeLocal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a link local multicast address.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCLinkLocal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCLinkLocal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a site local multicast address.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCSiteLocal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCSiteLocal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a organization local
-   * multicast address.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCOrgLocal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCOrgLocal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Returns the hostname for this address.  This will return the IP address
-   * as a String if there is no hostname available for this address
-   *
-   * @return The hostname for this address
-   */
-  public String getHostName()
-  {
-    if (hostName == null)
-      hostName = getCanonicalHostName();
-
-    return hostName;
-  }
-
-  /**
-   * Returns the canonical hostname represented by this InetAddress
-   */
-  String internalGetCanonicalHostName()
-  {
-    try
-      {
-	return ResolverCache.getHostByAddr(addr);
-      }
-    catch (UnknownHostException e)
-      {
-	return getHostAddress();
-      }
-  }
-
-  /**
-   * Returns the canonical hostname represented by this InetAddress
-   * 
-   * @since 1.4
-   */
-  public String getCanonicalHostName()
-  {
-    String hostname = internalGetCanonicalHostName();
-
-    SecurityManager sm = System.getSecurityManager();
-    if (sm != null)
-      {
-        try
-	  {
-            sm.checkConnect(hostname, -1);
-	  }
-	catch (SecurityException e)
-	  {
-	    return getHostAddress();
-	  }
-      }
-
-    return hostname;
-  }
-
-  /**
-   * Returns the IP address of this object as a byte array.
-   *
-   * @return IP address
-   */
-  public byte[] getAddress()
-  {
-    // An experiment shows that JDK1.2 returns a different byte array each
-    // time.  This makes sense, in terms of security.
-    return (byte[]) addr.clone();
-  }
-
-  /**
-   * Returns the IP address of this object as a String.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @return The IP address of this object in String form
-   *
-   * @since 1.0.2
-   */
-  public String getHostAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).getHostAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Returns a hash value for this address.  Useful for creating hash
-   * tables.  Overrides Object.hashCode()
-   *
-   * @return A hash value for this address.
-   */
-  public int hashCode()
-  {
-    // There hashing algorithm is not specified, but a simple experiment
-    // shows that it is equal to the address, as a 32-bit big-endian integer.
-    int hash = 0;
-    int len = addr.length;
-    int i = len > 4 ? len - 4 : 0;
-
-    for (; i < len; i++)
-      hash = (hash << 8) | (addr[i] & 0xff);
-
-    return hash;
-  }
-
-  /**
-   * Tests this address for equality against another InetAddress.  The two
-   * addresses are considered equal if they contain the exact same octets.
-   * This implementation overrides Object.equals()
-   *
-   * @param obj The address to test for equality
-   *
-   * @return true if the passed in object's address is equal to this one's,
-   * false otherwise
-   */
-  public boolean equals(Object obj)
-  {
-    if (! (obj instanceof InetAddress))
-      return false;
-
-    // "The Java Class Libraries" 2nd edition says "If a machine has
-    // multiple names instances of InetAddress for different name of
-    // that same machine are not equal.  This is because they have
-    // different host names."  This violates the description in the
-    // JDK 1.2 API documentation.  A little experimentation
-    // shows that the latter is correct.
-    byte[] addr2 = ((InetAddress) obj).addr;
-
-    if (addr.length != addr2.length)
-      return false;
-
-    for (int i = 0; i < addr.length; i++)
-      if (addr[i] != addr2[i])
-	return false;
-
-    return true;
-  }
-
-  /**
-   * Converts this address to a String.  This string contains the IP in
-   * dotted decimal form. For example: "127.0.0.1"  This method is equivalent
-   * to getHostAddress() and overrides Object.toString()
-   *
-   * @return This address in String form
-   */
-  public String toString()
-  {
-    String addr = getHostAddress();
-    String host = (hostName != null) ? hostName : "";
-    return host + "/" + addr;
-  }
-
-  /**
-   * Returns an InetAddress object given the raw IP address.
-   *
-   * The argument is in network byte order: the highest order byte of the
-   * address is in getAddress()[0].
-   *
-   * @param addr The IP address to create the InetAddress object from
-   *
-   * @exception UnknownHostException If IP address has illegal length
-   *
-   * @since 1.4
-   */
-  public static InetAddress getByAddress(byte[] addr)
-    throws UnknownHostException
-  {
-    return getByAddress(null, addr);
-  }
-
-  /**
-   * Creates an InetAddress based on the provided host name and IP address.
-   * No name service is checked for the validity of the address.
-   *
-   * @param host The hostname of the InetAddress object to create
-   * @param addr The IP address to create the InetAddress object from
-   *
-   * @exception UnknownHostException If IP address is of illegal length
-   *
-   * @since 1.4
-   */
-  public static InetAddress getByAddress(String host, byte[] addr)
-    throws UnknownHostException
-  {
-    if (addr.length == 4)
-      return new Inet4Address(addr, host);
-
-    if (addr.length == 16)
-      {
-	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");
-  }
-
-  /**
-   * Returns an InetAddress object representing the IP address of
-   * the given literal IP address in dotted decimal format such as
-   * "127.0.0.1".  This is used by SocketPermission.setHostPort()
-   * to parse literal IP addresses without performing a DNS lookup.
-   *
-   * @param literal The literal IP address to create the InetAddress
-   * object from
-   *
-   * @return The address of the host as an InetAddress object, or
-   * null if the IP address is invalid.
-   */
-  static InetAddress getByLiteral(String literal)
-  {
-    byte[] address = VMInetAddress.aton(literal);
-    if (address == null)
-      return null;
-    
-    try
-      {
-	return getByAddress(address);
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Returns an InetAddress object representing the IP address of the given
-   * hostname.  This name can be either a hostname such as "www.urbanophile.com"
-   * or an IP address in dotted decimal format such as "127.0.0.1".  If the
-   * hostname is null or "", the hostname of the local machine is supplied by
-   * default.  This method is equivalent to returning the first element in
-   * the InetAddress array returned from GetAllByName.
-   *
-   * @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.
-   *
-   * @exception UnknownHostException If no IP address for the host could
-   * be found
-   * @exception SecurityException If a security manager exists and its
-   * checkConnect method doesn't allow the operation
-   */
-  public static InetAddress getByName(String hostname)
-    throws UnknownHostException
-  {
-    InetAddress[] addresses = getAllByName(hostname);
-    return addresses[0];
-  }
-
-  /**
-   * Returns an array of InetAddress objects representing all the host/ip
-   * addresses of a given host, given the host's name.  This name can be
-   * either a hostname such as "www.urbanophile.com" or an IP address in
-   * dotted decimal format such as "127.0.0.1".  If the value is null, the
-   * hostname of the local machine is supplied by default.
-   *
-   * @param hostname The name of the desired host, or null for the
-   * local loopback address.
-   *
-   * @return All addresses of the host as an array of InetAddress objects.
-   *
-   * @exception UnknownHostException If no IP address for the host could
-   * be found
-   * @exception SecurityException If a security manager exists and its
-   * checkConnect method doesn't allow the operation
-   */
-  public static InetAddress[] getAllByName(String hostname)
-    throws UnknownHostException
-  {
-    // If null or the empty string is supplied, the loopback address
-    // is returned.
-    if (hostname == null || hostname.length() == 0)
-      return new InetAddress[] {LOCALHOST};
-
-    // Check if hostname is an IP address
-    InetAddress address = getByLiteral(hostname);
-    if (address != null)
-      return new InetAddress[] {address};
-
-    // Perform security check before resolving
-    SecurityManager sm = System.getSecurityManager();
-    if (sm != null)
-      sm.checkConnect(hostname, -1);
-
-    // Resolve the hostname
-    byte[][] iplist = ResolverCache.getHostByName(hostname);
-    if (iplist.length == 0)
-      throw new UnknownHostException(hostname);
-
-    InetAddress[] addresses = new InetAddress[iplist.length];
-    for (int i = 0; i < iplist.length; i++)
-      addresses[i] = getByAddress(hostname, iplist[i]);
-
-    return addresses;
-  }
-
-  /**
-   * Returns an InetAddress object representing the address of the current
-   * host.
-   *
-   * @return The local host's address
-   *
-   * @exception UnknownHostException If no IP address for the host could
-   * be found
-   */
-  public static InetAddress getLocalHost() throws UnknownHostException
-  {
-    String hostname = VMInetAddress.getLocalHostname();
-    try
-      {
-	return getByName(hostname);
-      }
-    catch (SecurityException e)
-      {
-	return LOCALHOST;
-      }
-  }
-
-  /**
-   * Inet4Address objects are serialized as InetAddress objects.
-   * This deserializes them back into Inet4Address objects.
-   */
-  private Object readResolve() throws ObjectStreamException
-  {
-    return new Inet4Address(addr, hostName);
-  }
-
-  private void readObject(ObjectInputStream ois)
-    throws IOException, ClassNotFoundException
-  {
-    ois.defaultReadObject();
-    addr = new byte[4];
-    addr[3] = (byte) address;
-
-    for (int i = 2; i >= 0; --i)
-      addr[i] = (byte) (address >>= 8);
-  }
-
-  private void writeObject(ObjectOutputStream oos) throws IOException
-  {
-    // Build a 32 bit address from the last 4 bytes of a 4 byte IPv4 address
-    // or a 16 byte IPv6 address.
-    int len = addr.length;
-    int i = len - 4;
-
-    for (; i < len; i++)
-      address = address << 8 | (addr[i] & 0xff);
-
-    oos.defaultWriteObject();
-  }
-
-  // The native methods remain here for now;
-  // methods in VMInetAddress map onto them.
-  static native byte[] aton(String hostname);
-  static native InetAddress[] lookup (String hostname,
-				      InetAddress ipaddr, boolean all);
-  static native int getFamily (byte[] ipaddr);
-  static native String getLocalHostname();
-
-  // Some soon-to-be-removed native code synchronizes on this.
-  static InetAddress loopbackAddress = LOCALHOST;
-  
-  // Some soon-to-be-removed code uses this old and broken method.
-  InetAddress(byte[] ipaddr, String hostname)
-  {
-    addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone();
-    hostName = hostname;
-
-    if (ipaddr != null)
-      family = getFamily(ipaddr);
-  }
-
-  // Some soon-to-be-removed native code uses this old method.
-  private static InetAddress[] allocArray (int count)
-  {
-    return new InetAddress [count];
-  }  
-}
Index: java/net/natInetAddressNoNet.cc
===================================================================
--- java/net/natInetAddressNoNet.cc	(revision 117194)
+++ java/net/natInetAddressNoNet.cc	(working copy)
@@ -1,36 +0,0 @@
-/* Copyright (C) 2003  Free Software Foundation
-
-   This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
-
-#include <config.h>
-#include <stddef.h>
-
-#include <java/net/InetAddress.h>
-
-jbyteArray
-java::net::InetAddress::aton (jstring)
-{
-  return NULL;
-}
-
-jint
-java::net::InetAddress::getFamily (jbyteArray bytes)
-{
-  return 0;
-}
-
-JArray<java::net::InetAddress*> *
-java::net::InetAddress::lookup (jstring, java::net::InetAddress *, jboolean)
-{
-  return NULL;
-}
-
-jstring
-java::net::InetAddress::getLocalHostname ()
-{
-  return NULL;
-}
Index: java/net/natInetAddressPosix.cc
===================================================================
--- java/net/natInetAddressPosix.cc	(revision 117194)
+++ java/net/natInetAddressPosix.cc	(working copy)
@@ -1,304 +0,0 @@
-/* Copyright (C) 2003  Free Software Foundation
-
-   This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
-
-#include <config.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <string.h>
-#include <errno.h>
-
-#include <sys/param.h>
-#include <sys/types.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-
-#include <gcj/cni.h>
-#include <jvm.h>
-#include <java/net/InetAddress.h>
-#include <java/net/UnknownHostException.h>
-#include <java/lang/SecurityException.h>
-
-#if defined(HAVE_UNAME) && ! defined(HAVE_GETHOSTNAME)
-#include <sys/utsname.h>
-#endif
-
-#ifndef HAVE_GETHOSTNAME_DECL
-extern "C" int gethostname (char *name, int namelen);
-#endif
-
-jbyteArray
-java::net::InetAddress::aton (jstring host)
-{
-  char *hostname;
-  char buf[100];
-  int len = JvGetStringUTFLength(host);
-  if (len < 100)
-    hostname = buf;
-  else
-    hostname = (char*) _Jv_AllocBytes (len+1);
-  JvGetStringUTFRegion (host, 0, host->length(), hostname);
-  buf[len] = '\0';
-  char* bytes = NULL;
-  int blen = 0;
-#ifdef HAVE_INET_ATON
-  struct in_addr laddr;
-  if (inet_aton (hostname, &laddr))
-    {
-      bytes = (char*) &laddr;
-      blen = 4;
-    }
-#elif defined(HAVE_INET_ADDR)
-#if ! HAVE_IN_ADDR_T
-  typedef jint in_addr_t;
-#endif
-  in_addr_t laddr = inet_addr (hostname);
-  if (laddr != (in_addr_t)(-1))
-    {
-      bytes = (char*) &laddr;
-      blen = 4;
-    }
-#endif
-#if defined (HAVE_INET_PTON) && defined (HAVE_INET6)
-  char inet6_addr[16];
-  if (len != 0 && inet_pton (AF_INET6, hostname, inet6_addr) > 0)
-    {
-      bytes = inet6_addr;
-      blen = 16;
-    }
-#endif
-  if (blen == 0)
-    return NULL;
-  jbyteArray result = JvNewByteArray (blen);
-  memcpy (elements (result), bytes, blen);
-  return result;
-}
-
-jint
-java::net::InetAddress::getFamily (jbyteArray bytes)
-{
-  int len = bytes->length;
-  if (len == 4)
-    return AF_INET;
-#ifdef HAVE_INET6
-  else if (len == 16)
-    return AF_INET6;
-#endif /* HAVE_INET6 */
-  else
-    JvFail ("unrecognized size");
-}
-
-
-JArray<java::net::InetAddress*> *
-java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
-				jboolean all)
-{
-  struct hostent *hptr = NULL;
-#if defined (HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYADDR_R)
-  struct hostent hent_r;
-#if HAVE_STRUCT_HOSTENT_DATA
-  struct hostent_data fixed_buffer, *buffer_r = &fixed_buffer;
-#else
-#if defined (__GLIBC__) 
-  // FIXME: in glibc, gethostbyname_r returns NETDB_INTERNAL to herr and
-  // ERANGE to errno if the buffer size is too small, rather than what is 
-  // expected here. We work around this by setting a bigger buffer size and 
-  // hoping that it is big enough.
-  char fixed_buffer[1024];
-#else
-  char fixed_buffer[200];
-#endif
-  char *buffer_r = fixed_buffer;
-  int size_r = sizeof (fixed_buffer);
-#endif
-#endif
-
-  if (host != NULL)
-    {
-      char *hostname;
-      char buf[100];
-      int len = JvGetStringUTFLength(host);
-      if (len < 100)
-	hostname = buf;
-      else
-	hostname = (char*) _Jv_AllocBytes (len+1);
-      JvGetStringUTFRegion (host, 0, host->length(), hostname);
-      buf[len] = '\0';
-#ifdef HAVE_GETHOSTBYNAME_R
-      while (true)
-	{
-	  int ok;
-#if HAVE_STRUCT_HOSTENT_DATA
-	  ok = ! gethostbyname_r (hostname, &hent_r, buffer_r);
-#else
-	  int herr = 0;
-#ifdef GETHOSTBYNAME_R_RETURNS_INT
-	  ok = ! gethostbyname_r (hostname, &hent_r, buffer_r, size_r,
-				  &hptr, &herr);
-#else
-	  hptr = gethostbyname_r (hostname, &hent_r, buffer_r, size_r, &herr);
-	  ok = hptr != NULL;
-#endif /* GETHOSTNAME_R_RETURNS_INT */
-	  if (! ok && herr == ERANGE)
-	    {
-	      size_r *= 2;
-	      buffer_r = (char *) _Jv_AllocBytes (size_r);
-	    }
-	  else
-#endif /* HAVE_STRUCT_HOSTENT_DATA */
-	    break;
-	}
-#else
-      // FIXME: this is insufficient if some other piece of code calls
-      // this gethostbyname.
-      JvSynchronize sync (java::net::InetAddress::loopbackAddress);
-      hptr = gethostbyname (hostname);
-#endif /* HAVE_GETHOSTBYNAME_R */
-    }
-  else
-    {
-      jbyteArray bytes = iaddr->addr;
-      char *chars = (char*) elements (bytes);
-      int len = bytes->length;
-      int type;
-      char *val;
-      if (len == 4)
-	{
-	  val = chars;
-	  type = iaddr->family = AF_INET;
-	}
-#ifdef HAVE_INET6
-      else if (len == 16)
-	{
-	  val = (char *) &chars;
-	  type = iaddr->family = AF_INET6;
-	}
-#endif /* HAVE_INET6 */
-      else
-	JvFail ("unrecognized size");
-
-#ifdef HAVE_GETHOSTBYADDR_R
-      while (true)
-	{
-	  int ok;
-#if HAVE_STRUCT_HOSTENT_DATA
-	  ok = ! gethostbyaddr_r (val, len, type, &hent_r, buffer_r);
-#else
-	  int herr = 0;
-#ifdef GETHOSTBYADDR_R_RETURNS_INT
-	  ok = ! gethostbyaddr_r (val, len, type, &hent_r,
-				  buffer_r, size_r, &hptr, &herr);
-#else
-	  hptr = gethostbyaddr_r (val, len, type, &hent_r,
-				  buffer_r, size_r, &herr);
-	  ok = hptr != NULL;
-#endif /* GETHOSTBYADDR_R_RETURNS_INT */
-	  if (! ok && herr == ERANGE)
-	    {
-	      size_r *= 2;
-	      buffer_r = (char *) _Jv_AllocBytes (size_r);
-	    }
-	  else 
-#endif /* HAVE_STRUCT_HOSTENT_DATA */
-	    break;
-	}
-#else /* HAVE_GETHOSTBYADDR_R */
-      // FIXME: this is insufficient if some other piece of code calls
-      // this gethostbyaddr.
-      JvSynchronize sync (java::net::InetAddress::loopbackAddress);
-      hptr = gethostbyaddr (val, len, type);
-#endif /* HAVE_GETHOSTBYADDR_R */
-    }
-  if (hptr != NULL)
-    {
-      if (!all)
-        host = JvNewStringUTF (hptr->h_name);
-    }
-  if (hptr == NULL)
-    {
-      if (iaddr != NULL && iaddr->addr != NULL)
-	{
-	  iaddr->hostName = iaddr->getHostAddress();
-	  return NULL;
-	}
-      else
-	throw new java::net::UnknownHostException(host);
-    }
-  int count;
-  if (all)
-    {
-      char** ptr = hptr->h_addr_list;
-      count = 0;
-      while (*ptr++)  count++;
-    }
-  else
-    count = 1;
-  JArray<java::net::InetAddress*> *result;
-  java::net::InetAddress** iaddrs;
-  if (all)
-    {
-      result = java::net::InetAddress::allocArray (count);
-      iaddrs = elements (result);
-    }
-  else
-    {
-      result = NULL;
-      iaddrs = &iaddr;
-    }
-
-  for (int i = 0;  i < count;  i++)
-    {
-      if (iaddrs[i] == NULL)
-	iaddrs[i] = new java::net::InetAddress (NULL, NULL);
-      if (iaddrs[i]->hostName == NULL)
-        iaddrs[i]->hostName = host;
-      if (iaddrs[i]->addr == NULL)
-	{
-	  char *bytes = hptr->h_addr_list[i];
-	  iaddrs[i]->addr = JvNewByteArray (hptr->h_length);
-	  iaddrs[i]->family = getFamily (iaddrs[i]->addr);
-	  memcpy (elements (iaddrs[i]->addr), bytes, hptr->h_length);
-	}
-    }
-  return result;
-}
-
-jstring
-java::net::InetAddress::getLocalHostname ()
-{
-  char *chars;
-#ifdef HAVE_GETHOSTNAME
-  char buffer[MAXHOSTNAMELEN];
-  if (gethostname (buffer, MAXHOSTNAMELEN))
-    return NULL;
-  chars = buffer;
-#elif HAVE_UNAME
-  struct utsname stuff;
-  if (uname (&stuff) != 0)
-    return NULL;
-  chars = stuff.nodename;
-#else
-  return NULL;
-#endif
-  // It is admittedly non-optimal to convert the hostname to Unicode
-  // only to convert it back in getByName, but simplicity wins.  Note
-  // that unless there is a SecurityManager, we only get called once
-  // anyway, thanks to the InetAddress.localhost cache.
-  return JvNewStringUTF (chars);
-}
Index: java/net/natInetAddressWin32.cc
===================================================================
--- java/net/natInetAddressWin32.cc	(revision 117194)
+++ java/net/natInetAddressWin32.cc	(working copy)
@@ -1,168 +0,0 @@
-/* Copyright (C) 2003  Free Software Foundation
-
-   This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
-
-#include <config.h>
-#include <platform.h>
-
-#undef STRICT
-
-#include <java/net/InetAddress.h>
-#include <java/net/UnknownHostException.h>
-#include <java/lang/SecurityException.h>
-
-jbyteArray
-java::net::InetAddress::aton (jstring host)
-{
-  JV_TEMP_UTF_STRING (hostname, host);
-  char* bytes = NULL;
-  int blen = 0;
-  unsigned long laddr = inet_addr (hostname);
-  if (laddr != INADDR_NONE)
-    {
-      bytes = (char*) &laddr;
-      blen = 4;
-    }
-  if (blen == 0)
-    return NULL;
-  jbyteArray result = JvNewByteArray (blen);
-  memcpy (elements (result), bytes, blen);
-  return result;
-}
-
-jint
-java::net::InetAddress::getFamily (jbyteArray bytes)
-{
-  int len = bytes->length;
-  if (len == 4)
-    return AF_INET;
-#ifdef HAVE_INET6
-  else if (len == 16)
-    return AF_INET6;
-#endif /* HAVE_INET6 */
-  else
-    JvFail ("unrecognized size");
-}
-
-
-JArray<java::net::InetAddress*> *
-java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
-        jboolean all)
-{
-  struct hostent *hptr = NULL;
-  if (host != NULL)
-    {
-      JV_TEMP_UTF_STRING (hostname, host);
-
-      // FIXME: this is insufficient if some other piece of code calls
-      // this gethostbyname.
-      JvSynchronize sync (java::net::InetAddress::loopbackAddress);
-      hptr = gethostbyname (hostname);
-    }
-  else
-    {
-      jbyteArray bytes = iaddr->addr;
-      char *chars = (char*) elements (bytes);
-      int len = bytes->length;
-      int type;
-      char *val;
-      if (len == 4)
-        {
-          val = chars;
-          type = iaddr->family = AF_INET;
-        }
-#ifdef HAVE_INET6
-      else if (len == 16)
-      {
-        val = (char *) &chars;
-        type = iaddr->family = AF_INET6;
-      }
-#endif /* HAVE_INET6 */
-      else
-        JvFail ("unrecognized size");
-
-      // FIXME: this is insufficient if some other piece of code calls
-      // this gethostbyaddr.
-      JvSynchronize sync (java::net::InetAddress::loopbackAddress);
-      hptr = gethostbyaddr (val, len, type);
-    }
-  if (hptr != NULL)
-    {
-      if (!all)
-        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 (iaddr != NULL && iaddr->addr != NULL)
-        {
-          iaddr->hostName = iaddr->getHostAddress();
-          return NULL;
-        }
-      else
-        throw new java::net::UnknownHostException(host);
-    }
-
-  int count;
-  if (all)
-    {
-      char** ptr = hptr->h_addr_list;
-      count = 0;
-      while (*ptr++)  count++;
-    }
-  else
-    count = 1;
-
-  JArray<java::net::InetAddress*> *result;
-  java::net::InetAddress** iaddrs;
-  if (all)
-    {
-      result = java::net::InetAddress::allocArray (count);
-      iaddrs = elements (result);
-    }
-  else
-    {
-      result = NULL;
-      iaddrs = &iaddr;
-    }
-
-  for (int i = 0;  i < count;  i++)
-    {
-      if (iaddrs[i] == NULL)
-        iaddrs[i] = new java::net::InetAddress (NULL, NULL);
-      if (iaddrs[i]->hostName == NULL)
-        iaddrs[i]->hostName = host;
-      if (iaddrs[i]->addr == NULL)
-        {
-          char *bytes = hptr->h_addr_list[i];
-          iaddrs[i]->addr = JvNewByteArray (hptr->h_length);
-          iaddrs[i]->family = getFamily (iaddrs[i]->addr);
-          memcpy (elements (iaddrs[i]->addr), bytes, hptr->h_length);
-        }
-    }
-    
-  return result;
-}
-
-jstring
-java::net::InetAddress::getLocalHostname ()
-{
-  char buffer[400];
-  if (gethostname (buffer, sizeof(buffer)))
-    return NULL;
-  // It is admittedly non-optimal to convert the hostname to Unicode
-  // only to convert it back in getByName, but simplicity wins.  Note
-  // that unless there is a SecurityManager, we only get called once
-  // anyway, thanks to the InetAddress.localhost cache.
-  return JvNewStringUTF (buffer);
-}
Index: java/net/VMInetAddress.java
===================================================================
--- java/net/VMInetAddress.java	(revision 117194)
+++ java/net/VMInetAddress.java	(working copy)
@@ -58,18 +58,12 @@
    *
    * @return The local hostname.
    */
-  public static String getLocalHostname()
-  {
-    return InetAddress.getLocalHostname();
-  }
+  public static native String getLocalHostname();
 
   /**
    * Returns the value of the special address INADDR_ANY
    */
-  public static byte[] lookupInaddrAny() throws UnknownHostException
-  {
-    return new byte[] {0, 0, 0, 0};
-  }
+  public static native byte[] lookupInaddrAny() throws UnknownHostException;
 
   /**
    * This method returns the hostname for a given IP address.  It will
@@ -81,26 +75,15 @@
    *
    * @exception UnknownHostException If the reverse lookup fails
    */
-  public static String getHostByAddr(byte[] ip) throws UnknownHostException
-  {
-    InetAddress addr = InetAddress.getByAddress(ip);
-    InetAddress.lookup(null, addr, false);
-    return addr.getHostName();
-  }
+  public 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.
    */
-  public static byte[][] getHostByName(String hostname)
-    throws UnknownHostException
-  {
-    InetAddress[] iaddrs = InetAddress.lookup(hostname, null, true);
-    byte[][] addrs = new byte[iaddrs.length][];
-    for (int i = 0; i < iaddrs.length; i++)
-      addrs[i] = iaddrs[i].getAddress();
-    return addrs;
-  }
+  public static native byte[][] getHostByName(String hostname)
+    throws UnknownHostException;
 
   /**
    * Return the IP address represented by a literal address.
@@ -110,8 +93,5 @@
    *
    * @return The IP address as a byte array
    */
-  public static byte[] aton(String address)
-  {
-    return InetAddress.aton(address);
-  }
+  public static native byte[] aton(String address);
 }
Index: java/net/natVMInetAddressNoNet.cc
===================================================================
--- java/net/natVMInetAddressNoNet.cc	(revision 0)
+++ java/net/natVMInetAddressNoNet.cc	(revision 0)
@@ -0,0 +1,40 @@
+/* Copyright (C) 2003, 2006  Free Software Foundation
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+#include <config.h>
+#include <stddef.h>
+
+jstring
+java::net::VMInetAddress::getLocalHostname ()
+{
+  return NULL;
+}
+
+jbyteArray
+java::net::VMInetAddress::lookupInaddrAny ()
+{
+  return NULL;
+}
+
+jstring
+java::net::VMInetAddress::getHostByAddr (jbyteArray addr)
+{
+  return NULL;
+}
+
+JArray<jbyteArray> *
+java::net::VMInetAddress::getHostByName (jstring host)
+{
+  return NULL;
+}
+
+jbyteArray
+java::net::VMInetAddress::aton (jstring host)
+{
+  return NULL;
+}
Index: java/net/natVMInetAddressPosix.cc
===================================================================
--- java/net/natVMInetAddressPosix.cc	(revision 0)
+++ java/net/natVMInetAddressPosix.cc	(revision 0)
@@ -0,0 +1,289 @@
+/* Copyright (C) 2003, 2006  Free Software Foundation
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+#include <config.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <string.h>
+#include <errno.h>
+
+#include <sys/param.h>
+#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
+#include <gcj/cni.h>
+#include <jvm.h>
+#include <java/net/VMInetAddress.h>
+#include <java/net/UnknownHostException.h>
+
+#if defined(HAVE_UNAME) && ! defined(HAVE_GETHOSTNAME)
+#include <sys/utsname.h>
+#endif
+
+#ifndef HAVE_GETHOSTNAME_DECL
+extern "C" int gethostname (char *name, int namelen);
+#endif
+
+jstring
+java::net::VMInetAddress::getLocalHostname ()
+{
+  char *chars;
+#ifdef HAVE_GETHOSTNAME
+  char buffer[MAXHOSTNAMELEN];
+  if (gethostname (buffer, MAXHOSTNAMELEN))
+    return NULL;
+  chars = buffer;
+#elif HAVE_UNAME
+  struct utsname stuff;
+  if (uname (&stuff) != 0)
+    return NULL;
+  chars = stuff.nodename;
+#else
+  return NULL;
+#endif
+  // It is admittedly non-optimal to convert the hostname to Unicode
+  // only to convert it back in getByName, but simplicity wins.
+  return JvNewStringUTF (chars);
+}
+
+jbyteArray
+java::net::VMInetAddress::lookupInaddrAny ()
+{
+#if ! HAVE_IN_ADDR_T
+  typedef jint in_addr_t;
+#endif
+  in_addr_t laddr = INADDR_ANY;
+  char *bytes = (char *) &laddr;
+  int blen = sizeof (laddr);
+  jbyteArray result = JvNewByteArray (blen);
+  memcpy (elements (result), bytes, blen);
+  return result;
+}
+
+jstring
+java::net::VMInetAddress::getHostByAddr (jbyteArray addr)
+{
+  struct hostent *hptr = NULL;
+#ifdef HAVE_GETHOSTBYADDR_R
+  struct hostent hent_r;
+#if HAVE_STRUCT_HOSTENT_DATA
+  struct hostent_data fixed_buffer, *buffer_r = &fixed_buffer;
+#else
+#ifdef __GLIBC__
+  // FIXME: in glibc, gethostbyname_r returns NETDB_INTERNAL to herr and
+  // ERANGE to errno if the buffer size is too small, rather than what is 
+  // expected here. We work around this by setting a bigger buffer size and 
+  // hoping that it is big enough.
+  char fixed_buffer[1024];
+#else
+  char fixed_buffer[200];
+#endif /* __GLIBC__ */
+  char *buffer_r = fixed_buffer;
+  int size_r = sizeof (fixed_buffer);
+#endif /* HAVE_STRUCT_HOSTENT_DATA */
+#endif /* HAVE_GETHOSTBYADDR_R */
+
+  char *bytes = (char*) elements (addr);
+  int len = addr->length;
+  int type;
+  char *val;
+  if (len == 4)
+    {
+      val = bytes;
+      type = AF_INET;
+    }
+#ifdef HAVE_INET6
+  else if (len == 16)
+    {
+      val = (char *) &bytes;
+      type = AF_INET6;
+    }
+#endif /* HAVE_INET6 */
+  else
+    JvFail ("unrecognized size");
+
+#ifdef HAVE_GETHOSTBYADDR_R
+  while (true)
+    {
+      int ok;
+#if HAVE_STRUCT_HOSTENT_DATA
+      ok = ! gethostbyaddr_r (val, len, type, &hent_r, buffer_r);
+#else
+      int herr = 0;
+#ifdef GETHOSTBYADDR_R_RETURNS_INT
+      ok = ! gethostbyaddr_r (val, len, type, &hent_r,
+			      buffer_r, size_r, &hptr, &herr);
+#else
+      hptr = gethostbyaddr_r (val, len, type, &hent_r,
+			      buffer_r, size_r, &herr);
+      ok = hptr != NULL;
+#endif /* GETHOSTBYADDR_R_RETURNS_INT */
+      if (! ok && herr == ERANGE)
+	{
+	  size_r *= 2;
+	  buffer_r = (char *) _Jv_AllocBytes (size_r);
+	}
+      else 
+#endif /* HAVE_STRUCT_HOSTENT_DATA */
+	break;
+    }
+#else /* HAVE_GETHOSTBYADDR_R */
+  // FIXME: this is insufficient if some other piece of code calls
+  // this gethostbyaddr.
+  JvSynchronize sync (&java::net::VMInetAddress::class$);
+  hptr = gethostbyaddr (val, len, type);
+#endif /* HAVE_GETHOSTBYADDR_R */
+
+  if (hptr == NULL)
+    throw new java::net::UnknownHostException ();
+
+  return JvNewStringUTF (hptr->h_name);
+}
+
+JArray<jbyteArray> *
+java::net::VMInetAddress::getHostByName (jstring host)
+{
+  struct hostent *hptr = NULL;
+#ifdef HAVE_GETHOSTBYNAME_R
+  struct hostent hent_r;
+#if HAVE_STRUCT_HOSTENT_DATA
+  struct hostent_data fixed_buffer, *buffer_r = &fixed_buffer;
+#else
+#ifdef __GLIBC__
+  // FIXME: in glibc, gethostbyname_r returns NETDB_INTERNAL to herr and
+  // ERANGE to errno if the buffer size is too small, rather than what is 
+  // expected here. We work around this by setting a bigger buffer size and 
+  // hoping that it is big enough.
+  char fixed_buffer[1024];
+#else
+  char fixed_buffer[200];
+#endif /* __GLIBC__ */
+  char *buffer_r = fixed_buffer;
+  int size_r = sizeof (fixed_buffer);
+#endif /* HAVE_STRUCT_HOSTENT_DATA */
+#endif /* HAVE_GETHOSTBYNAME_R */
+
+  char *hostname;
+  char buf[100];
+  int len = JvGetStringUTFLength(host);
+  if (len < 100)
+    hostname = buf;
+  else
+    hostname = (char *) _Jv_AllocBytes (len + 1);
+  JvGetStringUTFRegion (host, 0, host->length(), hostname);
+  buf[len] = '\0';
+#ifdef HAVE_GETHOSTBYNAME_R
+  while (true)
+    {
+      int ok;
+#if HAVE_STRUCT_HOSTENT_DATA
+      ok = ! gethostbyname_r (hostname, &hent_r, buffer_r);
+#else
+      int herr = 0;
+#ifdef GETHOSTBYNAME_R_RETURNS_INT
+      ok = ! gethostbyname_r (hostname, &hent_r, buffer_r, size_r,
+			      &hptr, &herr);
+#else
+      hptr = gethostbyname_r (hostname, &hent_r, buffer_r, size_r, &herr);
+      ok = hptr != NULL;
+#endif /* GETHOSTNAME_R_RETURNS_INT */
+      if (! ok && herr == ERANGE)
+	{
+	  size_r *= 2;
+	  buffer_r = (char *) _Jv_AllocBytes (size_r);
+	}
+      else
+#endif /* HAVE_STRUCT_HOSTENT_DATA */
+	break;
+    }
+#else /* HAVE_GETHOSTBYNAME_R */
+  // FIXME: this is insufficient if some other piece of code calls
+  // this gethostbyname.
+  JvSynchronize sync (&java::net::VMInetAddress::class$);
+  hptr = gethostbyname (hostname);
+#endif /* HAVE_GETHOSTBYNAME_R */
+
+  if (hptr == NULL)
+    throw new java::net::UnknownHostException (host);
+
+  int count = 0;
+  char ** ptr = hptr->h_addr_list;
+  while (*ptr++)  count++;
+
+  JArray<jbyteArray> *result =
+    (JArray<jbyteArray> *) _Jv_NewObjectArray (
+      count, _Jv_GetArrayClass(JvPrimClass(byte), NULL), NULL);
+  jbyteArray* addrs = elements (result);
+
+  for (int i = 0; i < count; i++)
+    {
+      addrs[i] = JvNewByteArray (hptr->h_length);
+      memcpy (elements (addrs[i]), hptr->h_addr_list[i], hptr->h_length);
+    }
+  return result;
+}
+
+jbyteArray
+java::net::VMInetAddress::aton (jstring host)
+{
+  char *hostname;
+  char buf[100];
+  int len = JvGetStringUTFLength(host);
+  if (len < 100)
+    hostname = buf;
+  else
+    hostname = (char *) _Jv_AllocBytes (len+1);
+  JvGetStringUTFRegion (host, 0, host->length(), hostname);
+  buf[len] = '\0';
+  char *bytes = NULL;
+  int blen = 0;
+#ifdef HAVE_INET_ATON
+  struct in_addr laddr;
+  if (inet_aton (hostname, &laddr))
+    {
+      bytes = (char *) &laddr;
+      blen = 4;
+    }
+#elif defined(HAVE_INET_ADDR)
+#if ! HAVE_IN_ADDR_T
+  typedef jint in_addr_t;
+#endif
+  in_addr_t laddr = inet_addr (hostname);
+  if (laddr != (in_addr_t)(-1))
+    {
+      bytes = (char *) &laddr;
+      blen = 4;
+    }
+#endif
+#if defined (HAVE_INET_PTON) && defined (HAVE_INET6)
+  char inet6_addr[16];
+  if (len != 0 && inet_pton (AF_INET6, hostname, inet6_addr) > 0)
+    {
+      bytes = inet6_addr;
+      blen = 16;
+    }
+#endif
+  if (blen == 0)
+    return NULL;
+  jbyteArray result = JvNewByteArray (blen);
+  memcpy (elements (result), bytes, blen);
+  return result;
+}
Index: java/net/natVMInetAddressWin32.cc
===================================================================
--- java/net/natVMInetAddressWin32.cc	(revision 0)
+++ java/net/natVMInetAddressWin32.cc	(revision 0)
@@ -0,0 +1,121 @@
+/* Copyright (C) 2003, 2006 Free Software Foundation
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+#include <config.h>
+#include <platform.h>
+
+#undef STRICT
+
+#include <java/net/VMInetAddress.h>
+#include <java/net/UnknownHostException.h>
+
+jstring
+java::net::VMInetAddress::getLocalHostname ()
+{
+  char buffer[400];
+  if (gethostname (buffer, sizeof(buffer)))
+    return NULL;
+  // It is admittedly non-optimal to convert the hostname to Unicode
+  // only to convert it back in getByName, but simplicity wins.
+  return JvNewStringUTF (buffer);
+}
+
+jbyteArray
+java::net::VMInetAddress::lookupInaddrAny ()
+{
+  unsigned long laddr = INADDR_ANY;
+  char *bytes = (char *) &laddr;
+  int blen = sizeof (laddr);
+  jbyteArray result = JvNewByteArray (blen);
+  memcpy (elements (result), bytes, blen);
+  return result;
+}
+
+jstring
+java::net::VMInetAddress::getHostByAddr (jbyteArray addr)
+{
+  struct hostent *hptr = NULL;
+  char *bytes = (char*) elements (addr);
+  int len = addr->length;
+  int type;
+  char *val;
+  if (len == 4)
+    {
+      val = bytes;
+      type = AF_INET;
+    }
+#ifdef HAVE_INET6
+  else if (len == 16)
+    {
+      val = (char *) &bytes;
+      type = AF_INET6;
+    }
+#endif /* HAVE_INET6 */
+  else
+    JvFail ("unrecognized size");
+
+  // FIXME: this is insufficient if some other piece of code calls
+  // this gethostbyaddr.
+  JvSynchronize sync (&java::net::VMInetAddress::class$);
+  hptr = gethostbyaddr (val, len, type);
+
+  if (hptr == NULL)
+    throw new java::net::UnknownHostException ();
+
+  return JvNewStringUTF (hptr->h_name);
+}
+
+JArray<jbyteArray> *
+java::net::VMInetAddress::getHostByName (jstring host)
+{
+  struct hostent *hptr = NULL;
+  JV_TEMP_UTF_STRING (hostname, host);
+
+  // FIXME: this is insufficient if some other piece of code calls
+  // this gethostbyname.
+  JvSynchronize sync (&java::net::VMInetAddress::class$);
+  hptr = gethostbyname (hostname);
+
+  if (hptr == NULL)
+    throw new java::net::UnknownHostException (host);
+
+  int count = 0;
+  char ** ptr = hptr->h_addr_list;
+  while (*ptr++)  count++;
+
+  JArray<jbyteArray> *result =
+    (JArray<jbyteArray> *) _Jv_NewObjectArray (
+      count, _Jv_GetArrayClass(JvPrimClass(byte), NULL), NULL);
+  jbyteArray* addrs = elements (result);
+
+  for (int i = 0; i < count; i++)
+    {
+      addrs[i] = JvNewByteArray (hptr->h_length);
+      memcpy (elements (addrs[i]), hptr->h_addr_list[i], hptr->h_length);
+    }
+  return result;
+}
+
+jbyteArray
+java::net::VMInetAddress::aton (jstring host)
+{
+  JV_TEMP_UTF_STRING (hostname, host);
+  char* bytes = NULL;
+  int blen = 0;
+  unsigned long laddr = inet_addr (hostname);
+  if (laddr != INADDR_NONE)
+    {
+      bytes = (char *) &laddr;
+      blen = 4;
+    }
+  if (blen == 0)
+    return NULL;
+  jbyteArray result = JvNewByteArray (blen);
+  memcpy (elements (result), bytes, blen);
+  return result;
+}
Index: Makefile.am
===================================================================
--- Makefile.am	(revision 117194)
+++ Makefile.am	(working copy)
@@ -852,7 +852,7 @@
 java/lang/reflect/natField.cc \
 java/lang/reflect/natMethod.cc \
 java/net/natVMNetworkInterface.cc \
-java/net/natInetAddress.cc \
+java/net/natVMInetAddress.cc \
 java/net/natURLClassLoader.cc \
 java/nio/channels/natVMChannels.cc \
 java/nio/natDirectByteBufferImpl.cc \
Index: configure.ac
===================================================================
--- configure.ac	(revision 117194)
+++ configure.ac	(working copy)
@@ -663,9 +663,9 @@
 AC_CONFIG_LINKS(java/lang/ConcreteProcess.java:java/lang/${PLATFORM}Process.java)
 AC_CONFIG_LINKS(java/lang/natConcreteProcess.cc:java/lang/nat${PLATFORM}Process.cc)
 
-# Likewise for natInetAddress.cc and natVMNetworkInterface.cc.
+# Likewise for natVMInetAddress.cc and natVMNetworkInterface.cc.
 test -d java/net || mkdir java/net
-AC_CONFIG_LINKS(java/net/natInetAddress.cc:java/net/natInetAddress${PLATFORMNET}.cc)
+AC_CONFIG_LINKS(java/net/natVMInetAddress.cc:java/net/natVMInetAddress${PLATFORMNET}.cc)
 AC_CONFIG_LINKS(java/net/natVMNetworkInterface.cc:java/net/natVMNetworkInterface${PLATFORMNET}.cc)
 
 # Likewise for natPlainSocketImpl.cc and natPlainDatagramSocketImpl.cc.
Index: sources.am
===================================================================
--- sources.am	(revision 117194)
+++ sources.am	(working copy)
@@ -5211,7 +5211,7 @@
 classpath/java/net/HttpURLConnection.java \
 classpath/java/net/Inet4Address.java \
 classpath/java/net/Inet6Address.java \
-java/net/InetAddress.java \
+classpath/java/net/InetAddress.java \
 classpath/java/net/InetSocketAddress.java \
 classpath/java/net/JarURLConnection.java \
 classpath/java/net/MalformedURLException.java \
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 117194)
+++ Makefile.in	(working copy)
@@ -93,7 +93,7 @@
 	$(top_builddir)/gcj/libgcj-config.h
 CONFIG_CLEAN_FILES = libgcj.pc libgcj.spec libgcj-test.spec \
 	scripts/jar java/io/natFile.cc java/lang/ConcreteProcess.java \
-	java/lang/natConcreteProcess.cc java/net/natInetAddress.cc \
+	java/lang/natConcreteProcess.cc java/net/natVMInetAddress.cc \
 	java/net/natVMNetworkInterface.cc \
 	gnu/java/net/natPlainSocketImpl.cc \
 	gnu/java/net/natPlainDatagramSocketImpl.cc \
@@ -298,7 +298,7 @@
 	java/lang/ref/natReference.cc java/lang/reflect/natArray.cc \
 	java/lang/reflect/natConstructor.cc \
 	java/lang/reflect/natField.cc java/lang/reflect/natMethod.cc \
-	java/net/natVMNetworkInterface.cc java/net/natInetAddress.cc \
+	java/net/natVMNetworkInterface.cc java/net/natVMInetAddress.cc \
 	java/net/natURLClassLoader.cc \
 	java/nio/channels/natVMChannels.cc \
 	java/nio/natDirectByteBufferImpl.cc \
@@ -345,7 +345,7 @@
 	java/lang/ref/natReference.lo java/lang/reflect/natArray.lo \
 	java/lang/reflect/natConstructor.lo \
 	java/lang/reflect/natField.lo java/lang/reflect/natMethod.lo \
-	java/net/natVMNetworkInterface.lo java/net/natInetAddress.lo \
+	java/net/natVMNetworkInterface.lo java/net/natVMInetAddress.lo \
 	java/net/natURLClassLoader.lo \
 	java/nio/channels/natVMChannels.lo \
 	java/nio/natDirectByteBufferImpl.lo \
@@ -4124,7 +4124,7 @@
 classpath/java/net/HttpURLConnection.java \
 classpath/java/net/Inet4Address.java \
 classpath/java/net/Inet6Address.java \
-java/net/InetAddress.java \
+classpath/java/net/InetAddress.java \
 classpath/java/net/InetSocketAddress.java \
 classpath/java/net/JarURLConnection.java \
 classpath/java/net/MalformedURLException.java \
@@ -7422,7 +7422,7 @@
 java/lang/reflect/natField.cc \
 java/lang/reflect/natMethod.cc \
 java/net/natVMNetworkInterface.cc \
-java/net/natInetAddress.cc \
+java/net/natVMInetAddress.cc \
 java/net/natURLClassLoader.cc \
 java/nio/channels/natVMChannels.cc \
 java/nio/natDirectByteBufferImpl.cc \
@@ -7912,7 +7912,7 @@
 	@: > java/net/$(DEPDIR)/$(am__dirstamp)
 java/net/natVMNetworkInterface.lo: java/net/$(am__dirstamp) \
 	java/net/$(DEPDIR)/$(am__dirstamp)
-java/net/natInetAddress.lo: java/net/$(am__dirstamp) \
+java/net/natVMInetAddress.lo: java/net/$(am__dirstamp) \
 	java/net/$(DEPDIR)/$(am__dirstamp)
 java/net/natURLClassLoader.lo: java/net/$(am__dirstamp) \
 	java/net/$(DEPDIR)/$(am__dirstamp)
@@ -8242,10 +8242,10 @@
 	-rm -f java/lang/reflect/natField.lo
 	-rm -f java/lang/reflect/natMethod.$(OBJEXT)
 	-rm -f java/lang/reflect/natMethod.lo
-	-rm -f java/net/natInetAddress.$(OBJEXT)
-	-rm -f java/net/natInetAddress.lo
 	-rm -f java/net/natURLClassLoader.$(OBJEXT)
 	-rm -f java/net/natURLClassLoader.lo
+	-rm -f java/net/natVMInetAddress.$(OBJEXT)
+	-rm -f java/net/natVMInetAddress.lo
 	-rm -f java/net/natVMNetworkInterface.$(OBJEXT)
 	-rm -f java/net/natVMNetworkInterface.lo
 	-rm -f java/nio/channels/natVMChannels.$(OBJEXT)
@@ -8372,8 +8372,8 @@
 @AMDEP_TRUE@@am__include@ @am__quote@java/lang/reflect/$(DEPDIR)/natConstructor.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/lang/reflect/$(DEPDIR)/natField.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/lang/reflect/$(DEPDIR)/natMethod.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natInetAddress.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natURLClassLoader.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natVMInetAddress.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natVMNetworkInterface.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/nio/$(DEPDIR)/natDirectByteBufferImpl.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/nio/channels/$(DEPDIR)/natVMChannels.Plo@am__quote@
Index: configure
===================================================================
--- configure	(revision 117194)
+++ configure	(working copy)
@@ -7486,9 +7486,9 @@
           ac_config_links="$ac_config_links java/lang/natConcreteProcess.cc:java/lang/nat${PLATFORM}Process.cc"
 
 
-# Likewise for natInetAddress.cc and natVMNetworkInterface.cc.
+# Likewise for natVMInetAddress.cc and natVMNetworkInterface.cc.
 test -d java/net || mkdir java/net
-          ac_config_links="$ac_config_links java/net/natInetAddress.cc:java/net/natInetAddress${PLATFORMNET}.cc"
+          ac_config_links="$ac_config_links java/net/natVMInetAddress.cc:java/net/natVMInetAddress${PLATFORMNET}.cc"
 
           ac_config_links="$ac_config_links java/net/natVMNetworkInterface.cc:java/net/natVMNetworkInterface${PLATFORMNET}.cc"
 
@@ -17389,7 +17389,7 @@
   "java/io/natFile.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/io/natFile.cc:java/io/natFile${FILE-${PLATFORM}}.cc" ;;
   "java/lang/ConcreteProcess.java" ) CONFIG_LINKS="$CONFIG_LINKS java/lang/ConcreteProcess.java:java/lang/${PLATFORM}Process.java" ;;
   "java/lang/natConcreteProcess.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/lang/natConcreteProcess.cc:java/lang/nat${PLATFORM}Process.cc" ;;
-  "java/net/natInetAddress.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/net/natInetAddress.cc:java/net/natInetAddress${PLATFORMNET}.cc" ;;
+  "java/net/natVMInetAddress.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/net/natVMInetAddress.cc:java/net/natVMInetAddress${PLATFORMNET}.cc" ;;
   "java/net/natVMNetworkInterface.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/net/natVMNetworkInterface.cc:java/net/natVMNetworkInterface${PLATFORMNET}.cc" ;;
   "gnu/java/net/natPlainSocketImpl.cc" ) CONFIG_LINKS="$CONFIG_LINKS gnu/java/net/natPlainSocketImpl.cc:gnu/java/net/natPlainSocketImpl${PLATFORMNET}.cc" ;;
   "gnu/java/net/natPlainDatagramSocketImpl.cc" ) CONFIG_LINKS="$CONFIG_LINKS gnu/java/net/natPlainDatagramSocketImpl.cc:gnu/java/net/natPlainDatagramSocketImpl${PLATFORMNET}.cc" ;;
Index: java/net/natVMNetworkInterfaceWin32.cc
===================================================================
--- java/net/natVMNetworkInterfaceWin32.cc	(revision 117194)
+++ java/net/natVMNetworkInterfaceWin32.cc	(working copy)
@@ -12,7 +12,7 @@
 #undef STRICT
 
 #include <java/net/NetworkInterface.h>
-#include <java/net/Inet4Address.h>
+#include <java/net/InetAddress.h>
 #include <java/net/SocketException.h>
 #include <java/net/VMNetworkInterface.h>
 #include <java/util/Vector.h>
@@ -83,8 +83,8 @@
         }
 
       jstring if_name = _Jv_Win32NewString (szName);
-      java::net::Inet4Address* address =
-        new java::net::Inet4Address (baddr, JvNewStringLatin1 (""));
+      java::net::InetAddress* address =
+        java::net::InetAddress::getByAddress (baddr);
       pjstrName[i] = if_name;
       ppAddress[i] = address;
     }
Index: gnu/java/net/natPlainSocketImplWin32.cc
===================================================================
--- gnu/java/net/natPlainSocketImplWin32.cc	(revision 117194)
+++ gnu/java/net/natPlainSocketImplWin32.cc	(working copy)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003, 2004, 2005 Free Software Foundation
+/* Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
 
    This file is part of libgcj.
 
@@ -328,7 +328,7 @@
 
   s->native_fd = (jint) hSocket;
   s->localport = localport;
-  s->address = new ::java::net::InetAddress (raddr, NULL);
+  s->address = ::java::net::InetAddress::getByAddress (raddr);
   s->port = rport;
   return;
 
@@ -735,7 +735,7 @@
           else
             throw new ::java::net::SocketException
               (JvNewStringUTF ("invalid family"));
-          localAddress = new ::java::net::InetAddress (laddr, NULL);
+          localAddress = ::java::net::InetAddress::getByAddress (laddr);
         }
 
       return localAddress;
Index: gnu/java/net/natPlainDatagramSocketImplWin32.cc
===================================================================
--- gnu/java/net/natPlainDatagramSocketImplWin32.cc	(revision 117194)
+++ gnu/java/net/natPlainDatagramSocketImplWin32.cc	(working copy)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003  Free Software Foundation
+/* Copyright (C) 2003, 2006 Free Software Foundation
 
    This file is part of libgcj.
 
@@ -238,7 +238,7 @@
   else
     throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
 
-  p->setAddress (new ::java::net::InetAddress (raddr, NULL));
+  p->setAddress (::java::net::InetAddress::getByAddress (raddr));
   p->setPort (rport);
   p->length = (jint) retlen;
   return rport;
@@ -360,7 +360,7 @@
   else
     throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
 
-  p->setAddress (new ::java::net::InetAddress (raddr, NULL));
+  p->setAddress (::java::net::InetAddress::getByAddress (raddr));
   p->setPort (rport);
   p->length = (jint) retlen;
   return;
@@ -656,7 +656,7 @@
       else
         throw new ::java::net::SocketException (
             JvNewStringUTF ("invalid family"));
-      localAddress = new ::java::net::InetAddress (laddr, NULL);
+      localAddress = ::java::net::InetAddress::getByAddress (laddr);
     }
   return localAddress;
   break;
Index: classpath/java/net/Inet4Address.java
===================================================================
--- classpath/java/net/Inet4Address.java	(revision 117194)
+++ classpath/java/net/Inet4Address.java	(working copy)
@@ -59,14 +59,14 @@
   /**
    * The address family of these addresses (used for serialization).
    */
-  private static final int FAMILY = 2; // AF_INET
+  private static final int AF_INET = 2;
 
   /**
    * Inet4Address objects are serialized as InetAddress objects.
    */
   private Object writeReplace() throws ObjectStreamException
   {
-    return new InetAddress(addr, hostName, FAMILY);
+    return new InetAddress(addr, hostName, AF_INET);
   }
   
   /**
@@ -79,7 +79,7 @@
    */
   Inet4Address(byte[] addr, String host)
   {
-    super(addr, host, FAMILY);
+    super(addr, host, AF_INET);
   }
 
   /**
Index: classpath/java/net/Inet6Address.java
===================================================================
--- classpath/java/net/Inet6Address.java	(revision 117194)
+++ classpath/java/net/Inet6Address.java	(working copy)
@@ -95,7 +95,7 @@
   /**
    * The address family of these addresses (used for serialization).
    */
-  private static final int FAMILY = 10; // AF_INET6
+  private static final int AF_INET6 = 10;
 
   /**
    * Create an Inet6Address object
@@ -105,7 +105,7 @@
    */
   Inet6Address(byte[] addr, String host)
   {
-    super(addr, host, FAMILY);
+    super(addr, host, AF_INET6);
     // Super constructor clones the addr.  Get a reference to the clone.
     this.ipaddress = this.addr;
     ifname = null;

^ permalink raw reply	[flat|nested] 9+ messages in thread

* FYI: InetAddress merge
  2006-09-25 14:58   ` RFC: Updated " Gary Benson
@ 2006-11-03 10:23     ` Gary Benson
  2006-11-03 11:48       ` Anthony Green
  0 siblings, 1 reply; 9+ messages in thread
From: Gary Benson @ 2006-11-03 10:23 UTC (permalink / raw)
  To: java-patches

[-- Attachment #1: Type: text/plain, Size: 114 bytes --]

Hi all,

This commit completes the merge of InetAddress with Classpath that I
started in September.

Cheers,
Gary

[-- Attachment #2: inetaddress-merge-final.patch --]
[-- Type: text/plain, Size: 67585 bytes --]

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 118450)
+++ ChangeLog	(working copy)
@@ -1,3 +1,26 @@
+2006-11-03  Gary Benson  <gbenson@redhat.com>
+
+	* java/net/InetAddress.java: Removed.
+	* java/net/natInetAddressNoNet.cc: Likewise.
+	* java/net/natInetAddressPosix.cc: Likewise.
+	* java/net/natInetAddressWin32.cc: Likewise.
+	* java/net/VMInetAddress.java (getLocalHostname,
+	lookupInaddrAny, getHostByAddr, getHostByName,
+	aton): Replace glue methods with native ones.
+	* java/net/natVMInetAddressNoNet.cc: New file.
+	* java/net/natVMInetAddressPosix.cc: Likewise.
+	* java/net/natVMInetAddressWin32.cc: Likewise.
+	* Makefile.am, configure.ac: Reflect the above.
+	* sources.am, Makefile.in, configure: Rebuilt.
+
+	* java/net/natVMNetworkInterfaceWin32.cc
+	(winsock2GetRealNetworkInterfaces): Create InetAddress
+	objects using InetAddress.getByAddress.
+	* gnu/java/net/natPlainSocketImplWin32.cc
+	(accept, getOption): Likewise.
+	* gnu/java/net/natPlainDatagramSocketImplWin32.cc
+	(peekData, receive, getOption): Likewise.
+
 2006-11-02  Keith Seitz  <keiths@redhat.com>
 
 	* gnu/classpath/jdwp/natVMMethod.cc (getLineTable): Implement.
Index: classpath/ChangeLog.gcj
===================================================================
--- classpath/ChangeLog.gcj	(revision 118450)
+++ classpath/ChangeLog.gcj	(working copy)
@@ -1,3 +1,12 @@
+2006-11-03  Gary Benson  <gbenson@redhat.com>
+
+	* java/net/Inet4Address.java
+	(FAMILY): Renamed to AF_INET.
+	(<init>, writeReplace): Reflect the above.
+	* java/net/Inet6Address.java
+	(FAMILY): Renamed to AF_INET6.
+	(<init>): Reflect the above.	
+
 2006-10-10  Tom Tromey  <tromey@redhat.com>
 
 	PR classpath/29362:
Index: java/net/InetAddress.java
===================================================================
--- java/net/InetAddress.java	(revision 118450)
+++ java/net/InetAddress.java	(working copy)
@@ -1,819 +0,0 @@
-/* InetAddress.java -- Class to model an Internet address
-   Copyright (C) 1998, 1999, 2002, 2004, 2005, 2006
-   Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING.  If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library.  Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module.  An independent module is a module which is not derived from
-or based on this library.  If you modify this library, you may extend
-this exception to your version of the library, but you are not
-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.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamException;
-import java.io.Serializable;
-
-/**
- * This class models an Internet address.  It does not have a public
- * constructor.  Instead, new instances of this objects are created
- * using the static methods getLocalHost(), getByName(), and
- * getAllByName().
- *
- * <p>This class fulfills the function of the C style functions gethostname(),
- * gethostbyname(), and gethostbyaddr().  It resolves Internet DNS names
- * into their corresponding numeric addresses and vice versa.</p>
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- * @author Per Bothner
- * @author Gary Benson (gbenson@redhat.com)
- *
- * @specnote This class is not final since JK 1.4
- */
-public class InetAddress implements Serializable
-{
-  private static final long serialVersionUID = 3286316764910316507L;
-
-  /**
-   * Stores static localhost address object.
-   */
-  static InetAddress LOCALHOST;
-  static
-  {
-    try
-      {
-	LOCALHOST = getByAddress("localhost", new byte[] {127, 0, 0, 1});
-	// Some soon-to-be-removed native code synchronizes on this.
-	loopbackAddress = LOCALHOST;
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }    
-
-  /**
-   * Dummy InetAddress, used to bind socket to any (all) network interfaces.
-   */
-  static InetAddress ANY_IF;
-  static
-  {
-    byte[] addr;
-    try
-      {
-	addr = VMInetAddress.lookupInaddrAny();
-      }
-    catch (UnknownHostException e)
-      {
-	// Make one up and hope it works.
-	addr = new byte[] {0, 0, 0, 0};
-      }
-    try
-      {
-	ANY_IF = getByAddress(addr);
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-    ANY_IF.hostName = ANY_IF.getHostName();
-  }
-  
-  /**
-   * The Serialized Form specifies that an int 'address' is saved/restored.
-   * This class uses a byte array internally so we'll just do the conversion
-   * at serialization time and leave the rest of the algorithm as is.
-   */
-  private int address;
-
-  /**
-   * An array of octets representing an IP address.
-   */
-  transient byte[] addr;
-
-  /**
-   * The name of the host for this address.
-   */
-  String hostName;
-
-  /**
-   * Needed for serialization.
-   */
-  private int family;
-
-  /**
-   * Constructor.  Prior to the introduction of IPv6 support in 1.4,
-   * methods such as InetAddress.getByName() would return InetAddress
-   * objects.  From 1.4 such methods returned either Inet4Address or
-   * Inet6Address objects, but for compatibility Inet4Address objects
-   * are serialized as InetAddresses.  As such, there are only two
-   * places where it is appropriate to invoke this constructor: within
-   * subclasses constructors and within Inet4Address.writeReplace().
-   *
-   * @param ipaddr The IP number of this address as an array of bytes
-   * @param hostname The hostname of this IP address.
-   * @param family The address family of this IP address.
-   */
-  InetAddress(byte[] ipaddr, String hostname, int family)
-  {
-    addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone();
-    hostName = hostname;
-    this.family = family;
-  }
-
-  /**
-   * Returns true if this address is a multicast address, false otherwise.
-   * An address is multicast if the high four bits are "1110".  These are
-   * also known as "Class D" addresses.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @return true if mulitcast, false if not
-   *
-   * @since 1.1
-   */
-  public boolean isMulticastAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMulticastAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if the InetAddress in a wildcard address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isAnyLocalAddress()
-  {
-    // This is inefficient, but certain methods on Win32 create
-    // InetAddress objects using "new InetAddress" rather than
-    // "InetAddress.getByAddress" so we provide a method body.
-    // This code is never executed on Posix systems.
-    try
-      {
-	return getByAddress(hostName, addr).isAnyLocalAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if the InetAddress is a loopback address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isLoopbackAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isLoopbackAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a link local address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isLinkLocalAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isLinkLocalAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a site local address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isSiteLocalAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isSiteLocalAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a global multicast address
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCGlobal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCGlobal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a node local multicast address.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCNodeLocal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCNodeLocal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a link local multicast address.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCLinkLocal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCLinkLocal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a site local multicast address.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCSiteLocal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCSiteLocal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Utility routine to check if InetAddress is a organization local
-   * multicast address.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @since 1.4
-   */
-  public boolean isMCOrgLocal()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).isMCOrgLocal();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Returns the hostname for this address.  This will return the IP address
-   * as a String if there is no hostname available for this address
-   *
-   * @return The hostname for this address
-   */
-  public String getHostName()
-  {
-    if (hostName == null)
-      hostName = getCanonicalHostName();
-
-    return hostName;
-  }
-
-  /**
-   * Returns the canonical hostname represented by this InetAddress
-   */
-  String internalGetCanonicalHostName()
-  {
-    try
-      {
-	return ResolverCache.getHostByAddr(addr);
-      }
-    catch (UnknownHostException e)
-      {
-	return getHostAddress();
-      }
-  }
-
-  /**
-   * Returns the canonical hostname represented by this InetAddress
-   * 
-   * @since 1.4
-   */
-  public String getCanonicalHostName()
-  {
-    String hostname = internalGetCanonicalHostName();
-
-    SecurityManager sm = System.getSecurityManager();
-    if (sm != null)
-      {
-        try
-	  {
-            sm.checkConnect(hostname, -1);
-	  }
-	catch (SecurityException e)
-	  {
-	    return getHostAddress();
-	  }
-      }
-
-    return hostname;
-  }
-
-  /**
-   * Returns the IP address of this object as a byte array.
-   *
-   * @return IP address
-   */
-  public byte[] getAddress()
-  {
-    // An experiment shows that JDK1.2 returns a different byte array each
-    // time.  This makes sense, in terms of security.
-    return (byte[]) addr.clone();
-  }
-
-  /**
-   * Returns the IP address of this object as a String.
-   *
-   * <p>This method cannot be abstract for backward compatibility reasons. By
-   * default it always throws {@link UnsupportedOperationException} unless
-   * overridden.</p>
-   * 
-   * @return The IP address of this object in String form
-   *
-   * @since 1.0.2
-   */
-  public String getHostAddress()
-  {
-    // This method is masked on Posix systems, where all InetAddress
-    // objects are created using InetAddress.getByAddress() which 
-    // returns either Inet4Address or Inet6Address objects.  Certain
-    // native methods on Win32 use "new InetAddress" in which case
-    // this method will be visible.
-    try
-      {
-	return getByAddress(hostName, addr).getHostAddress();
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Returns a hash value for this address.  Useful for creating hash
-   * tables.  Overrides Object.hashCode()
-   *
-   * @return A hash value for this address.
-   */
-  public int hashCode()
-  {
-    // There hashing algorithm is not specified, but a simple experiment
-    // shows that it is equal to the address, as a 32-bit big-endian integer.
-    int hash = 0;
-    int len = addr.length;
-    int i = len > 4 ? len - 4 : 0;
-
-    for (; i < len; i++)
-      hash = (hash << 8) | (addr[i] & 0xff);
-
-    return hash;
-  }
-
-  /**
-   * Tests this address for equality against another InetAddress.  The two
-   * addresses are considered equal if they contain the exact same octets.
-   * This implementation overrides Object.equals()
-   *
-   * @param obj The address to test for equality
-   *
-   * @return true if the passed in object's address is equal to this one's,
-   * false otherwise
-   */
-  public boolean equals(Object obj)
-  {
-    if (! (obj instanceof InetAddress))
-      return false;
-
-    // "The Java Class Libraries" 2nd edition says "If a machine has
-    // multiple names instances of InetAddress for different name of
-    // that same machine are not equal.  This is because they have
-    // different host names."  This violates the description in the
-    // JDK 1.2 API documentation.  A little experimentation
-    // shows that the latter is correct.
-    byte[] addr2 = ((InetAddress) obj).addr;
-
-    if (addr.length != addr2.length)
-      return false;
-
-    for (int i = 0; i < addr.length; i++)
-      if (addr[i] != addr2[i])
-	return false;
-
-    return true;
-  }
-
-  /**
-   * Converts this address to a String.  This string contains the IP in
-   * dotted decimal form. For example: "127.0.0.1"  This method is equivalent
-   * to getHostAddress() and overrides Object.toString()
-   *
-   * @return This address in String form
-   */
-  public String toString()
-  {
-    String addr = getHostAddress();
-    String host = (hostName != null) ? hostName : "";
-    return host + "/" + addr;
-  }
-
-  /**
-   * Returns an InetAddress object given the raw IP address.
-   *
-   * The argument is in network byte order: the highest order byte of the
-   * address is in getAddress()[0].
-   *
-   * @param addr The IP address to create the InetAddress object from
-   *
-   * @exception UnknownHostException If IP address has illegal length
-   *
-   * @since 1.4
-   */
-  public static InetAddress getByAddress(byte[] addr)
-    throws UnknownHostException
-  {
-    return getByAddress(null, addr);
-  }
-
-  /**
-   * Creates an InetAddress based on the provided host name and IP address.
-   * No name service is checked for the validity of the address.
-   *
-   * @param host The hostname of the InetAddress object to create
-   * @param addr The IP address to create the InetAddress object from
-   *
-   * @exception UnknownHostException If IP address is of illegal length
-   *
-   * @since 1.4
-   */
-  public static InetAddress getByAddress(String host, byte[] addr)
-    throws UnknownHostException
-  {
-    if (addr.length == 4)
-      return new Inet4Address(addr, host);
-
-    if (addr.length == 16)
-      {
-	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");
-  }
-
-  /**
-   * Returns an InetAddress object representing the IP address of
-   * the given literal IP address in dotted decimal format such as
-   * "127.0.0.1".  This is used by SocketPermission.setHostPort()
-   * to parse literal IP addresses without performing a DNS lookup.
-   *
-   * @param literal The literal IP address to create the InetAddress
-   * object from
-   *
-   * @return The address of the host as an InetAddress object, or
-   * null if the IP address is invalid.
-   */
-  static InetAddress getByLiteral(String literal)
-  {
-    byte[] address = VMInetAddress.aton(literal);
-    if (address == null)
-      return null;
-    
-    try
-      {
-	return getByAddress(address);
-      }
-    catch (UnknownHostException e)
-      {
-	throw new RuntimeException("should never happen", e);
-      }
-  }
-
-  /**
-   * Returns an InetAddress object representing the IP address of the given
-   * hostname.  This name can be either a hostname such as "www.urbanophile.com"
-   * or an IP address in dotted decimal format such as "127.0.0.1".  If the
-   * hostname is null or "", the hostname of the local machine is supplied by
-   * default.  This method is equivalent to returning the first element in
-   * the InetAddress array returned from GetAllByName.
-   *
-   * @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.
-   *
-   * @exception UnknownHostException If no IP address for the host could
-   * be found
-   * @exception SecurityException If a security manager exists and its
-   * checkConnect method doesn't allow the operation
-   */
-  public static InetAddress getByName(String hostname)
-    throws UnknownHostException
-  {
-    InetAddress[] addresses = getAllByName(hostname);
-    return addresses[0];
-  }
-
-  /**
-   * Returns an array of InetAddress objects representing all the host/ip
-   * addresses of a given host, given the host's name.  This name can be
-   * either a hostname such as "www.urbanophile.com" or an IP address in
-   * dotted decimal format such as "127.0.0.1".  If the value is null, the
-   * hostname of the local machine is supplied by default.
-   *
-   * @param hostname The name of the desired host, or null for the
-   * local loopback address.
-   *
-   * @return All addresses of the host as an array of InetAddress objects.
-   *
-   * @exception UnknownHostException If no IP address for the host could
-   * be found
-   * @exception SecurityException If a security manager exists and its
-   * checkConnect method doesn't allow the operation
-   */
-  public static InetAddress[] getAllByName(String hostname)
-    throws UnknownHostException
-  {
-    // If null or the empty string is supplied, the loopback address
-    // is returned.
-    if (hostname == null || hostname.length() == 0)
-      return new InetAddress[] {LOCALHOST};
-
-    // Check if hostname is an IP address
-    InetAddress address = getByLiteral(hostname);
-    if (address != null)
-      return new InetAddress[] {address};
-
-    // Perform security check before resolving
-    SecurityManager sm = System.getSecurityManager();
-    if (sm != null)
-      sm.checkConnect(hostname, -1);
-
-    // Resolve the hostname
-    byte[][] iplist = ResolverCache.getHostByName(hostname);
-    if (iplist.length == 0)
-      throw new UnknownHostException(hostname);
-
-    InetAddress[] addresses = new InetAddress[iplist.length];
-    for (int i = 0; i < iplist.length; i++)
-      addresses[i] = getByAddress(hostname, iplist[i]);
-
-    return addresses;
-  }
-
-  /**
-   * Returns an InetAddress object representing the address of the current
-   * host.
-   *
-   * @return The local host's address
-   *
-   * @exception UnknownHostException If no IP address for the host could
-   * be found
-   */
-  public static InetAddress getLocalHost() throws UnknownHostException
-  {
-    String hostname = VMInetAddress.getLocalHostname();
-    try
-      {
-	return getByName(hostname);
-      }
-    catch (SecurityException e)
-      {
-	return LOCALHOST;
-      }
-  }
-
-  /**
-   * Inet4Address objects are serialized as InetAddress objects.
-   * This deserializes them back into Inet4Address objects.
-   */
-  private Object readResolve() throws ObjectStreamException
-  {
-    return new Inet4Address(addr, hostName);
-  }
-
-  private void readObject(ObjectInputStream ois)
-    throws IOException, ClassNotFoundException
-  {
-    ois.defaultReadObject();
-    addr = new byte[4];
-    addr[3] = (byte) address;
-
-    for (int i = 2; i >= 0; --i)
-      addr[i] = (byte) (address >>= 8);
-  }
-
-  private void writeObject(ObjectOutputStream oos) throws IOException
-  {
-    // Build a 32 bit address from the last 4 bytes of a 4 byte IPv4 address
-    // or a 16 byte IPv6 address.
-    int len = addr.length;
-    int i = len - 4;
-
-    for (; i < len; i++)
-      address = address << 8 | (addr[i] & 0xff);
-
-    oos.defaultWriteObject();
-  }
-
-  // The native methods remain here for now;
-  // methods in VMInetAddress map onto them.
-  static native byte[] aton(String hostname);
-  static native InetAddress[] lookup (String hostname,
-				      InetAddress ipaddr, boolean all);
-  static native int getFamily (byte[] ipaddr);
-  static native String getLocalHostname();
-
-  // Some soon-to-be-removed native code synchronizes on this.
-  static InetAddress loopbackAddress;
-  
-  // Some soon-to-be-removed code uses this old and broken method.
-  InetAddress(byte[] ipaddr, String hostname)
-  {
-    addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone();
-    hostName = hostname;
-
-    if (ipaddr != null)
-      family = getFamily(ipaddr);
-  }
-
-  // Some soon-to-be-removed native code uses these old methods.
-  private static InetAddress[] allocArray (int count)
-  {
-    return new InetAddress [count];
-  }  
-  private static SecurityException checkConnect (String hostname)
-  {
-    return null;
-  }
-}
Index: java/net/natInetAddressNoNet.cc
===================================================================
--- java/net/natInetAddressNoNet.cc	(revision 118450)
+++ java/net/natInetAddressNoNet.cc	(working copy)
@@ -1,36 +0,0 @@
-/* Copyright (C) 2003  Free Software Foundation
-
-   This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
-
-#include <config.h>
-#include <stddef.h>
-
-#include <java/net/InetAddress.h>
-
-jbyteArray
-java::net::InetAddress::aton (jstring)
-{
-  return NULL;
-}
-
-jint
-java::net::InetAddress::getFamily (jbyteArray bytes)
-{
-  return 0;
-}
-
-JArray<java::net::InetAddress*> *
-java::net::InetAddress::lookup (jstring, java::net::InetAddress *, jboolean)
-{
-  return NULL;
-}
-
-jstring
-java::net::InetAddress::getLocalHostname ()
-{
-  return NULL;
-}
Index: java/net/natInetAddressPosix.cc
===================================================================
--- java/net/natInetAddressPosix.cc	(revision 118450)
+++ java/net/natInetAddressPosix.cc	(working copy)
@@ -1,304 +0,0 @@
-/* Copyright (C) 2003  Free Software Foundation
-
-   This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
-
-#include <config.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <string.h>
-#include <errno.h>
-
-#include <sys/param.h>
-#include <sys/types.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-
-#include <gcj/cni.h>
-#include <jvm.h>
-#include <java/net/InetAddress.h>
-#include <java/net/UnknownHostException.h>
-#include <java/lang/SecurityException.h>
-
-#if defined(HAVE_UNAME) && ! defined(HAVE_GETHOSTNAME)
-#include <sys/utsname.h>
-#endif
-
-#ifndef HAVE_GETHOSTNAME_DECL
-extern "C" int gethostname (char *name, int namelen);
-#endif
-
-jbyteArray
-java::net::InetAddress::aton (jstring host)
-{
-  char *hostname;
-  char buf[100];
-  int len = JvGetStringUTFLength(host);
-  if (len < 100)
-    hostname = buf;
-  else
-    hostname = (char*) _Jv_AllocBytes (len+1);
-  JvGetStringUTFRegion (host, 0, host->length(), hostname);
-  buf[len] = '\0';
-  char* bytes = NULL;
-  int blen = 0;
-#ifdef HAVE_INET_ATON
-  struct in_addr laddr;
-  if (inet_aton (hostname, &laddr))
-    {
-      bytes = (char*) &laddr;
-      blen = 4;
-    }
-#elif defined(HAVE_INET_ADDR)
-#if ! HAVE_IN_ADDR_T
-  typedef jint in_addr_t;
-#endif
-  in_addr_t laddr = inet_addr (hostname);
-  if (laddr != (in_addr_t)(-1))
-    {
-      bytes = (char*) &laddr;
-      blen = 4;
-    }
-#endif
-#if defined (HAVE_INET_PTON) && defined (HAVE_INET6)
-  char inet6_addr[16];
-  if (len != 0 && inet_pton (AF_INET6, hostname, inet6_addr) > 0)
-    {
-      bytes = inet6_addr;
-      blen = 16;
-    }
-#endif
-  if (blen == 0)
-    return NULL;
-  jbyteArray result = JvNewByteArray (blen);
-  memcpy (elements (result), bytes, blen);
-  return result;
-}
-
-jint
-java::net::InetAddress::getFamily (jbyteArray bytes)
-{
-  int len = bytes->length;
-  if (len == 4)
-    return AF_INET;
-#ifdef HAVE_INET6
-  else if (len == 16)
-    return AF_INET6;
-#endif /* HAVE_INET6 */
-  else
-    JvFail ("unrecognized size");
-}
-
-
-JArray<java::net::InetAddress*> *
-java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
-				jboolean all)
-{
-  struct hostent *hptr = NULL;
-#if defined (HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYADDR_R)
-  struct hostent hent_r;
-#if HAVE_STRUCT_HOSTENT_DATA
-  struct hostent_data fixed_buffer, *buffer_r = &fixed_buffer;
-#else
-#if defined (__GLIBC__) 
-  // FIXME: in glibc, gethostbyname_r returns NETDB_INTERNAL to herr and
-  // ERANGE to errno if the buffer size is too small, rather than what is 
-  // expected here. We work around this by setting a bigger buffer size and 
-  // hoping that it is big enough.
-  char fixed_buffer[1024];
-#else
-  char fixed_buffer[200];
-#endif
-  char *buffer_r = fixed_buffer;
-  int size_r = sizeof (fixed_buffer);
-#endif
-#endif
-
-  if (host != NULL)
-    {
-      char *hostname;
-      char buf[100];
-      int len = JvGetStringUTFLength(host);
-      if (len < 100)
-	hostname = buf;
-      else
-	hostname = (char*) _Jv_AllocBytes (len+1);
-      JvGetStringUTFRegion (host, 0, host->length(), hostname);
-      buf[len] = '\0';
-#ifdef HAVE_GETHOSTBYNAME_R
-      while (true)
-	{
-	  int ok;
-#if HAVE_STRUCT_HOSTENT_DATA
-	  ok = ! gethostbyname_r (hostname, &hent_r, buffer_r);
-#else
-	  int herr = 0;
-#ifdef GETHOSTBYNAME_R_RETURNS_INT
-	  ok = ! gethostbyname_r (hostname, &hent_r, buffer_r, size_r,
-				  &hptr, &herr);
-#else
-	  hptr = gethostbyname_r (hostname, &hent_r, buffer_r, size_r, &herr);
-	  ok = hptr != NULL;
-#endif /* GETHOSTNAME_R_RETURNS_INT */
-	  if (! ok && herr == ERANGE)
-	    {
-	      size_r *= 2;
-	      buffer_r = (char *) _Jv_AllocBytes (size_r);
-	    }
-	  else
-#endif /* HAVE_STRUCT_HOSTENT_DATA */
-	    break;
-	}
-#else
-      // FIXME: this is insufficient if some other piece of code calls
-      // this gethostbyname.
-      JvSynchronize sync (java::net::InetAddress::loopbackAddress);
-      hptr = gethostbyname (hostname);
-#endif /* HAVE_GETHOSTBYNAME_R */
-    }
-  else
-    {
-      jbyteArray bytes = iaddr->addr;
-      char *chars = (char*) elements (bytes);
-      int len = bytes->length;
-      int type;
-      char *val;
-      if (len == 4)
-	{
-	  val = chars;
-	  type = iaddr->family = AF_INET;
-	}
-#ifdef HAVE_INET6
-      else if (len == 16)
-	{
-	  val = (char *) &chars;
-	  type = iaddr->family = AF_INET6;
-	}
-#endif /* HAVE_INET6 */
-      else
-	JvFail ("unrecognized size");
-
-#ifdef HAVE_GETHOSTBYADDR_R
-      while (true)
-	{
-	  int ok;
-#if HAVE_STRUCT_HOSTENT_DATA
-	  ok = ! gethostbyaddr_r (val, len, type, &hent_r, buffer_r);
-#else
-	  int herr = 0;
-#ifdef GETHOSTBYADDR_R_RETURNS_INT
-	  ok = ! gethostbyaddr_r (val, len, type, &hent_r,
-				  buffer_r, size_r, &hptr, &herr);
-#else
-	  hptr = gethostbyaddr_r (val, len, type, &hent_r,
-				  buffer_r, size_r, &herr);
-	  ok = hptr != NULL;
-#endif /* GETHOSTBYADDR_R_RETURNS_INT */
-	  if (! ok && herr == ERANGE)
-	    {
-	      size_r *= 2;
-	      buffer_r = (char *) _Jv_AllocBytes (size_r);
-	    }
-	  else 
-#endif /* HAVE_STRUCT_HOSTENT_DATA */
-	    break;
-	}
-#else /* HAVE_GETHOSTBYADDR_R */
-      // FIXME: this is insufficient if some other piece of code calls
-      // this gethostbyaddr.
-      JvSynchronize sync (java::net::InetAddress::loopbackAddress);
-      hptr = gethostbyaddr (val, len, type);
-#endif /* HAVE_GETHOSTBYADDR_R */
-    }
-  if (hptr != NULL)
-    {
-      if (!all)
-        host = JvNewStringUTF (hptr->h_name);
-    }
-  if (hptr == NULL)
-    {
-      if (iaddr != NULL && iaddr->addr != NULL)
-	{
-	  iaddr->hostName = iaddr->getHostAddress();
-	  return NULL;
-	}
-      else
-	throw new java::net::UnknownHostException(host);
-    }
-  int count;
-  if (all)
-    {
-      char** ptr = hptr->h_addr_list;
-      count = 0;
-      while (*ptr++)  count++;
-    }
-  else
-    count = 1;
-  JArray<java::net::InetAddress*> *result;
-  java::net::InetAddress** iaddrs;
-  if (all)
-    {
-      result = java::net::InetAddress::allocArray (count);
-      iaddrs = elements (result);
-    }
-  else
-    {
-      result = NULL;
-      iaddrs = &iaddr;
-    }
-
-  for (int i = 0;  i < count;  i++)
-    {
-      if (iaddrs[i] == NULL)
-	iaddrs[i] = new java::net::InetAddress (NULL, NULL);
-      if (iaddrs[i]->hostName == NULL)
-        iaddrs[i]->hostName = host;
-      if (iaddrs[i]->addr == NULL)
-	{
-	  char *bytes = hptr->h_addr_list[i];
-	  iaddrs[i]->addr = JvNewByteArray (hptr->h_length);
-	  iaddrs[i]->family = getFamily (iaddrs[i]->addr);
-	  memcpy (elements (iaddrs[i]->addr), bytes, hptr->h_length);
-	}
-    }
-  return result;
-}
-
-jstring
-java::net::InetAddress::getLocalHostname ()
-{
-  char *chars;
-#ifdef HAVE_GETHOSTNAME
-  char buffer[MAXHOSTNAMELEN];
-  if (gethostname (buffer, MAXHOSTNAMELEN))
-    return NULL;
-  chars = buffer;
-#elif HAVE_UNAME
-  struct utsname stuff;
-  if (uname (&stuff) != 0)
-    return NULL;
-  chars = stuff.nodename;
-#else
-  return NULL;
-#endif
-  // It is admittedly non-optimal to convert the hostname to Unicode
-  // only to convert it back in getByName, but simplicity wins.  Note
-  // that unless there is a SecurityManager, we only get called once
-  // anyway, thanks to the InetAddress.localhost cache.
-  return JvNewStringUTF (chars);
-}
Index: java/net/natInetAddressWin32.cc
===================================================================
--- java/net/natInetAddressWin32.cc	(revision 118450)
+++ java/net/natInetAddressWin32.cc	(working copy)
@@ -1,168 +0,0 @@
-/* Copyright (C) 2003  Free Software Foundation
-
-   This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
-details.  */
-
-#include <config.h>
-#include <platform.h>
-
-#undef STRICT
-
-#include <java/net/InetAddress.h>
-#include <java/net/UnknownHostException.h>
-#include <java/lang/SecurityException.h>
-
-jbyteArray
-java::net::InetAddress::aton (jstring host)
-{
-  JV_TEMP_UTF_STRING (hostname, host);
-  char* bytes = NULL;
-  int blen = 0;
-  unsigned long laddr = inet_addr (hostname);
-  if (laddr != INADDR_NONE)
-    {
-      bytes = (char*) &laddr;
-      blen = 4;
-    }
-  if (blen == 0)
-    return NULL;
-  jbyteArray result = JvNewByteArray (blen);
-  memcpy (elements (result), bytes, blen);
-  return result;
-}
-
-jint
-java::net::InetAddress::getFamily (jbyteArray bytes)
-{
-  int len = bytes->length;
-  if (len == 4)
-    return AF_INET;
-#ifdef HAVE_INET6
-  else if (len == 16)
-    return AF_INET6;
-#endif /* HAVE_INET6 */
-  else
-    JvFail ("unrecognized size");
-}
-
-
-JArray<java::net::InetAddress*> *
-java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
-        jboolean all)
-{
-  struct hostent *hptr = NULL;
-  if (host != NULL)
-    {
-      JV_TEMP_UTF_STRING (hostname, host);
-
-      // FIXME: this is insufficient if some other piece of code calls
-      // this gethostbyname.
-      JvSynchronize sync (java::net::InetAddress::loopbackAddress);
-      hptr = gethostbyname (hostname);
-    }
-  else
-    {
-      jbyteArray bytes = iaddr->addr;
-      char *chars = (char*) elements (bytes);
-      int len = bytes->length;
-      int type;
-      char *val;
-      if (len == 4)
-        {
-          val = chars;
-          type = iaddr->family = AF_INET;
-        }
-#ifdef HAVE_INET6
-      else if (len == 16)
-      {
-        val = (char *) &chars;
-        type = iaddr->family = AF_INET6;
-      }
-#endif /* HAVE_INET6 */
-      else
-        JvFail ("unrecognized size");
-
-      // FIXME: this is insufficient if some other piece of code calls
-      // this gethostbyaddr.
-      JvSynchronize sync (java::net::InetAddress::loopbackAddress);
-      hptr = gethostbyaddr (val, len, type);
-    }
-  if (hptr != NULL)
-    {
-      if (!all)
-        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 (iaddr != NULL && iaddr->addr != NULL)
-        {
-          iaddr->hostName = iaddr->getHostAddress();
-          return NULL;
-        }
-      else
-        throw new java::net::UnknownHostException(host);
-    }
-
-  int count;
-  if (all)
-    {
-      char** ptr = hptr->h_addr_list;
-      count = 0;
-      while (*ptr++)  count++;
-    }
-  else
-    count = 1;
-
-  JArray<java::net::InetAddress*> *result;
-  java::net::InetAddress** iaddrs;
-  if (all)
-    {
-      result = java::net::InetAddress::allocArray (count);
-      iaddrs = elements (result);
-    }
-  else
-    {
-      result = NULL;
-      iaddrs = &iaddr;
-    }
-
-  for (int i = 0;  i < count;  i++)
-    {
-      if (iaddrs[i] == NULL)
-        iaddrs[i] = new java::net::InetAddress (NULL, NULL);
-      if (iaddrs[i]->hostName == NULL)
-        iaddrs[i]->hostName = host;
-      if (iaddrs[i]->addr == NULL)
-        {
-          char *bytes = hptr->h_addr_list[i];
-          iaddrs[i]->addr = JvNewByteArray (hptr->h_length);
-          iaddrs[i]->family = getFamily (iaddrs[i]->addr);
-          memcpy (elements (iaddrs[i]->addr), bytes, hptr->h_length);
-        }
-    }
-    
-  return result;
-}
-
-jstring
-java::net::InetAddress::getLocalHostname ()
-{
-  char buffer[400];
-  if (gethostname (buffer, sizeof(buffer)))
-    return NULL;
-  // It is admittedly non-optimal to convert the hostname to Unicode
-  // only to convert it back in getByName, but simplicity wins.  Note
-  // that unless there is a SecurityManager, we only get called once
-  // anyway, thanks to the InetAddress.localhost cache.
-  return JvNewStringUTF (buffer);
-}
Index: java/net/VMInetAddress.java
===================================================================
--- java/net/VMInetAddress.java	(revision 118450)
+++ java/net/VMInetAddress.java	(working copy)
@@ -58,18 +58,12 @@
    *
    * @return The local hostname.
    */
-  public static String getLocalHostname()
-  {
-    return InetAddress.getLocalHostname();
-  }
+  public static native String getLocalHostname();
 
   /**
    * Returns the value of the special address INADDR_ANY
    */
-  public static byte[] lookupInaddrAny() throws UnknownHostException
-  {
-    return new byte[] {0, 0, 0, 0};
-  }
+  public static native byte[] lookupInaddrAny() throws UnknownHostException;
 
   /**
    * This method returns the hostname for a given IP address.  It will
@@ -81,26 +75,15 @@
    *
    * @exception UnknownHostException If the reverse lookup fails
    */
-  public static String getHostByAddr(byte[] ip) throws UnknownHostException
-  {
-    InetAddress addr = InetAddress.getByAddress(ip);
-    InetAddress.lookup(null, addr, false);
-    return addr.getHostName();
-  }
+  public 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.
    */
-  public static byte[][] getHostByName(String hostname)
-    throws UnknownHostException
-  {
-    InetAddress[] iaddrs = InetAddress.lookup(hostname, null, true);
-    byte[][] addrs = new byte[iaddrs.length][];
-    for (int i = 0; i < iaddrs.length; i++)
-      addrs[i] = iaddrs[i].getAddress();
-    return addrs;
-  }
+  public static native byte[][] getHostByName(String hostname)
+    throws UnknownHostException;
 
   /**
    * Return the IP address represented by a literal address.
@@ -110,8 +93,5 @@
    *
    * @return The IP address as a byte array
    */
-  public static byte[] aton(String address)
-  {
-    return InetAddress.aton(address);
-  }
+  public static native byte[] aton(String address);
 }
Index: java/net/natVMInetAddressNoNet.cc
===================================================================
--- java/net/natVMInetAddressNoNet.cc	(revision 0)
+++ java/net/natVMInetAddressNoNet.cc	(revision 0)
@@ -0,0 +1,40 @@
+/* Copyright (C) 2003, 2006  Free Software Foundation
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+#include <config.h>
+#include <stddef.h>
+
+jstring
+java::net::VMInetAddress::getLocalHostname ()
+{
+  return NULL;
+}
+
+jbyteArray
+java::net::VMInetAddress::lookupInaddrAny ()
+{
+  return NULL;
+}
+
+jstring
+java::net::VMInetAddress::getHostByAddr (jbyteArray addr)
+{
+  return NULL;
+}
+
+JArray<jbyteArray> *
+java::net::VMInetAddress::getHostByName (jstring host)
+{
+  return NULL;
+}
+
+jbyteArray
+java::net::VMInetAddress::aton (jstring host)
+{
+  return NULL;
+}
Index: java/net/natVMInetAddressPosix.cc
===================================================================
--- java/net/natVMInetAddressPosix.cc	(revision 0)
+++ java/net/natVMInetAddressPosix.cc	(revision 0)
@@ -0,0 +1,289 @@
+/* Copyright (C) 2003, 2006  Free Software Foundation
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+#include <config.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <string.h>
+#include <errno.h>
+
+#include <sys/param.h>
+#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
+#include <gcj/cni.h>
+#include <jvm.h>
+#include <java/net/VMInetAddress.h>
+#include <java/net/UnknownHostException.h>
+
+#if defined(HAVE_UNAME) && ! defined(HAVE_GETHOSTNAME)
+#include <sys/utsname.h>
+#endif
+
+#ifndef HAVE_GETHOSTNAME_DECL
+extern "C" int gethostname (char *name, int namelen);
+#endif
+
+jstring
+java::net::VMInetAddress::getLocalHostname ()
+{
+  char *chars;
+#ifdef HAVE_GETHOSTNAME
+  char buffer[MAXHOSTNAMELEN];
+  if (gethostname (buffer, MAXHOSTNAMELEN))
+    return NULL;
+  chars = buffer;
+#elif HAVE_UNAME
+  struct utsname stuff;
+  if (uname (&stuff) != 0)
+    return NULL;
+  chars = stuff.nodename;
+#else
+  return NULL;
+#endif
+  // It is admittedly non-optimal to convert the hostname to Unicode
+  // only to convert it back in getByName, but simplicity wins.
+  return JvNewStringUTF (chars);
+}
+
+jbyteArray
+java::net::VMInetAddress::lookupInaddrAny ()
+{
+#if ! HAVE_IN_ADDR_T
+  typedef jint in_addr_t;
+#endif
+  in_addr_t laddr = INADDR_ANY;
+  char *bytes = (char *) &laddr;
+  int blen = sizeof (laddr);
+  jbyteArray result = JvNewByteArray (blen);
+  memcpy (elements (result), bytes, blen);
+  return result;
+}
+
+jstring
+java::net::VMInetAddress::getHostByAddr (jbyteArray addr)
+{
+  struct hostent *hptr = NULL;
+#ifdef HAVE_GETHOSTBYADDR_R
+  struct hostent hent_r;
+#if HAVE_STRUCT_HOSTENT_DATA
+  struct hostent_data fixed_buffer, *buffer_r = &fixed_buffer;
+#else
+#ifdef __GLIBC__
+  // FIXME: in glibc, gethostbyname_r returns NETDB_INTERNAL to herr and
+  // ERANGE to errno if the buffer size is too small, rather than what is 
+  // expected here. We work around this by setting a bigger buffer size and 
+  // hoping that it is big enough.
+  char fixed_buffer[1024];
+#else
+  char fixed_buffer[200];
+#endif /* __GLIBC__ */
+  char *buffer_r = fixed_buffer;
+  int size_r = sizeof (fixed_buffer);
+#endif /* HAVE_STRUCT_HOSTENT_DATA */
+#endif /* HAVE_GETHOSTBYADDR_R */
+
+  char *bytes = (char*) elements (addr);
+  int len = addr->length;
+  int type;
+  char *val;
+  if (len == 4)
+    {
+      val = bytes;
+      type = AF_INET;
+    }
+#ifdef HAVE_INET6
+  else if (len == 16)
+    {
+      val = (char *) &bytes;
+      type = AF_INET6;
+    }
+#endif /* HAVE_INET6 */
+  else
+    JvFail ("unrecognized size");
+
+#ifdef HAVE_GETHOSTBYADDR_R
+  while (true)
+    {
+      int ok;
+#if HAVE_STRUCT_HOSTENT_DATA
+      ok = ! gethostbyaddr_r (val, len, type, &hent_r, buffer_r);
+#else
+      int herr = 0;
+#ifdef GETHOSTBYADDR_R_RETURNS_INT
+      ok = ! gethostbyaddr_r (val, len, type, &hent_r,
+			      buffer_r, size_r, &hptr, &herr);
+#else
+      hptr = gethostbyaddr_r (val, len, type, &hent_r,
+			      buffer_r, size_r, &herr);
+      ok = hptr != NULL;
+#endif /* GETHOSTBYADDR_R_RETURNS_INT */
+      if (! ok && herr == ERANGE)
+	{
+	  size_r *= 2;
+	  buffer_r = (char *) _Jv_AllocBytes (size_r);
+	}
+      else 
+#endif /* HAVE_STRUCT_HOSTENT_DATA */
+	break;
+    }
+#else /* HAVE_GETHOSTBYADDR_R */
+  // FIXME: this is insufficient if some other piece of code calls
+  // this gethostbyaddr.
+  JvSynchronize sync (&java::net::VMInetAddress::class$);
+  hptr = gethostbyaddr (val, len, type);
+#endif /* HAVE_GETHOSTBYADDR_R */
+
+  if (hptr == NULL)
+    throw new java::net::UnknownHostException ();
+
+  return JvNewStringUTF (hptr->h_name);
+}
+
+JArray<jbyteArray> *
+java::net::VMInetAddress::getHostByName (jstring host)
+{
+  struct hostent *hptr = NULL;
+#ifdef HAVE_GETHOSTBYNAME_R
+  struct hostent hent_r;
+#if HAVE_STRUCT_HOSTENT_DATA
+  struct hostent_data fixed_buffer, *buffer_r = &fixed_buffer;
+#else
+#ifdef __GLIBC__
+  // FIXME: in glibc, gethostbyname_r returns NETDB_INTERNAL to herr and
+  // ERANGE to errno if the buffer size is too small, rather than what is 
+  // expected here. We work around this by setting a bigger buffer size and 
+  // hoping that it is big enough.
+  char fixed_buffer[1024];
+#else
+  char fixed_buffer[200];
+#endif /* __GLIBC__ */
+  char *buffer_r = fixed_buffer;
+  int size_r = sizeof (fixed_buffer);
+#endif /* HAVE_STRUCT_HOSTENT_DATA */
+#endif /* HAVE_GETHOSTBYNAME_R */
+
+  char *hostname;
+  char buf[100];
+  int len = JvGetStringUTFLength(host);
+  if (len < 100)
+    hostname = buf;
+  else
+    hostname = (char *) _Jv_AllocBytes (len + 1);
+  JvGetStringUTFRegion (host, 0, host->length(), hostname);
+  buf[len] = '\0';
+#ifdef HAVE_GETHOSTBYNAME_R
+  while (true)
+    {
+      int ok;
+#if HAVE_STRUCT_HOSTENT_DATA
+      ok = ! gethostbyname_r (hostname, &hent_r, buffer_r);
+#else
+      int herr = 0;
+#ifdef GETHOSTBYNAME_R_RETURNS_INT
+      ok = ! gethostbyname_r (hostname, &hent_r, buffer_r, size_r,
+			      &hptr, &herr);
+#else
+      hptr = gethostbyname_r (hostname, &hent_r, buffer_r, size_r, &herr);
+      ok = hptr != NULL;
+#endif /* GETHOSTNAME_R_RETURNS_INT */
+      if (! ok && herr == ERANGE)
+	{
+	  size_r *= 2;
+	  buffer_r = (char *) _Jv_AllocBytes (size_r);
+	}
+      else
+#endif /* HAVE_STRUCT_HOSTENT_DATA */
+	break;
+    }
+#else /* HAVE_GETHOSTBYNAME_R */
+  // FIXME: this is insufficient if some other piece of code calls
+  // this gethostbyname.
+  JvSynchronize sync (&java::net::VMInetAddress::class$);
+  hptr = gethostbyname (hostname);
+#endif /* HAVE_GETHOSTBYNAME_R */
+
+  if (hptr == NULL)
+    throw new java::net::UnknownHostException (host);
+
+  int count = 0;
+  char ** ptr = hptr->h_addr_list;
+  while (*ptr++)  count++;
+
+  JArray<jbyteArray> *result =
+    (JArray<jbyteArray> *) _Jv_NewObjectArray (
+      count, _Jv_GetArrayClass(JvPrimClass(byte), NULL), NULL);
+  jbyteArray* addrs = elements (result);
+
+  for (int i = 0; i < count; i++)
+    {
+      addrs[i] = JvNewByteArray (hptr->h_length);
+      memcpy (elements (addrs[i]), hptr->h_addr_list[i], hptr->h_length);
+    }
+  return result;
+}
+
+jbyteArray
+java::net::VMInetAddress::aton (jstring host)
+{
+  char *hostname;
+  char buf[100];
+  int len = JvGetStringUTFLength(host);
+  if (len < 100)
+    hostname = buf;
+  else
+    hostname = (char *) _Jv_AllocBytes (len+1);
+  JvGetStringUTFRegion (host, 0, host->length(), hostname);
+  buf[len] = '\0';
+  char *bytes = NULL;
+  int blen = 0;
+#ifdef HAVE_INET_ATON
+  struct in_addr laddr;
+  if (inet_aton (hostname, &laddr))
+    {
+      bytes = (char *) &laddr;
+      blen = 4;
+    }
+#elif defined(HAVE_INET_ADDR)
+#if ! HAVE_IN_ADDR_T
+  typedef jint in_addr_t;
+#endif
+  in_addr_t laddr = inet_addr (hostname);
+  if (laddr != (in_addr_t)(-1))
+    {
+      bytes = (char *) &laddr;
+      blen = 4;
+    }
+#endif
+#if defined (HAVE_INET_PTON) && defined (HAVE_INET6)
+  char inet6_addr[16];
+  if (len != 0 && inet_pton (AF_INET6, hostname, inet6_addr) > 0)
+    {
+      bytes = inet6_addr;
+      blen = 16;
+    }
+#endif
+  if (blen == 0)
+    return NULL;
+  jbyteArray result = JvNewByteArray (blen);
+  memcpy (elements (result), bytes, blen);
+  return result;
+}
Index: java/net/natVMInetAddressWin32.cc
===================================================================
--- java/net/natVMInetAddressWin32.cc	(revision 0)
+++ java/net/natVMInetAddressWin32.cc	(revision 0)
@@ -0,0 +1,121 @@
+/* Copyright (C) 2003, 2006 Free Software Foundation
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+#include <config.h>
+#include <platform.h>
+
+#undef STRICT
+
+#include <java/net/VMInetAddress.h>
+#include <java/net/UnknownHostException.h>
+
+jstring
+java::net::VMInetAddress::getLocalHostname ()
+{
+  char buffer[400];
+  if (gethostname (buffer, sizeof(buffer)))
+    return NULL;
+  // It is admittedly non-optimal to convert the hostname to Unicode
+  // only to convert it back in getByName, but simplicity wins.
+  return JvNewStringUTF (buffer);
+}
+
+jbyteArray
+java::net::VMInetAddress::lookupInaddrAny ()
+{
+  unsigned long laddr = INADDR_ANY;
+  char *bytes = (char *) &laddr;
+  int blen = sizeof (laddr);
+  jbyteArray result = JvNewByteArray (blen);
+  memcpy (elements (result), bytes, blen);
+  return result;
+}
+
+jstring
+java::net::VMInetAddress::getHostByAddr (jbyteArray addr)
+{
+  struct hostent *hptr = NULL;
+  char *bytes = (char*) elements (addr);
+  int len = addr->length;
+  int type;
+  char *val;
+  if (len == 4)
+    {
+      val = bytes;
+      type = AF_INET;
+    }
+#ifdef HAVE_INET6
+  else if (len == 16)
+    {
+      val = (char *) &bytes;
+      type = AF_INET6;
+    }
+#endif /* HAVE_INET6 */
+  else
+    JvFail ("unrecognized size");
+
+  // FIXME: this is insufficient if some other piece of code calls
+  // this gethostbyaddr.
+  JvSynchronize sync (&java::net::VMInetAddress::class$);
+  hptr = gethostbyaddr (val, len, type);
+
+  if (hptr == NULL)
+    throw new java::net::UnknownHostException ();
+
+  return JvNewStringUTF (hptr->h_name);
+}
+
+JArray<jbyteArray> *
+java::net::VMInetAddress::getHostByName (jstring host)
+{
+  struct hostent *hptr = NULL;
+  JV_TEMP_UTF_STRING (hostname, host);
+
+  // FIXME: this is insufficient if some other piece of code calls
+  // this gethostbyname.
+  JvSynchronize sync (&java::net::VMInetAddress::class$);
+  hptr = gethostbyname (hostname);
+
+  if (hptr == NULL)
+    throw new java::net::UnknownHostException (host);
+
+  int count = 0;
+  char ** ptr = hptr->h_addr_list;
+  while (*ptr++)  count++;
+
+  JArray<jbyteArray> *result =
+    (JArray<jbyteArray> *) _Jv_NewObjectArray (
+      count, _Jv_GetArrayClass(JvPrimClass(byte), NULL), NULL);
+  jbyteArray* addrs = elements (result);
+
+  for (int i = 0; i < count; i++)
+    {
+      addrs[i] = JvNewByteArray (hptr->h_length);
+      memcpy (elements (addrs[i]), hptr->h_addr_list[i], hptr->h_length);
+    }
+  return result;
+}
+
+jbyteArray
+java::net::VMInetAddress::aton (jstring host)
+{
+  JV_TEMP_UTF_STRING (hostname, host);
+  char* bytes = NULL;
+  int blen = 0;
+  unsigned long laddr = inet_addr (hostname);
+  if (laddr != INADDR_NONE)
+    {
+      bytes = (char *) &laddr;
+      blen = 4;
+    }
+  if (blen == 0)
+    return NULL;
+  jbyteArray result = JvNewByteArray (blen);
+  memcpy (elements (result), bytes, blen);
+  return result;
+}
Index: Makefile.am
===================================================================
--- Makefile.am	(revision 118450)
+++ Makefile.am	(working copy)
@@ -858,7 +858,7 @@
 java/lang/reflect/natField.cc \
 java/lang/reflect/natMethod.cc \
 java/net/natVMNetworkInterface.cc \
-java/net/natInetAddress.cc \
+java/net/natVMInetAddress.cc \
 java/net/natURLClassLoader.cc \
 java/nio/channels/natVMChannels.cc \
 java/nio/natDirectByteBufferImpl.cc \
Index: configure.ac
===================================================================
--- configure.ac	(revision 118450)
+++ configure.ac	(working copy)
@@ -663,9 +663,9 @@
 AC_CONFIG_LINKS(java/lang/ConcreteProcess.java:java/lang/${PLATFORM}Process.java)
 AC_CONFIG_LINKS(java/lang/natConcreteProcess.cc:java/lang/nat${PLATFORM}Process.cc)
 
-# Likewise for natInetAddress.cc and natVMNetworkInterface.cc.
+# Likewise for natVMInetAddress.cc and natVMNetworkInterface.cc.
 test -d java/net || mkdir java/net
-AC_CONFIG_LINKS(java/net/natInetAddress.cc:java/net/natInetAddress${PLATFORMNET}.cc)
+AC_CONFIG_LINKS(java/net/natVMInetAddress.cc:java/net/natVMInetAddress${PLATFORMNET}.cc)
 AC_CONFIG_LINKS(java/net/natVMNetworkInterface.cc:java/net/natVMNetworkInterface${PLATFORMNET}.cc)
 
 # Likewise for natPlainSocketImpl.cc and natPlainDatagramSocketImpl.cc.
Index: sources.am
===================================================================
--- sources.am	(revision 118450)
+++ sources.am	(working copy)
@@ -5229,7 +5229,7 @@
 classpath/java/net/HttpURLConnection.java \
 classpath/java/net/Inet4Address.java \
 classpath/java/net/Inet6Address.java \
-java/net/InetAddress.java \
+classpath/java/net/InetAddress.java \
 classpath/java/net/InetSocketAddress.java \
 classpath/java/net/JarURLConnection.java \
 classpath/java/net/MalformedURLException.java \
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 118450)
+++ Makefile.in	(working copy)
@@ -95,7 +95,7 @@
 	$(top_builddir)/gcj/libgcj-config.h
 CONFIG_CLEAN_FILES = libgcj.pc libgcj.spec libgcj-test.spec \
 	scripts/jar java/io/natFile.cc java/lang/ConcreteProcess.java \
-	java/lang/natConcreteProcess.cc java/net/natInetAddress.cc \
+	java/lang/natConcreteProcess.cc java/net/natVMInetAddress.cc \
 	java/net/natVMNetworkInterface.cc \
 	gnu/java/net/natPlainSocketImpl.cc \
 	gnu/java/net/natPlainDatagramSocketImpl.cc \
@@ -300,7 +300,7 @@
 	java/lang/ref/natReference.cc java/lang/reflect/natArray.cc \
 	java/lang/reflect/natConstructor.cc \
 	java/lang/reflect/natField.cc java/lang/reflect/natMethod.cc \
-	java/net/natVMNetworkInterface.cc java/net/natInetAddress.cc \
+	java/net/natVMNetworkInterface.cc java/net/natVMInetAddress.cc \
 	java/net/natURLClassLoader.cc \
 	java/nio/channels/natVMChannels.cc \
 	java/nio/natDirectByteBufferImpl.cc \
@@ -348,7 +348,7 @@
 	java/lang/ref/natReference.lo java/lang/reflect/natArray.lo \
 	java/lang/reflect/natConstructor.lo \
 	java/lang/reflect/natField.lo java/lang/reflect/natMethod.lo \
-	java/net/natVMNetworkInterface.lo java/net/natInetAddress.lo \
+	java/net/natVMNetworkInterface.lo java/net/natVMInetAddress.lo \
 	java/net/natURLClassLoader.lo \
 	java/nio/channels/natVMChannels.lo \
 	java/nio/natDirectByteBufferImpl.lo \
@@ -4130,7 +4130,7 @@
 classpath/java/net/HttpURLConnection.java \
 classpath/java/net/Inet4Address.java \
 classpath/java/net/Inet6Address.java \
-java/net/InetAddress.java \
+classpath/java/net/InetAddress.java \
 classpath/java/net/InetSocketAddress.java \
 classpath/java/net/JarURLConnection.java \
 classpath/java/net/MalformedURLException.java \
@@ -7431,7 +7431,7 @@
 java/lang/reflect/natField.cc \
 java/lang/reflect/natMethod.cc \
 java/net/natVMNetworkInterface.cc \
-java/net/natInetAddress.cc \
+java/net/natVMInetAddress.cc \
 java/net/natURLClassLoader.cc \
 java/nio/channels/natVMChannels.cc \
 java/nio/natDirectByteBufferImpl.cc \
@@ -7929,7 +7929,7 @@
 	@: > java/net/$(DEPDIR)/$(am__dirstamp)
 java/net/natVMNetworkInterface.lo: java/net/$(am__dirstamp) \
 	java/net/$(DEPDIR)/$(am__dirstamp)
-java/net/natInetAddress.lo: java/net/$(am__dirstamp) \
+java/net/natVMInetAddress.lo: java/net/$(am__dirstamp) \
 	java/net/$(DEPDIR)/$(am__dirstamp)
 java/net/natURLClassLoader.lo: java/net/$(am__dirstamp) \
 	java/net/$(DEPDIR)/$(am__dirstamp)
@@ -8261,10 +8261,10 @@
 	-rm -f java/lang/reflect/natField.lo
 	-rm -f java/lang/reflect/natMethod.$(OBJEXT)
 	-rm -f java/lang/reflect/natMethod.lo
-	-rm -f java/net/natInetAddress.$(OBJEXT)
-	-rm -f java/net/natInetAddress.lo
 	-rm -f java/net/natURLClassLoader.$(OBJEXT)
 	-rm -f java/net/natURLClassLoader.lo
+	-rm -f java/net/natVMInetAddress.$(OBJEXT)
+	-rm -f java/net/natVMInetAddress.lo
 	-rm -f java/net/natVMNetworkInterface.$(OBJEXT)
 	-rm -f java/net/natVMNetworkInterface.lo
 	-rm -f java/nio/channels/natVMChannels.$(OBJEXT)
@@ -8392,8 +8392,8 @@
 @AMDEP_TRUE@@am__include@ @am__quote@java/lang/reflect/$(DEPDIR)/natConstructor.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/lang/reflect/$(DEPDIR)/natField.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/lang/reflect/$(DEPDIR)/natMethod.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natInetAddress.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natURLClassLoader.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natVMInetAddress.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/net/$(DEPDIR)/natVMNetworkInterface.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/nio/$(DEPDIR)/natDirectByteBufferImpl.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@java/nio/channels/$(DEPDIR)/natVMChannels.Plo@am__quote@
Index: configure
===================================================================
--- configure	(revision 118450)
+++ configure	(working copy)
@@ -7486,9 +7486,9 @@
           ac_config_links="$ac_config_links java/lang/natConcreteProcess.cc:java/lang/nat${PLATFORM}Process.cc"
 
 
-# Likewise for natInetAddress.cc and natVMNetworkInterface.cc.
+# Likewise for natVMInetAddress.cc and natVMNetworkInterface.cc.
 test -d java/net || mkdir java/net
-          ac_config_links="$ac_config_links java/net/natInetAddress.cc:java/net/natInetAddress${PLATFORMNET}.cc"
+          ac_config_links="$ac_config_links java/net/natVMInetAddress.cc:java/net/natVMInetAddress${PLATFORMNET}.cc"
 
           ac_config_links="$ac_config_links java/net/natVMNetworkInterface.cc:java/net/natVMNetworkInterface${PLATFORMNET}.cc"
 
@@ -17479,7 +17479,7 @@
   "java/io/natFile.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/io/natFile.cc:java/io/natFile${FILE-${PLATFORM}}.cc" ;;
   "java/lang/ConcreteProcess.java" ) CONFIG_LINKS="$CONFIG_LINKS java/lang/ConcreteProcess.java:java/lang/${PLATFORM}Process.java" ;;
   "java/lang/natConcreteProcess.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/lang/natConcreteProcess.cc:java/lang/nat${PLATFORM}Process.cc" ;;
-  "java/net/natInetAddress.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/net/natInetAddress.cc:java/net/natInetAddress${PLATFORMNET}.cc" ;;
+  "java/net/natVMInetAddress.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/net/natVMInetAddress.cc:java/net/natVMInetAddress${PLATFORMNET}.cc" ;;
   "java/net/natVMNetworkInterface.cc" ) CONFIG_LINKS="$CONFIG_LINKS java/net/natVMNetworkInterface.cc:java/net/natVMNetworkInterface${PLATFORMNET}.cc" ;;
   "gnu/java/net/natPlainSocketImpl.cc" ) CONFIG_LINKS="$CONFIG_LINKS gnu/java/net/natPlainSocketImpl.cc:gnu/java/net/natPlainSocketImpl${PLATFORMNET}.cc" ;;
   "gnu/java/net/natPlainDatagramSocketImpl.cc" ) CONFIG_LINKS="$CONFIG_LINKS gnu/java/net/natPlainDatagramSocketImpl.cc:gnu/java/net/natPlainDatagramSocketImpl${PLATFORMNET}.cc" ;;
Index: java/net/natVMNetworkInterfaceWin32.cc
===================================================================
--- java/net/natVMNetworkInterfaceWin32.cc	(revision 118450)
+++ java/net/natVMNetworkInterfaceWin32.cc	(working copy)
@@ -12,7 +12,7 @@
 #undef STRICT
 
 #include <java/net/NetworkInterface.h>
-#include <java/net/Inet4Address.h>
+#include <java/net/InetAddress.h>
 #include <java/net/SocketException.h>
 #include <java/net/VMNetworkInterface.h>
 #include <java/util/Vector.h>
@@ -83,8 +83,8 @@
         }
 
       jstring if_name = _Jv_Win32NewString (szName);
-      java::net::Inet4Address* address =
-        new java::net::Inet4Address (baddr, JvNewStringLatin1 (""));
+      java::net::InetAddress* address =
+        java::net::InetAddress::getByAddress (baddr);
       pjstrName[i] = if_name;
       ppAddress[i] = address;
     }
Index: gnu/java/net/natPlainSocketImplWin32.cc
===================================================================
--- gnu/java/net/natPlainSocketImplWin32.cc	(revision 118450)
+++ gnu/java/net/natPlainSocketImplWin32.cc	(working copy)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003, 2004, 2005 Free Software Foundation
+/* Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
 
    This file is part of libgcj.
 
@@ -328,7 +328,7 @@
 
   s->native_fd = (jint) hSocket;
   s->localport = localport;
-  s->address = new ::java::net::InetAddress (raddr, NULL);
+  s->address = ::java::net::InetAddress::getByAddress (raddr);
   s->port = rport;
   return;
 
@@ -735,7 +735,7 @@
           else
             throw new ::java::net::SocketException
               (JvNewStringUTF ("invalid family"));
-          localAddress = new ::java::net::InetAddress (laddr, NULL);
+          localAddress = ::java::net::InetAddress::getByAddress (laddr);
         }
 
       return localAddress;
Index: gnu/java/net/natPlainDatagramSocketImplWin32.cc
===================================================================
--- gnu/java/net/natPlainDatagramSocketImplWin32.cc	(revision 118450)
+++ gnu/java/net/natPlainDatagramSocketImplWin32.cc	(working copy)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003  Free Software Foundation
+/* Copyright (C) 2003, 2006 Free Software Foundation
 
    This file is part of libgcj.
 
@@ -238,7 +238,7 @@
   else
     throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
 
-  p->setAddress (new ::java::net::InetAddress (raddr, NULL));
+  p->setAddress (::java::net::InetAddress::getByAddress (raddr));
   p->setPort (rport);
   p->length = (jint) retlen;
   return rport;
@@ -360,7 +360,7 @@
   else
     throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
 
-  p->setAddress (new ::java::net::InetAddress (raddr, NULL));
+  p->setAddress (::java::net::InetAddress::getByAddress (raddr));
   p->setPort (rport);
   p->length = (jint) retlen;
   return;
@@ -656,7 +656,7 @@
       else
         throw new ::java::net::SocketException (
             JvNewStringUTF ("invalid family"));
-      localAddress = new ::java::net::InetAddress (laddr, NULL);
+      localAddress = ::java::net::InetAddress::getByAddress (laddr);
     }
   return localAddress;
   break;
Index: classpath/java/net/Inet4Address.java
===================================================================
--- classpath/java/net/Inet4Address.java	(revision 118450)
+++ classpath/java/net/Inet4Address.java	(working copy)
@@ -59,14 +59,14 @@
   /**
    * The address family of these addresses (used for serialization).
    */
-  private static final int FAMILY = 2; // AF_INET
+  private static final int AF_INET = 2;
 
   /**
    * Inet4Address objects are serialized as InetAddress objects.
    */
   private Object writeReplace() throws ObjectStreamException
   {
-    return new InetAddress(addr, hostName, FAMILY);
+    return new InetAddress(addr, hostName, AF_INET);
   }
   
   /**
@@ -79,7 +79,7 @@
    */
   Inet4Address(byte[] addr, String host)
   {
-    super(addr, host, FAMILY);
+    super(addr, host, AF_INET);
   }
 
   /**
Index: classpath/java/net/Inet6Address.java
===================================================================
--- classpath/java/net/Inet6Address.java	(revision 118450)
+++ classpath/java/net/Inet6Address.java	(working copy)
@@ -95,7 +95,7 @@
   /**
    * The address family of these addresses (used for serialization).
    */
-  private static final int FAMILY = 10; // AF_INET6
+  private static final int AF_INET6 = 10;
 
   /**
    * Create an Inet6Address object
@@ -105,7 +105,7 @@
    */
   Inet6Address(byte[] addr, String host)
   {
-    super(addr, host, FAMILY);
+    super(addr, host, AF_INET6);
     // Super constructor clones the addr.  Get a reference to the clone.
     this.ipaddress = this.addr;
     ifname = null;

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: FYI: InetAddress merge
  2006-11-03 10:23     ` FYI: " Gary Benson
@ 2006-11-03 11:48       ` Anthony Green
  2006-11-03 11:56         ` Gary Benson
  0 siblings, 1 reply; 9+ messages in thread
From: Anthony Green @ 2006-11-03 11:48 UTC (permalink / raw)
  To: Gary Benson; +Cc: java-patches

On Fri, 2006-11-03 at 10:23 +0000, Gary Benson wrote:
> Hi all,
> 
> This commit completes the merge of InetAddress with Classpath that I
> started in September.

Great.  Are you going to make a patch for 4.1 branch we use in FC6?

Thanks,

AG


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: FYI: InetAddress merge
  2006-11-03 11:48       ` Anthony Green
@ 2006-11-03 11:56         ` Gary Benson
  0 siblings, 0 replies; 9+ messages in thread
From: Gary Benson @ 2006-11-03 11:56 UTC (permalink / raw)
  To: java-patches

Anthony Green wrote:
> On Fri, 2006-11-03 at 10:23 +0000, Gary Benson wrote:
> > Hi all,
> > 
> > This commit completes the merge of InetAddress with Classpath that
> > I started in September.
> 
> Great.  Are you going to make a patch for 4.1 branch we use in FC6?

Yeah, I'm on it.  It's required to fix that Azureus bug (or, well,
not strictly, but it makes the fix neater).  Almost all the stuff I
did recently on Inet*Address and SocketPermission was to fix issues
I uncovered while fixing that damn Azureus bug ;)

Cheers,
Gary

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2006-11-03 11:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-20  8:52 FYI: Partial InetAddress merge Gary Benson
2006-09-20 12:15 ` RFT: The remainder of the " Gary Benson
2006-09-23 14:20   ` Mohan Embar
2006-09-24  2:29     ` Mohan Embar
2006-09-25 12:21       ` Gary Benson
2006-09-25 14:58   ` RFC: Updated " Gary Benson
2006-11-03 10:23     ` FYI: " Gary Benson
2006-11-03 11:48       ` Anthony Green
2006-11-03 11:56         ` Gary Benson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).