Initial load
diff --git a/test/java/net/InetAddress/B4762344.java b/test/java/net/InetAddress/B4762344.java
new file mode 100644
index 0000000..45ad267
--- /dev/null
+++ b/test/java/net/InetAddress/B4762344.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4762344
+ * @summary 2nd nameservice provider is non functional
+ * @build B4762344 SimpleNameService Simple1NameServiceDescriptor Simple2NameServiceDescriptor
+ * @run main/othervm -Dsun.net.spi.nameservice.provider.1=simple1,sun -Dsun.net.spi.nameservice.provider.2=simple2,sun B4762344
+ */
+
+import java.net.*;
+import java.util.*;
+
+
+public class B4762344 {
+    private static String[][] hostnames = new String[][] {
+            // both providers know this host, but with different address
+            new String[] {"blade", "10.0.0.1"},
+            // provider1 knwos this host
+            new String[] {"blade.domain1", "10.0.0.2"},
+            // provider2 knows this host
+            new String[] {"blade.domain2", "20.0.0.2"}
+        };
+    private static String[][] hostaddrs = new String[][] {
+            new String[] {"10.0.0.1", "blade"},
+            new String[] {"10.0.0.2", "blade.domain1"},
+            new String[] {"20.0.0.2", "blade.domain2"}
+        };
+
+    public static void main(String[] args) throws Exception {
+        for (int i = 0; i < hostnames.length; i++) {
+            doLookup(hostnames[i][0], hostnames[i][1]);
+        }
+        for (int i = 0; i < hostaddrs.length; i++) {
+            doReverseLookup(hostaddrs[i][0], hostaddrs[i][1]);
+        }
+    }
+
+    private static void doLookup(String host, String addr) throws Exception {
+        String res = InetAddress.getByName(host).getHostAddress();
+        if (!res.equals(addr)) {
+            throw new RuntimeException("Test failed: wrong address for host " + host);
+        }
+    }
+
+    private static void doReverseLookup(String addr, String host) throws Exception {
+        StringTokenizer tokenizer = new StringTokenizer(addr, ".");
+        byte addrs[] = new byte[4];
+        for (int i = 0; i < 4; i++) {
+            addrs[i] = (byte)Integer.parseInt(tokenizer.nextToken());
+        }
+        String res = InetAddress.getByAddress(addrs).getHostName();
+        if (!res.equals(host)) {
+            throw new RuntimeException("Test failed: wrong host name for address " + addr);
+        }
+    }
+}
diff --git a/test/java/net/InetAddress/B5087907.java b/test/java/net/InetAddress/B5087907.java
new file mode 100644
index 0000000..2835978
--- /dev/null
+++ b/test/java/net/InetAddress/B5087907.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 5087907
+ * @summary  InetAddress.getAllByName does not obey setting of java.net.preferIPv6Addresses
+ * @run main/othervm -Djava.net.preferIPv6Addresses=false B5087907
+ * @run main/othervm -Djava.net.preferIPv6Addresses=true B5087907
+ * @run main/othervm B5087907
+ */
+
+import java.net.*;
+
+public class B5087907 {
+
+    public static void main(String args[]) {
+        InetAddress lh = null;
+        InetAddress addrs[] = null;
+        try {
+            lh = InetAddress.getByName("localhost");
+            addrs = InetAddress.getAllByName("localhost");
+        } catch (UnknownHostException e) {
+            System.out.println ("Cant lookup localhost. cant run test");
+            return;
+        }
+
+        boolean hasIPv4Address = false;
+        boolean hasIPv6Address = false;
+        for (InetAddress addr: addrs) {
+            if (addr instanceof Inet4Address) {
+                hasIPv4Address = true;
+            }
+            if (addr instanceof Inet6Address) {
+                hasIPv6Address = true;
+            }
+            if (hasIPv4Address && hasIPv6Address) {
+                break;
+            }
+        }
+
+        String prop = System.getProperty("java.net.preferIPv6Addresses");
+        boolean preferIPv6Addresses = (prop == null) ? false : prop.equals("true");
+
+        System.out.println("java.net.preferIPv6Addresses: " + preferIPv6Addresses);
+        System.out.println("localhost resolves to:");
+        for (InetAddress addr: addrs) {
+            System.out.println("  " + addr);
+        }
+        System.out.println("InetAddres.getByName returned: " + lh);
+
+        boolean failed = false;
+        if (preferIPv6Addresses && hasIPv6Address) {
+            if (!(lh instanceof Inet6Address)) failed = true;
+        }
+        if (!preferIPv6Addresses && hasIPv4Address) {
+            if (!(lh instanceof Inet4Address)) failed = true;
+        }
+        if (failed) {
+            throw new RuntimeException("Test failed!");
+        }
+    }
+
+}
diff --git a/test/java/net/InetAddress/B6246242.java b/test/java/net/InetAddress/B6246242.java
new file mode 100644
index 0000000..b3c786e
--- /dev/null
+++ b/test/java/net/InetAddress/B6246242.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6246242
+ * @summary UnknownHostException contains wrong error message
+ */
+
+import java.net.*;
+
+public class B6246242 {
+    public static void main(String[] args) {
+        InetAddress a;
+        try {
+            a = InetAddress.getByName("foo.bar");
+        } catch (UnknownHostException e) {
+            String s = e.getMessage();
+            if (s.indexOf("foo.bar: foo.bar") >= 0)
+                throw new RuntimeException("UnknownHostException has wrong message: " + s);
+        }
+    }
+}
diff --git a/test/java/net/InetAddress/B6296240.java b/test/java/net/InetAddress/B6296240.java
new file mode 100644
index 0000000..2b66c78
--- /dev/null
+++ b/test/java/net/InetAddress/B6296240.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6296240
+ * @summary  REGRESSION: InetAddress.getAllByName accepts badly formed address
+ */
+
+import java.net.*;
+import java.util.BitSet;
+
+public class B6296240 {
+    public static void main(String[] args) {
+        String[] malformedIPv4s = {"192.168.1.220..."};
+        BitSet expectedExceptions = new BitSet(malformedIPv4s.length);
+        expectedExceptions.clear();
+
+        for (int i = 0; i < malformedIPv4s.length; i++) {
+            try {
+                InetAddress.getAllByName(malformedIPv4s[i]);
+            } catch (UnknownHostException e) {
+                expectedExceptions.set(i);
+            }
+        }
+
+        for (int i = 0; i < malformedIPv4s.length; i++) {
+            if (!expectedExceptions.get(i)) {
+                System.out.println("getAllByName(\"" + malformedIPv4s[i] + "\") should throw exception.");
+            }
+        }
+
+        if (expectedExceptions.cardinality() != malformedIPv4s.length) {
+            throw new RuntimeException("Failed: some expected UnknownHostExceptions are not thrown.");
+        }
+    }
+}
diff --git a/test/java/net/InetAddress/BadDottedIPAddress.java b/test/java/net/InetAddress/BadDottedIPAddress.java
new file mode 100644
index 0000000..db3b838
--- /dev/null
+++ b/test/java/net/InetAddress/BadDottedIPAddress.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2001-2002 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4321350
+ * @bug 4516522
+ * @summary Check that InetAddress.getByName() throws UHE with dotted
+ *          IP address with octets out of range (Windows specific bug)
+ *         or when bad IPv6 Litterals addresses are passed.
+ */
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class BadDottedIPAddress {
+
+    public static void main(String args[]) throws Exception {
+
+        String host = "999.999.999.999";
+
+        boolean exc_thrown = false;
+        try {
+            InetAddress ia = InetAddress.getByName(host);
+        } catch (UnknownHostException e) {
+            exc_thrown = true;
+        }
+
+        if (!exc_thrown) {
+            throw new Exception("UnknownHostException was not thrown for: "
+                + host);
+        }
+
+        host = "[]";
+        exc_thrown = false;
+        try {
+            InetAddress ia = InetAddress.getByName(host);
+        } catch (UnknownHostException e) {
+            exc_thrown = true;
+        } catch (Exception e) {
+        }
+
+        if (!exc_thrown) {
+            throw new Exception("UnknownHostException was not thrown for: "
+                + host);
+        }
+
+        host = "[127.0.0.1]";
+        exc_thrown = false;
+        try {
+            InetAddress ia = InetAddress.getByName(host);
+        } catch (UnknownHostException e) {
+            exc_thrown = true;
+        } catch (Exception e) {
+        }
+
+        if (!exc_thrown) {
+            throw new Exception("UnknownHostException was not thrown for: "
+                + host);
+        }
+
+        host = "[localhost]";
+        exc_thrown = false;
+        try {
+            InetAddress ia = InetAddress.getByName(host);
+        } catch (UnknownHostException e) {
+            exc_thrown = true;
+        } catch (Exception e) {
+        }
+
+        if (!exc_thrown) {
+            throw new Exception("UnknownHostException was not thrown for: "
+                + host);
+        }
+    }
+}
diff --git a/test/java/net/InetAddress/CachedUnknownHostName.java b/test/java/net/InetAddress/CachedUnknownHostName.java
new file mode 100644
index 0000000..b1e118a
--- /dev/null
+++ b/test/java/net/InetAddress/CachedUnknownHostName.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 1999 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @author Gary Ellison
+ * @bug 4208282
+ * @summary java.net.InetAddress.getByName caching unknown host lookups
+ */
+
+import java.net.InetAddress;
+
+public class CachedUnknownHostName {
+  public static void main(String argv[]) throws Exception {
+    String hostname = new String("bogusHostName");
+
+    try {
+      InetAddress.getByName(hostname);
+      System.err.println("Missing java.net.UnknownHostException for host " +
+                         hostname);
+      throw new Exception("Missing java.net.UnknownHostException");
+    } catch(java.net.UnknownHostException e) {
+      // this one is anticipated
+      System.out.println("Caught expected exception:" + e);
+    }
+
+    try {
+      InetAddress.getByName(hostname);
+      System.err.println("Missing java.net.UnknownHostException for host " +
+                         hostname);
+      throw new Exception("Missing java.net.UnknownHostException");
+    } catch(java.net.UnknownHostException e) {
+      // this is the one that was not firing off.
+      System.out.println("Caught expected exception:" + e);
+    }
+
+    System.out.println("Passed. OKAY");
+  }
+}
diff --git a/test/java/net/InetAddress/CheckJNI.java b/test/java/net/InetAddress/CheckJNI.java
new file mode 100644
index 0000000..03cd1b7
--- /dev/null
+++ b/test/java/net/InetAddress/CheckJNI.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2003-2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @bug 4889870 4890033
+   @summary java -Xcheck:jni failing in net code on Solaris / [Datagram]Socket.getLocalAddress() failure
+   @run main/othervm -Xcheck:jni CheckJNI
+*/
+
+import java.net.*;
+import java.util.*;
+
+public class CheckJNI {
+    static Socket s;
+    static ServerSocket server;
+    static DatagramSocket dg1, dg2;
+
+    public static void main (String[] args) throws Exception {
+        /* try to invoke as much java.net native code as possible */
+
+        System.out.println ("Testing IPv4 Socket/ServerSocket");
+        server = new ServerSocket (0);
+        s = new Socket ("127.0.0.1", server.getLocalPort());
+        s.close();
+        server.close();
+
+        System.out.println ("Testing IPv4 DatagramSocket");
+        dg1 = new DatagramSocket (0, InetAddress.getByName ("127.0.0.1"));
+        dg2 = new DatagramSocket (0, InetAddress.getByName ("127.0.0.1"));
+        testDatagrams (dg1, dg2);
+
+        /* Use NetworkInterface to find link local IPv6 addrs to test */
+
+        Enumeration ifs = NetworkInterface.getNetworkInterfaces();
+        server = new ServerSocket (0);
+
+        while (ifs.hasMoreElements()) {
+            NetworkInterface nif = (NetworkInterface)ifs.nextElement();
+            Enumeration addrs = nif.getInetAddresses();
+            while (addrs.hasMoreElements()) {
+                InetAddress addr = (InetAddress) addrs.nextElement();
+                if (addr instanceof Inet6Address) {
+                    Inet6Address ia6 = (Inet6Address) addr;
+                    if (ia6.isLinkLocalAddress()) {
+                        System.out.println ("Testing IPv6 Socket");
+                        s = new Socket (ia6, server.getLocalPort());
+                        s.close();
+
+                        System.out.println ("Testing IPv6 DatagramSocket");
+                        dg1 = new DatagramSocket (0, ia6);
+                        dg2 = new DatagramSocket (0, ia6);
+                        testDatagrams (dg1, dg2);
+                    }
+                }
+            }
+        }
+        server.close();
+        System.out.println ("OK");
+    }
+
+    static void testDatagrams (DatagramSocket s1, DatagramSocket s2) throws Exception {
+        DatagramPacket p1 = new DatagramPacket (
+                "hello world".getBytes(),
+                0, "hello world".length(), s2.getLocalAddress(),
+                s2.getLocalPort()
+        );
+
+        DatagramPacket p2 = new DatagramPacket (new byte[128], 128);
+        s1.send (p1);
+        s2.receive (p2);
+        s1.close ();
+        s2.close ();
+    }
+}
diff --git a/test/java/net/InetAddress/GetLocalHostWithSM.java b/test/java/net/InetAddress/GetLocalHostWithSM.java
new file mode 100644
index 0000000..5928277
--- /dev/null
+++ b/test/java/net/InetAddress/GetLocalHostWithSM.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2002 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4531817
+ * @summary Inet[46]Address.localHost need doPrivileged
+ * @run main/othervm GetLocalHostWithSM
+ * files needed: GetLocalHostWithSM.java, MyPrincipal.java, and policy.file
+ */
+
+import java.net.*;
+
+import javax.security.auth.Subject;
+import java.security.Principal;
+import java.security.PrivilegedExceptionAction;
+import java.util.*;
+
+public class GetLocalHostWithSM {
+
+        public static void main(String[] args) throws Exception {
+
+            // try setting the local hostname
+            try {
+                System.setProperty("host.name", InetAddress.
+                                                getLocalHost().
+                                                getHostName());
+            } catch (UnknownHostException e) {
+                System.out.println("Cannot find the local hostname, " +
+                        "no nameserver entry found");
+            }
+            String policyFileName = System.getProperty("test.src", ".") +
+                          "/" + "policy.file";
+            System.setProperty("java.security.policy", policyFileName);
+            System.setSecurityManager(new SecurityManager());
+
+            InetAddress localHost1 = null;
+            InetAddress localHost2 = null;
+
+            localHost1 = InetAddress.getLocalHost();
+
+            Subject mySubject = new Subject();
+            MyPrincipal userPrincipal = new MyPrincipal("test");
+            mySubject.getPrincipals().add(userPrincipal);
+            localHost2 = (InetAddress)Subject.doAsPrivileged(mySubject,
+                                new MyAction(), null);
+
+            if (localHost1.equals(localHost2)) {
+                throw new RuntimeException("InetAddress.getLocalHost() test " +
+                                           " fails. localHost2 should be " +
+                                           " the real address instead of " +
+                                           " the loopback address."+localHost2);
+            }
+        }
+}
+
+
+class MyAction implements PrivilegedExceptionAction {
+
+    public Object run() throws Exception {
+        return InetAddress.getLocalHost();
+    }
+}
diff --git a/test/java/net/InetAddress/GetLoopbackAddress.java b/test/java/net/InetAddress/GetLoopbackAddress.java
new file mode 100644
index 0000000..6f29498
--- /dev/null
+++ b/test/java/net/InetAddress/GetLoopbackAddress.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6376404
+ * @summary InetAddress needs a getLoopbackAddress
+ */
+import java.net.*;
+
+public class GetLoopbackAddress
+{
+    static InetAddress IPv4Loopback;
+    static InetAddress IPv6Loopback;
+
+    static {
+        try {
+            IPv4Loopback = InetAddress.getByAddress(
+                new byte[] {0x7F,0x00,0x00,0x01});
+
+            IPv6Loopback = InetAddress.getByAddress(
+                new byte[] {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01});
+        } catch (UnknownHostException e) {
+        }
+    }
+
+    public static void main(String[] args) {
+        InetAddress addr = InetAddress.getLoopbackAddress();
+
+        if (!(addr.equals(IPv4Loopback) || addr.equals(IPv6Loopback)))
+            throw new RuntimeException("Failed: getLoopbackAddress" +
+                 " not returning a valid loopback address");
+
+        InetAddress addr2 = InetAddress.getLoopbackAddress();
+
+        if (addr != addr2)
+            throw new RuntimeException("Failed: getLoopbackAddress" +
+                " should return a reference to the same InetAddress loopback instance.");
+    }
+}
diff --git a/test/java/net/InetAddress/HashSpread.java b/test/java/net/InetAddress/HashSpread.java
new file mode 100644
index 0000000..610f3c4
--- /dev/null
+++ b/test/java/net/InetAddress/HashSpread.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2002 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4687909
+ * @summary Check Inet6Address.hashCode returns a reasonable spread of hash
+ *          codes.
+ */
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Random;
+
+public class HashSpread {
+
+    static Random r = new Random();
+
+    /**
+     * Generate and return a random IPv6 address.
+     */
+    static InetAddress randomIPv6Adress() {
+        StringBuffer sb = new StringBuffer();
+
+        for (int i=0; i<8; i++) {
+
+            if (i > 0)
+                sb.append(":");
+
+            for (int j=0; j<4; j++) {
+                int v = r.nextInt(16);
+                if (v < 10) {
+                    sb.append(Integer.toString(v));
+                } else {
+                    char c = (char) ('A' + v - 10);
+                    sb.append(c);
+                }
+            }
+        }
+
+        try {
+            return InetAddress.getByName(sb.toString());
+        } catch (UnknownHostException x) {
+            throw new Error("Internal error in test");
+        }
+    }
+
+    public static void main(String args[]) throws Exception {
+
+        int iterations = 10000;
+        if (args.length > 0) {
+            iterations = Integer.parseInt(args[0]);
+        }
+
+        int MIN_SHORT = (int)Short.MIN_VALUE;
+        int MAX_SHORT = (int)Short.MAX_VALUE;
+
+        /*
+         * Iterate through 10k hash codes and count the number
+         * in the MIN_SHORT-MAX_SHORT range.
+         */
+        int narrow = 0;
+        for (int i=0; i<iterations; i++) {
+            int hc = randomIPv6Adress().hashCode();
+            if (hc >= MIN_SHORT && hc <= MAX_SHORT) {
+                narrow++;
+            }
+        }
+
+        /*
+         * If >85% of hash codes in the range then fail.
+         */
+        double percent = (double)narrow / (double)iterations * 100.0;
+        if (percent > 85.0) {
+            throw new RuntimeException(percent + " of hash codes were in " +
+                MIN_SHORT + " to " + MAX_SHORT  + " range.");
+        }
+
+    }
+
+}
diff --git a/test/java/net/InetAddress/IPv4Formats.java b/test/java/net/InetAddress/IPv4Formats.java
new file mode 100644
index 0000000..11bb20a
--- /dev/null
+++ b/test/java/net/InetAddress/IPv4Formats.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2003-2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4866927
+ * @summary InetAddress.getByName behaves differently on windows
+ */
+import java.net.*;
+
+public class IPv4Formats {
+    public static void main(String[] args) {
+        InetAddress ad1, ad2;
+        String adds[][] = {
+            {"0", "0.0.0.0"},
+            {"126.1", "126.0.0.1"},
+            {"128.50.65534", "128.50.255.254"},
+            {"192.168.1.2", "192.168.1.2"},
+            {"hello.foo.bar", null},
+            {"1024.1.2.3", null},
+            {"128.14.66000", null }
+        };
+        for (int i = 0; i < adds.length; i++) {
+            if (adds[i][1] != null) {
+                try {
+                    ad1 = InetAddress.getByName(adds[i][0]);
+                    ad2 = InetAddress.getByName(adds[i][1]);
+                } catch (UnknownHostException ue) {
+                    throw new RuntimeException("Wrong conversion: " + adds[i][0] + " should be " + adds[i][1] + " But throws " + ue);
+                }
+                if (! ad1.equals(ad2))
+                    throw new RuntimeException("Wrong conversion: " + adds[i][0] + " should be " + adds[i][1] + " But is " + ad1);
+            } else {
+                try {
+                    ad1 = InetAddress.getByName(adds[i][0]);
+                    // should throw an UnknownHostException
+                    throw new RuntimeException(adds[i][0] + " should throw UnknownHostException!");
+                } catch (UnknownHostException e) {
+                    // This is what we expect!
+                }
+            }
+        }
+    }
+}
diff --git a/test/java/net/InetAddress/IsHostReachableBug.java b/test/java/net/InetAddress/IsHostReachableBug.java
new file mode 100644
index 0000000..b5341ed
--- /dev/null
+++ b/test/java/net/InetAddress/IsHostReachableBug.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2003 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4922568
+ * @run main/othervm -Djava.net.preferIPv4Stack=true IsHostReachableBug
+ * @summary  isReachable returns true for IPv6
+ */
+
+import java.net.*;
+import java.io.*;
+
+public class IsHostReachableBug {
+    public static void main(String[] args) throws Exception{
+                String hostName = "fec0::1:a00:20ff:feed:b08d";
+                BufferedReader in = null;
+                FileWriter fw = null;
+                String inString = " ";
+                if (args.length > 0)
+                        hostName = args[0];
+
+                InetAddress addr = InetAddress.getByName(hostName);
+                System.out.println("InetAddress is : " + addr);
+                System.out.println("Is InetAddress instance of Inet6Address ? "
++ (addr instanceof Inet6Address));
+                if (!addr.isReachable(10000)){
+                        System.out.println(hostName + " is not reachable");
+                }else {
+                        throw new RuntimeException ("IPv6 address should not be reachable");
+                }
+
+
+    }
+}
diff --git a/test/java/net/InetAddress/IsReachable.java b/test/java/net/InetAddress/IsReachable.java
new file mode 100644
index 0000000..0e42493
--- /dev/null
+++ b/test/java/net/InetAddress/IsReachable.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2003 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4639861
+ * @summary API to test reachability of a host
+ */
+import java.net.InetAddress;
+import java.io.IOException;
+import java.net.NetworkInterface;
+public class IsReachable {
+    public static void main(String[] args) {
+        try {
+            InetAddress addr = InetAddress.getByName("localhost");
+            if (!addr.isReachable(10000))
+                throw new RuntimeException("Localhost should always be reachable");
+            NetworkInterface inf = NetworkInterface.getByInetAddress(addr);
+            if (inf != null) {
+                if (!addr.isReachable(inf, 20, 10000))
+                throw new RuntimeException("Localhost should always be reachable");
+            }
+
+        } catch (IOException e) {
+            throw new RuntimeException("Unexpected exception:" + e);
+        }
+    }
+}
diff --git a/test/java/net/InetAddress/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor b/test/java/net/InetAddress/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor
new file mode 100644
index 0000000..efcf237
--- /dev/null
+++ b/test/java/net/InetAddress/META-INF/services/sun.net.spi.nameservice.NameServiceDescriptor
@@ -0,0 +1,2 @@
+Simple1NameServiceDescriptor
+Simple2NameServiceDescriptor
diff --git a/test/java/net/InetAddress/MyPrincipal.java b/test/java/net/InetAddress/MyPrincipal.java
new file mode 100644
index 0000000..d916de3
--- /dev/null
+++ b/test/java/net/InetAddress/MyPrincipal.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2002 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+import java.security.Principal;
+
+public class MyPrincipal implements Principal {
+    private String name;
+
+    public MyPrincipal(String name) {
+        if (name == null)
+            throw new NullPointerException("illegal null input");
+
+        this.name = name;
+    }
+    public String getName() {
+        return name;
+    }
+
+    public String toString() {
+        return("MyPrincipal:  " + name);
+    }
+
+    public boolean equals(Object o) {
+        if (o == null)
+            return false;
+
+        if (this == o)
+            return true;
+
+        if (!(o instanceof MyPrincipal))
+            return false;
+        MyPrincipal that = (MyPrincipal)o;
+
+        if (this.getName().equals(that.getName()))
+            return true;
+        return false;
+    }
+    public int hashCode() {
+        return name.hashCode();
+    }
+}
diff --git a/test/java/net/InetAddress/Simple1NameServiceDescriptor.java b/test/java/net/InetAddress/Simple1NameServiceDescriptor.java
new file mode 100644
index 0000000..cb77875
--- /dev/null
+++ b/test/java/net/InetAddress/Simple1NameServiceDescriptor.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ */
+
+import sun.net.spi.nameservice.*;
+
+
+public class Simple1NameServiceDescriptor implements NameServiceDescriptor {
+    public NameService createNameService() {
+        SimpleNameService ns = new SimpleNameService();
+
+        // both providers know this host, but the address is different
+        ns.put("blade", "10.0.0.1");
+        // only this provider knows this host
+        ns.put("blade.domain1", "10.0.0.2");
+
+        return ns;
+    }
+
+    public String getProviderName() {
+        return "sun";
+    }
+
+    public String getType() {
+        return "simple1";
+    }
+}
diff --git a/test/java/net/InetAddress/Simple2NameServiceDescriptor.java b/test/java/net/InetAddress/Simple2NameServiceDescriptor.java
new file mode 100644
index 0000000..2908cab
--- /dev/null
+++ b/test/java/net/InetAddress/Simple2NameServiceDescriptor.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ */
+
+import sun.net.spi.nameservice.*;
+
+
+public class Simple2NameServiceDescriptor implements NameServiceDescriptor {
+    public NameService createNameService() {
+        SimpleNameService ns = new SimpleNameService();
+        // both providers know this host, but the address of it is different
+        ns.put("blade", "20.0.0.1");
+        // only this provider knows this host
+        ns.put("blade.domain2", "20.0.0.2");
+
+        return ns;
+    }
+
+    public String getProviderName() {
+        return "sun";
+    }
+
+    public String getType() {
+        return "simple2";
+    }
+}
diff --git a/test/java/net/InetAddress/SimpleNameService.java b/test/java/net/InetAddress/SimpleNameService.java
new file mode 100644
index 0000000..58311f0
--- /dev/null
+++ b/test/java/net/InetAddress/SimpleNameService.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ */
+
+import java.net.*;
+import java.util.*;
+import sun.net.spi.nameservice.*;
+
+
+public class SimpleNameService implements NameService {
+    // host name <-> host addr mapping
+    private HashMap<String, String> hosts = new LinkedHashMap<String, String>();
+
+    public void put(String host, String addr) {
+        hosts.put(host, addr);
+    }
+
+    private static String addrToString(byte addr[]) {
+        return Byte.toString(addr[0]) + "." +
+               Byte.toString(addr[1]) + "." +
+               Byte.toString(addr[2]) + "." +
+               Byte.toString(addr[3]);
+    }
+
+    public SimpleNameService() {
+    }
+
+    public InetAddress[] lookupAllHostAddr(String host) throws UnknownHostException {
+        String addr = hosts.get(host);
+        if (addr == null) {
+            throw new UnknownHostException(host);
+        }
+
+        StringTokenizer tokenizer = new StringTokenizer(addr, ".");
+        byte addrs[] = new byte[4];
+        for (int i = 0; i < 4; i++) {
+            addrs[i] = (byte)Integer.parseInt(tokenizer.nextToken());
+        }
+        InetAddress[] ret = new InetAddress[1];
+        ret[0] = InetAddress.getByAddress(host, addrs);
+        return ret;
+    }
+
+    public String getHostByAddr(byte[] addr) throws UnknownHostException {
+        String addrString = addrToString(addr);
+        Iterator i = hosts.keySet().iterator();
+        while (i.hasNext()) {
+            String host = (String)i.next();
+            String value = (String)hosts.get(host);
+            if (value.equals(addrString)) {
+                return host;
+            }
+        }
+        throw new UnknownHostException();
+    }
+}
diff --git a/test/java/net/InetAddress/WhiteSpaceHostTest.java b/test/java/net/InetAddress/WhiteSpaceHostTest.java
new file mode 100644
index 0000000..08caa4f
--- /dev/null
+++ b/test/java/net/InetAddress/WhiteSpaceHostTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2000 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4361604
+ * @summary InetAddress.getByName on Solaris returns 0.0.0.0 for
+ *          hostname that start with white space.
+ */
+import java.net.*;
+import java.util.StringTokenizer;
+
+public class WhiteSpaceHostTest {
+
+    public static void main(String args[]) throws Exception {
+        String hosts = "        localhost;localhost; localhost;localhost1; localhost1; bogus.mil;\u0010localhost";
+
+        StringTokenizer tokenizer = new StringTokenizer(hosts, ";");
+        while (tokenizer.hasMoreTokens()) {
+            String hostname = tokenizer.nextToken();
+            InetAddress ia;
+            try {
+                ia = InetAddress.getByName(hostname);
+            } catch (UnknownHostException e) {
+                continue;
+            }
+            if (ia.isAnyLocalAddress()) {
+                throw new Exception("Bogus hostname lookup returned any local address");
+            }
+        }
+    }
+}
diff --git a/test/java/net/InetAddress/policy.file b/test/java/net/InetAddress/policy.file
new file mode 100644
index 0000000..449dba5
--- /dev/null
+++ b/test/java/net/InetAddress/policy.file
@@ -0,0 +1,10 @@
+grant {
+	permission javax.security.auth.AuthPermission "modifyPrincipals";
+	permission javax.security.auth.AuthPermission "doAsPrivileged";	
+	permission java.util.PropertyPermission "*", "read,write";
+};
+
+grant Principal MyPrincipal "test" { 
+	permission java.net.SocketPermission "${host.name}", "resolve";
+};
+
diff --git a/test/java/net/InetAddress/ptr/Lookup.java b/test/java/net/InetAddress/ptr/Lookup.java
new file mode 100644
index 0000000..66628ef
--- /dev/null
+++ b/test/java/net/InetAddress/ptr/Lookup.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2002 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ *
+ *
+ * Lookup/reverse lookup class for regression test 4773521 - see
+ * lookup.sh for details.
+ */
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class Lookup {
+    public static void main(String args[]) throws UnknownHostException {
+
+        // reverse lookup
+
+        if (args[0].equals("-q=PTR")) {
+            InetAddress ia = InetAddress.getByName(args[1]);
+            System.out.println(ia.getHostName());
+            return;
+        }
+
+        // lookup address
+
+        String addr;
+        if (args[0].equals("-q=A")) {
+            addr = args[1];
+        } else {
+            addr = args[0];
+        }
+        InetAddress ia = InetAddress.getByName(args[1]);
+        System.out.println(ia.getHostAddress());
+    }
+
+}
diff --git a/test/java/net/InetAddress/ptr/lookup.sh b/test/java/net/InetAddress/ptr/lookup.sh
new file mode 100644
index 0000000..c753f40
--- /dev/null
+++ b/test/java/net/InetAddress/ptr/lookup.sh
@@ -0,0 +1,72 @@
+#!/bin/sh
+
+#
+# Copyright 2002 Sun Microsystems, Inc.  All Rights Reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code 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
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+
+# @test
+# @bug 4773521
+# @build Lookup
+# @run shell lookup.sh
+# @summary Test that reverse lookups of IPv4 addresses work when IPv6
+#          is enabled. 
+
+# The host that we try to resolve
+
+HOST=javaweb.sfbay.sun.com
+
+CLASSPATH=${TESTCLASSES}
+export CLASSPATH
+JAVA="${TESTJAVA}/bin/java"
+
+
+# First check that host resolves to IPv4 address.
+
+echo ''
+ADDR=`$JAVA -Djava.net.preferIPv4Stack=true Lookup -q=A $HOST`
+if [ $? != 0 ]; then
+    echo "$HOST can't be resolved - test skipped."
+    exit 0
+fi
+echo "$HOST --> $ADDR"
+
+
+# IPv4 reverse lookup
+echo ''
+OUT1=`$JAVA -Djava.net.preferIPv4Stack=true Lookup -q=PTR $ADDR`
+echo "(IPv4) $ADDR --> $OUT1"
+
+
+# reverse lookup (default)
+echo ''
+OUT2=`$JAVA Lookup -q=PTR $ADDR`
+echo "(default) $ADDR --> $OUT2"
+
+
+# Compare results
+if [ "$OUT1" != "$OUT2" ]; then
+    echo ''
+    echo "Mistmatch between default and java.net.preferIPv4Stack=true results"
+    exit 1
+fi
+