Initial load
diff --git a/test/java/net/MulticastSocket/B6425815.java b/test/java/net/MulticastSocket/B6425815.java
new file mode 100644
index 0000000..b1ba842
--- /dev/null
+++ b/test/java/net/MulticastSocket/B6425815.java
@@ -0,0 +1,57 @@
+/*
+ * 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 6425815
+ *
+ * @summary java.net.MulticastSocket.setTimeToLive(255) reports 'Socket closed' (WinXP, IPv6)
+ *
+ */
+import java.net.*;
+import java.io.IOException;
+
+public class B6425815 {
+    public static void main(String[] args) throws Exception {
+        InetAddress ia;
+        MulticastSocket ms;
+
+        try {
+            ia = InetAddress.getByName("::1");
+            ms = new MulticastSocket(new InetSocketAddress(ia, 1234));
+        } catch (Exception e) {
+            // If this fails, it means the system doesn't have IPV6
+            // support, therefore this test shouldn't be run.
+            ia = null;
+            ms = null;
+        }
+        if (ms != null) {
+            ms.setTimeToLive(254);
+            if (ms.getTimeToLive() != 254) {
+                throw new RuntimeException("time to live is incorrect!");
+            }
+            ms.close();
+        }
+    }
+}
diff --git a/test/java/net/MulticastSocket/B6427403.java b/test/java/net/MulticastSocket/B6427403.java
new file mode 100644
index 0000000..5f701cc
--- /dev/null
+++ b/test/java/net/MulticastSocket/B6427403.java
@@ -0,0 +1,42 @@
+/*
+ * 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 6427403
+ *
+ * @summary java.net.MulticastSocket.joinGroup() reports 'socket closed'
+ *
+ */
+import java.net.*;
+import java.io.*;
+import java.util.*;
+public class B6427403 {
+    public static void main( String[] args ) throws IOException {
+        InetAddress lh = InetAddress.getLocalHost();
+        MulticastSocket ms = new MulticastSocket( new InetSocketAddress(lh, 0) );
+        ms.joinGroup( InetAddress.getByName("224.80.80.80") );
+        ms.close();
+    }
+}
diff --git a/test/java/net/MulticastSocket/JoinGroup.java b/test/java/net/MulticastSocket/JoinGroup.java
new file mode 100644
index 0000000..cf8fc0b
--- /dev/null
+++ b/test/java/net/MulticastSocket/JoinGroup.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 1998-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
+ * @bug 4091811 4148753
+ * @summary Test java.net.MulticastSocket joinGroup and leaveGroup
+ *
+ */
+
+import java.io.*;
+import java.net.*;
+
+
+public class JoinGroup {
+
+    public static void main(String args[]) throws Exception  {
+        MulticastSocket soc = null;
+        InetAddress sin = null;
+
+        soc = new MulticastSocket();
+        sin = InetAddress.getByName("224.80.80.80");
+        soc.joinGroup(sin);
+        soc.leaveGroup(sin);
+    }
+}
diff --git a/test/java/net/MulticastSocket/Leave.java b/test/java/net/MulticastSocket/Leave.java
new file mode 100644
index 0000000..ea46645
--- /dev/null
+++ b/test/java/net/MulticastSocket/Leave.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 1998 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 4102731
+ * @summary Test the java.net.multicastsocket.leave method
+ *
+ */
+
+import java.net.*;
+import java.io.*;
+
+public class Leave {
+
+    public static void main(String args[]) throws Exception {
+        MulticastSocket socket = null;
+        InetAddress mca = null;
+
+        mca = InetAddress.getByName("224.80.80.80");
+        socket = new MulticastSocket();
+        socket.joinGroup(mca);
+        socket.leaveGroup(mca);
+        socket.close();
+    }
+}
diff --git a/test/java/net/MulticastSocket/MulticastAddresses.java b/test/java/net/MulticastSocket/MulticastAddresses.java
new file mode 100644
index 0000000..4b3a8a5
--- /dev/null
+++ b/test/java/net/MulticastSocket/MulticastAddresses.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2001 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.
+ */
+
+/*
+ *
+ * @bug 4488458
+ * @summary Test that MutlicastSocket.joinGroup is working for
+ *          various multicast and non-multicast addresses.
+ */
+import java.net.*;
+import java.util.Enumeration;
+import java.io.IOException;
+
+public class MulticastAddresses {
+
+    public static void main(String args[]) throws Exception {
+
+        boolean ipv6_available = false;
+        NetworkInterface ni = null;
+
+        /*
+         * Examine the network interfaces and determine :-
+         *
+         * 1. If host has IPv6 support
+         * 2. Get reference to a non-loopback interface
+         */
+        Enumeration nifs = NetworkInterface.getNetworkInterfaces();
+        while (nifs.hasMoreElements()) {
+            NetworkInterface this_ni = (NetworkInterface)nifs.nextElement();
+
+            Enumeration addrs = this_ni.getInetAddresses();
+            while (addrs.hasMoreElements()) {
+                InetAddress addr = (InetAddress)addrs.nextElement();
+                if (addr instanceof Inet6Address) {
+                    ipv6_available = true;
+                }
+
+                if (!addr.isLoopbackAddress() && ni == null) {
+                    ni = this_ni;
+                }
+            }
+
+            if (ipv6_available) {
+                break;
+            }
+        }
+
+        int failures = 0;
+
+        String multicasts[] = {
+                "224.80.80.80",
+                "ff01::1",
+                "ff02::1234",
+                "ff05::a",
+                "ff0e::1234:a" };
+
+        String non_multicasts[] = {
+                "129.1.1.1",
+                "::1",
+                "::129.1.1.1",
+                "fe80::a00:20ff:fee5:bc02" };
+
+        MulticastSocket s = new MulticastSocket();
+
+        /* test valid multicast addresses */
+
+        for (int i=0; i<multicasts.length; i++) {
+            InetAddress ia = InetAddress.getByName(multicasts[i]);
+            if (ia instanceof Inet6Address && !ipv6_available) {
+                continue;
+            }
+
+            System.out.println("Test: " + ia);
+
+            try {
+
+                System.out.print("    joinGroup(InetAddress) ");
+                s.joinGroup(ia);
+                s.leaveGroup(ia);
+                System.out.println("    Passed.");
+
+                System.out.print("    joinGroup(InetAddress,NetworkInterface) ");
+                s.joinGroup(new InetSocketAddress(ia,0), ni);
+                s.leaveGroup(new InetSocketAddress(ia,0), ni);
+                System.out.println("    Passed.");
+            } catch (IOException e) {
+                failures++;
+                System.out.println("Failed: " + e.getMessage());
+            }
+
+        }
+
+        /* test non-multicast addresses */
+
+        for (int i=0; i<non_multicasts.length; i++) {
+            InetAddress ia = InetAddress.getByName(non_multicasts[i]);
+            if (ia instanceof Inet6Address && !ipv6_available) {
+                continue;
+            }
+
+            boolean failed = false;
+
+            System.out.println("Test: " + ia + " ");
+            try {
+                System.out.println("    joinGroup(InetAddress) ");
+                s.joinGroup(ia);
+
+                System.out.println("Failed!! -- incorrectly joined group");
+                failed = true;
+            } catch (IOException e) {
+                System.out.println("    Passed: " + e.getMessage());
+            }
+
+            if (failed) {
+                s.leaveGroup(ia);
+                failures++;
+            }
+        }
+
+        /* done */
+
+        s.close();
+
+        if (failures > 0) {
+            throw new Exception(failures + " test(s) failed - see log file.");
+        }
+    }
+
+}
diff --git a/test/java/net/MulticastSocket/MulticastTTL.java b/test/java/net/MulticastSocket/MulticastTTL.java
new file mode 100644
index 0000000..9ba9a41
--- /dev/null
+++ b/test/java/net/MulticastSocket/MulticastTTL.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 1998 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 4089415
+ * @summary Test MulticastSocket send for modification of ttl
+ *
+ */
+import java.io.*;
+import java.net.*;
+
+public class MulticastTTL {
+
+    public static void main(String args[]) throws Exception {
+        MulticastSocket soc = null;
+        DatagramPacket pac = null;
+        InetAddress sin = null;
+        byte [] array = new byte[65537];
+        int port = 0;
+        byte old_ttl = 0;
+        byte new_ttl = 64;
+        byte ttl = 0;
+
+        sin = InetAddress.getByName("224.80.80.80");
+        soc = new MulticastSocket();
+        port = soc.getLocalPort();
+        old_ttl = soc.getTTL();
+        pac = new DatagramPacket(array, array.length, sin, port);
+
+        try {
+            soc.send(pac, new_ttl);
+        } catch(java.io.IOException e) {
+            ttl = soc.getTTL();
+            soc.close();
+            if(ttl != old_ttl)
+                throw new RuntimeException("TTL ");
+        }
+        soc.close();
+    }
+}
diff --git a/test/java/net/MulticastSocket/NoLoopbackPackets.java b/test/java/net/MulticastSocket/NoLoopbackPackets.java
new file mode 100644
index 0000000..8341988
--- /dev/null
+++ b/test/java/net/MulticastSocket/NoLoopbackPackets.java
@@ -0,0 +1,146 @@
+/*
+ * 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 4742177
+ * @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
+ */
+import java.util.*;
+import java.net.*;
+
+
+public class NoLoopbackPackets {
+    private static int PORT = 9001;
+    private static String osname;
+
+    static boolean isWindows() {
+        if (osname == null)
+            osname = System.getProperty("os.name");
+        return osname.contains("Windows");
+    }
+
+    private static boolean hasIPv6() throws Exception {
+        List<NetworkInterface> nics = Collections.list(
+                                        NetworkInterface.getNetworkInterfaces());
+        for (NetworkInterface nic : nics) {
+            if (!nic.isLoopback()) {
+                List<InetAddress> addrs = Collections.list(nic.getInetAddresses());
+                for (InetAddress addr : addrs) {
+                    if (addr instanceof Inet6Address) {
+                        return true;
+                    }
+                }
+            }
+        }
+
+        return false;
+    }
+
+    public static void main(String[] args) throws Exception {
+        if (isWindows()) {
+            System.out.println("The test only run on non-Windows OS. Bye.");
+            return;
+        }
+
+        if (!hasIPv6()) {
+            System.out.println("No IPv6 available. Bye.");
+            return;
+        }
+
+        // we will send packets to three multicast groups :-
+        // 224.1.1.1, ::ffff:224.1.1.2, and ff02::1:1
+        //
+        List<SocketAddress> groups = new ArrayList<SocketAddress>();
+        groups.add(new InetSocketAddress(InetAddress.getByName("224.1.1.1"), PORT));
+        groups.add(new InetSocketAddress(InetAddress.getByName("::ffff:224.1.1.2"), PORT));
+        groups.add(new InetSocketAddress(InetAddress.getByName("ff02::1:1"), PORT));
+
+        Thread sender = new Thread(new Sender(groups));
+        sender.setDaemon(true); // we want sender to stop when main thread exits
+        sender.start();
+
+        // Now try to receive multicast packets. we should not see any of them
+        // since we disable loopback mode.
+        //
+        MulticastSocket msock = new MulticastSocket(PORT);
+        msock.setSoTimeout(5000);       // 5 seconds
+
+        byte[] buf = new byte[1024];
+        DatagramPacket packet = new DatagramPacket(buf, 0, buf.length);
+        List<SocketAddress> failedGroups = new ArrayList<SocketAddress>();
+        for (SocketAddress group : groups) {
+            msock.joinGroup(group, null);
+
+            try {
+                msock.receive(packet);
+
+                // it is an error if we receive something
+                failedGroups.add(group);
+            } catch (SocketTimeoutException e) {
+                // we expect this
+            }
+
+            msock.leaveGroup(group, null);
+        }
+
+        if (failedGroups.size() > 0) {
+            System.out.println("We should not receive anything from following groups, but we did:");
+            for (SocketAddress group : failedGroups)
+                System.out.println(group);
+            throw new RuntimeException("test failed.");
+        }
+    }
+}
+
+class Sender implements Runnable {
+    private List<SocketAddress> sendToGroups;
+
+    public Sender(List<SocketAddress> groups) {
+        sendToGroups = groups;
+    }
+
+    public void run() {
+        byte[] buf = "hello world".getBytes();
+        List<DatagramPacket> packets = new ArrayList<DatagramPacket>();
+
+        try {
+            for (SocketAddress group : sendToGroups) {
+                DatagramPacket packet = new DatagramPacket(buf, buf.length, group);
+                packets.add(packet);
+            }
+
+            MulticastSocket msock = new MulticastSocket();
+            msock.setLoopbackMode(true);    // disable loopback mode
+            for (;;) {
+                for (DatagramPacket packet : packets) {
+                    msock.send(packet);
+                }
+
+                Thread.currentThread().sleep(1000);     // 1 second
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+}
diff --git a/test/java/net/MulticastSocket/Reuse.java b/test/java/net/MulticastSocket/Reuse.java
new file mode 100644
index 0000000..325e76c
--- /dev/null
+++ b/test/java/net/MulticastSocket/Reuse.java
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+import java.net.MulticastSocket;
+import java.net.BindException;
+
+public class Reuse {
+    public static void main(String[] args) throws Exception {
+        MulticastSocket s1, s2;
+
+        try {
+            s1 = new MulticastSocket(4160);
+            s2 = new MulticastSocket(4160);
+            s1.close();
+            s2.close();
+        } catch (BindException e) {
+            throw new RuntimeException("MulticastSocket do no set SO_REUSEADDR");
+        }
+    }
+}
diff --git a/test/java/net/MulticastSocket/SetLoopbackMode.java b/test/java/net/MulticastSocket/SetLoopbackMode.java
new file mode 100644
index 0000000..4b16286
--- /dev/null
+++ b/test/java/net/MulticastSocket/SetLoopbackMode.java
@@ -0,0 +1,124 @@
+/*
+ * 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 4686717
+ * @summary Test MulticastSocket.setLoopbackMode
+ */
+import java.net.*;
+import java.io.IOException;
+
+public class SetLoopbackMode {
+
+    static final boolean FAILED = true;
+    static final boolean PASSED = false;
+
+    static boolean test(MulticastSocket mc, InetAddress grp) throws IOException {
+
+        boolean disabled = mc.getLoopbackMode();
+
+        if (disabled) {
+            System.out.println("Loopback mode is disabled.");
+        } else {
+            System.out.println("Loopback mode is enabled.");
+        }
+
+        byte b[] = "hello".getBytes();
+        DatagramPacket p = new DatagramPacket(b, b.length, grp,
+                                mc.getLocalPort());
+        mc.send(p);
+
+        boolean gotPacket = false;
+
+        mc.setSoTimeout(1000);
+        try {
+            b = new byte[16];
+            p = new DatagramPacket(b, b.length);
+            mc.receive(p);
+            gotPacket = true;
+
+            /* purge any additional copies of the packet */
+            for (;;) {
+                mc.receive(p);
+            }
+
+        } catch (SocketTimeoutException x) {
+        }
+
+        if (gotPacket && disabled) {
+            System.out.println("Packet received (unexpected as loopback is disabled)");
+            return FAILED;
+        }
+        if (!gotPacket && !disabled) {
+            System.out.println
+                ("Packet not received (packet excepted as loopback is enabled)");
+            return FAILED;
+        }
+
+        if (gotPacket && !disabled) {
+            System.out.println("Packet received - correct.");
+        } else {
+            System.out.println("Packet not received - correct.");
+        }
+
+        return PASSED;
+    }
+
+    public static void main (String args[]) throws Exception {
+        int failures = 0;
+
+        MulticastSocket mc = new MulticastSocket();
+        InetAddress grp = InetAddress.getByName("224.80.80.80");
+
+
+        /*
+         * If IPv6 is available then use IPv6 multicast group - needed
+         * to workaround Linux IPv6 bug whereby !IPV6_MULTICAST_LOOP
+         * doesn't prevent loopback of IPv4 multicast packets.
+         */
+        InetAddress lb = InetAddress.getByName("::1");
+        if (NetworkInterface.getByInetAddress(lb) != null) {
+            grp = InetAddress.getByName("ff01::1");
+        }
+
+        System.out.println("\nTest will use multicast group: " + grp);
+        mc.joinGroup(grp);
+
+        System.out.println("\n******************\n");
+
+        mc.setLoopbackMode(true);
+        if (test(mc, grp) == FAILED) failures++;
+
+        System.out.println("\n******************\n");
+
+        mc.setLoopbackMode(false);
+        if (test(mc, grp) == FAILED) failures++;
+
+        System.out.println("\n******************\n");
+
+        if (failures > 0) {
+            throw new RuntimeException("Test failed");
+        }
+    }
+}
diff --git a/test/java/net/MulticastSocket/SetOutgoingIf.java b/test/java/net/MulticastSocket/SetOutgoingIf.java
new file mode 100644
index 0000000..d24b03c
--- /dev/null
+++ b/test/java/net/MulticastSocket/SetOutgoingIf.java
@@ -0,0 +1,181 @@
+/*
+ * 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 4742177
+ * @summary Re-test IPv6 (and specifically MulticastSocket) with latest Linux & USAGI code
+ */
+import java.net.*;
+import java.util.concurrent.*;
+import java.util.*;
+
+
+public class SetOutgoingIf {
+    private static int PORT = 9001;
+    private static String osname;
+
+    static boolean isWindows() {
+        if (osname == null)
+            osname = System.getProperty("os.name");
+        return osname.contains("Windows");
+    }
+
+    private static boolean hasIPv6() throws Exception {
+        List<NetworkInterface> nics = Collections.list(
+                                        NetworkInterface.getNetworkInterfaces());
+        for (NetworkInterface nic : nics) {
+            List<InetAddress> addrs = Collections.list(nic.getInetAddresses());
+            for (InetAddress addr : addrs) {
+                if (addr instanceof Inet6Address)
+                    return true;
+            }
+        }
+
+        return false;
+    }
+
+    public static void main(String[] args) throws Exception {
+        if (isWindows()) {
+            System.out.println("The test only run on non-Windows OS. Bye.");
+            return;
+        }
+
+        if (!hasIPv6()) {
+            System.out.println("No IPv6 available. Bye.");
+            return;
+        }
+
+        // We need 2 or more network interfaces to run the test
+        //
+        List<NetworkInterface> nics = new ArrayList<NetworkInterface>();
+        for (NetworkInterface nic : Collections.list(NetworkInterface.getNetworkInterfaces())) {
+            if (!nic.isLoopback())
+                nics.add(nic);
+        }
+        if (nics.size() <= 1) {
+            System.out.println("Need 2 or more network interfaces to run. Bye.");
+            return;
+        }
+
+        // We will send packets to one ipv4, one ipv4-mapped, and one ipv6
+        // multicast group using each network interface :-
+        //      224.1.1.1        --|
+        //      ::ffff:224.1.1.2 -----> using network interface #1
+        //      ff02::1:1        --|
+        //      224.1.2.1        --|
+        //      ::ffff:224.1.2.2 -----> using network interface #2
+        //      ff02::1:2        --|
+        // and so on.
+        //
+        List<InetAddress> groups = new ArrayList<InetAddress>();
+        for (int i = 0; i < nics.size(); i++) {
+            InetAddress groupv4 = InetAddress.getByName("224.1." + (i+1) + ".1");
+            InetAddress groupv4mapped = InetAddress.getByName("::ffff:224.1." + (i+1) + ".2");
+            InetAddress groupv6 = InetAddress.getByName("ff02::1:" + (i+1));
+            groups.add(groupv4);
+            groups.add(groupv4mapped);
+            groups.add(groupv6);
+
+            // use a separated thread to send to those 3 groups
+            Thread sender = new Thread(new Sender(nics.get(i), groupv4, groupv4mapped, groupv6, PORT));
+            sender.setDaemon(true); // we want sender to stop when main thread exits
+            sender.start();
+        }
+
+        // try to receive on each group, then check if the packet comes
+        // from the expected network interface
+        //
+        byte[] buf = new byte[1024];
+        for (InetAddress group : groups) {
+        MulticastSocket mcastsock = new MulticastSocket(PORT);
+        mcastsock.setSoTimeout(5000);   // 5 second
+            DatagramPacket packet = new DatagramPacket(buf, 0, buf.length);
+
+            mcastsock.joinGroup(new InetSocketAddress(group, PORT), nics.get(groups.indexOf(group) / 3));
+
+            try {
+                mcastsock.receive(packet);
+            } catch (Exception e) {
+                // test failed if any exception
+                throw new RuntimeException(e);
+            }
+
+            // now check which network interface this packet comes from
+            NetworkInterface from = NetworkInterface.getByInetAddress(packet.getAddress());
+            NetworkInterface shouldbe = nics.get(groups.indexOf(group) / 3);
+            if (!from.equals(shouldbe)) {
+                System.out.println("Packets on group "
+                                    + group + " should come from "
+                                    + shouldbe.getName() + ", but came from "
+                                    + from.getName());
+                //throw new RuntimeException("Test failed.");
+            }
+
+            mcastsock.leaveGroup(new InetSocketAddress(group, PORT), nics.get(groups.indexOf(group) / 3));
+        }
+    }
+}
+
+class Sender implements Runnable {
+    private NetworkInterface nic;
+    private InetAddress group1;
+    private InetAddress group2;
+    private InetAddress group3;
+    private int port;
+
+    public Sender(NetworkInterface nic,
+                    InetAddress groupv4, InetAddress groupv4mapped, InetAddress groupv6,
+                    int port) {
+        this.nic = nic;
+        group1 = groupv4;
+        group2 = groupv4mapped;
+        group3 = groupv6;
+        this.port = port;
+    }
+
+    public void run() {
+        try {
+            MulticastSocket mcastsock = new MulticastSocket();
+            mcastsock.setNetworkInterface(nic);
+
+            byte[] buf = "hello world".getBytes();
+            DatagramPacket packet1 = new DatagramPacket(buf, buf.length,
+                                        new InetSocketAddress(group1, port));
+            DatagramPacket packet2 = new DatagramPacket(buf, buf.length,
+                                        new InetSocketAddress(group2, port));
+            DatagramPacket packet3 = new DatagramPacket(buf, buf.length,
+                                        new InetSocketAddress(group3, port));
+
+            for (;;) {
+                mcastsock.send(packet1);
+                mcastsock.send(packet2);
+                mcastsock.send(packet3);
+
+                Thread.currentThread().sleep(1000);   // sleep 1 second
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+}
diff --git a/test/java/net/MulticastSocket/SetTTLAndGetTTL.java b/test/java/net/MulticastSocket/SetTTLAndGetTTL.java
new file mode 100644
index 0000000..8dd3e2a
--- /dev/null
+++ b/test/java/net/MulticastSocket/SetTTLAndGetTTL.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 1998 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 4189640
+ * @summary Make setTTL/getTTL works
+ */
+
+import java.net.*;
+
+public class SetTTLAndGetTTL {
+
+    public static void main(String args[]) throws Exception {
+        MulticastSocket soc = null;
+
+        try {
+            soc = new MulticastSocket();
+        } catch(Exception e) {
+            throw new Exception("Unexpected Exception");
+        }
+
+        soc.setTTL((byte)200);
+        byte ttlValue = soc.getTTL();
+        if (ttlValue != (byte)200)
+            throw new Exception("setTTL/getTTL is broken");
+    }
+}
diff --git a/test/java/net/MulticastSocket/SetTTLTo0.java b/test/java/net/MulticastSocket/SetTTLTo0.java
new file mode 100644
index 0000000..c7385cb
--- /dev/null
+++ b/test/java/net/MulticastSocket/SetTTLTo0.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 1998 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 4148757
+ * @summary Make sure TTL can be set to 0
+ */
+
+import java.net.*;
+
+public class SetTTLTo0 {
+
+    public static void main(String args[]) throws Exception {
+        MulticastSocket soc = null;
+
+        try {
+            soc = new MulticastSocket();
+        } catch(Exception e) {
+            throw new Exception("Unexpected Exception");
+        }
+
+        soc.setTTL((byte)0);
+        soc.setTimeToLive(0);
+
+    }
+}
diff --git a/test/java/net/MulticastSocket/Test.java b/test/java/net/MulticastSocket/Test.java
new file mode 100644
index 0000000..14cedd3
--- /dev/null
+++ b/test/java/net/MulticastSocket/Test.java
@@ -0,0 +1,202 @@
+/*
+ * Copyright 2001 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 4488458
+ * @summary IPv4 and IPv6 multicasting broken on Linux
+ */
+import java.net.*;
+import java.io.IOException;
+import java.util.Enumeration;
+
+public class Test {
+
+    static int count = 0;
+    static int failures = 0;
+
+    void doTest(String address) throws Exception {
+        boolean failed = false;
+
+        InetAddress ia = InetAddress.getByName(address);
+
+        count++;
+        System.out.println("**********************");
+        System.out.println("Test " + count + ": " + ia);
+
+        MulticastSocket mc = new MulticastSocket();
+        int port = mc.getLocalPort();
+        DatagramSocket s1 = new DatagramSocket();
+
+        byte msg[] = "Hello".getBytes();
+        DatagramPacket p = new DatagramPacket(msg, msg.length);
+
+        mc.setSoTimeout(2000);
+
+        try {
+            for (int i=0; i<2; i++) {
+
+                System.out.println("Join: " + ia);
+                mc.joinGroup(ia);
+
+                /* packets should be received */
+
+                for (int j=0; j<2; j++) {
+                    p.setAddress(ia);
+                    p.setPort(port);
+
+                    System.out.println("Send packet to: " + ia);
+                    s1.send(p);
+
+                    try {
+                        mc.receive(p);
+                        System.out.println("Got packet! - Good.");
+                    } catch (SocketTimeoutException e) {
+                        failed = true;
+                        System.out.println("Failed: No packet received within timeout!!!");
+                    }
+                }
+
+                System.out.println("Leave: " + ia);
+                mc.leaveGroup(ia);
+
+                /*
+                 * If there are multiple interface we might be a couple of
+                 * copies still in our queue
+                 */
+                try {
+                    while (true) {
+                        mc.receive(p);
+                    }
+                } catch (SocketTimeoutException e) { }
+
+                /* packets should not be received */
+
+                p.setAddress(ia);
+                p.setPort(port);
+
+                s1.send(p);
+
+                try {
+                    mc.receive(p);
+                    System.out.println("Failed: Got packet after leaving group!!!");
+                    failed = true;
+                } catch (SocketTimeoutException e) {
+                    System.out.println("No packet received within timeout! - Good.");
+                }
+            }
+
+         } catch (IOException ioe) {
+            System.out.println("Failed: Unexpected exception thrown: ");
+            ioe.printStackTrace();
+            failed = true;
+        }
+
+        mc.close();
+        s1.close();
+
+        if (failed) {
+            failures++;
+            System.out.println("Test failed!!");
+        } else {
+            System.out.println("Test passed.");
+        }
+    }
+
+    void allTests() throws Exception {
+
+        /*
+         * Assume machine has IPv4 address
+         */
+        doTest("224.80.80.80");
+
+        /*
+         * Check if IPv6 is enabled and the scope of the addresses
+         */
+        boolean has_ipv6 = false;
+        boolean has_siteaddress = false;
+        boolean has_linklocaladdress = false;
+        boolean has_globaladdress = false;
+
+        Enumeration nifs = NetworkInterface.getNetworkInterfaces();
+        while (nifs.hasMoreElements()) {
+            NetworkInterface ni = (NetworkInterface)nifs.nextElement();
+            Enumeration addrs = ni.getInetAddresses();
+
+            while (addrs.hasMoreElements()) {
+                InetAddress ia = (InetAddress)addrs.nextElement();
+
+                if (ia instanceof Inet6Address) {
+                    has_ipv6 = true;
+                    if (ia.isLinkLocalAddress()) has_linklocaladdress = true;
+                    if (ia.isSiteLocalAddress()) has_siteaddress = true;
+
+                    if (!ia.isLinkLocalAddress() &&
+                        !ia.isSiteLocalAddress() &&
+                        !ia.isLoopbackAddress()) {
+                        has_globaladdress = true;
+                    }
+                }
+            }
+        }
+
+        /*
+         * If IPv6 is enabled perform multicast tests with various scopes
+         */
+        if (has_ipv6) {
+            doTest("ff01::a");
+        }
+
+        if (has_linklocaladdress) {
+            doTest("ff02::a");
+        }
+
+        if (has_siteaddress) {
+            doTest("ff05::a");
+        }
+
+        if (has_globaladdress) {
+            doTest("ff0e::a");
+        }
+    }
+
+    public static void main(String args[]) throws Exception {
+        Test t = new Test();
+
+        if (args.length == 0) {
+            t.allTests();
+        } else {
+            for (int i=0; i<args.length; i++) {
+                t.doTest(args[i]);
+            }
+        }
+
+        System.out.println("**********************");
+        System.out.println(count + " test(s) executed. " + failures +
+                           " test(s) failed.");
+
+        if (failures > 0) {
+            throw new Exception("Test failed - see log file for details");
+        }
+    }
+}
diff --git a/test/java/net/MulticastSocket/TestDefaults.java b/test/java/net/MulticastSocket/TestDefaults.java
new file mode 100644
index 0000000..0c04ad1
--- /dev/null
+++ b/test/java/net/MulticastSocket/TestDefaults.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2001 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 4488458
+ * @summary Test that MutlicastSocket.getInterface, getTimeToLive, and
+ *          getLoopbackMode work as expected on Linux 2.2 kernel
+ *          if IPv6 is enabled.
+ */
+import java.net.*;
+
+public class TestDefaults {
+
+    public static void main(String args[]) throws Exception {
+        MulticastSocket mc = new MulticastSocket();
+
+        int ttl = mc.getTimeToLive();
+        InetAddress ia = mc.getInterface();
+        boolean mode = mc.getLoopbackMode();
+
+        System.out.println("Default multicast settings:");
+        System.out.println("      ttl: " + ttl);
+        System.out.println("interface: " + ia);
+        System.out.println(" loopback: " + mode);
+
+        if (ttl != 1) {
+            throw new Exception("Default ttl != 1  -- test failed!!!");
+        }
+
+    }
+}
diff --git a/test/java/net/MulticastSocket/TestInterfaces.java b/test/java/net/MulticastSocket/TestInterfaces.java
new file mode 100644
index 0000000..8ad948d
--- /dev/null
+++ b/test/java/net/MulticastSocket/TestInterfaces.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2001 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 4422122
+ * @summary Test that MulticastSocket.getInterface returns the
+ *          same InetAddress set by MulticastSocket.setInterface
+ */
+import java.net.*;
+import java.util.Enumeration;
+import java.io.IOException;
+
+public class TestInterfaces {
+
+    public static void main(String args[]) throws Exception {
+        int failures = 0;
+
+        MulticastSocket soc = new MulticastSocket();
+
+        Enumeration nifs = NetworkInterface.getNetworkInterfaces();
+        while (nifs.hasMoreElements()) {
+            NetworkInterface ni = (NetworkInterface)nifs.nextElement();
+
+            /*
+             * Test MulticastSocket.getInterface
+             */
+            Enumeration addrs = ni.getInetAddresses();
+            while (addrs.hasMoreElements()) {
+                InetAddress ia = (InetAddress)addrs.nextElement();
+
+                System.out.println("********************************");
+                System.out.println("MulticastSocket.setInterface(" + ia + ")");
+
+                try {
+                    soc.setInterface(ia);
+                } catch (IOException ioe) {
+                    System.err.println("Can't set interface to: " + ia
+                        + " " + ioe.getMessage());
+                    continue;
+                }
+
+                InetAddress curr = soc.getInterface();
+                if (!curr.equals(ia)) {
+                    System.err.println("MulticastSocket.getInterface returned: " + curr);
+                    System.err.println("Failed! Expected: " + ia);
+                    failures++;
+                } else {
+                    System.out.println("Passed.");
+                }
+            }
+
+            /*
+             * Test MulticastSocket.getNetworkInterface
+             */
+            System.out.println("********************************");
+            System.out.println("MulticastSocket.setNetworkInterface(" +
+                ni.getName() + ")");
+
+            try {
+                soc.setNetworkInterface(ni);
+            } catch (IOException ioe) {
+                System.err.println("Can't set interface to: " + ni.getName()
+                        + " " + ioe.getMessage());
+                continue;
+            }
+
+            NetworkInterface curr = soc.getNetworkInterface();
+            if (!curr.equals(ni)) {
+                System.err.println("MulticastSocket.getNetworkInterface returned: " + curr);
+                System.err.println("Failed! Expected: " + ni);
+                failures++;
+            } else {
+                System.out.println("Passed.");
+            }
+
+        }
+
+        if (failures > 0) {
+            System.out.println("********************************");
+            throw new Exception(failures + " test(s) failed!!!");
+        }
+
+    }
+
+}
diff --git a/test/java/net/MulticastSocket/TimeToLive.java b/test/java/net/MulticastSocket/TimeToLive.java
new file mode 100644
index 0000000..59bcc0e
--- /dev/null
+++ b/test/java/net/MulticastSocket/TimeToLive.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 1998-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
+ *
+ * @bug 4091012
+ *
+ * @summary Tests MulticastSocket send for new set/getTimeToLived
+ *
+ */
+import java.net.*;
+
+public class TimeToLive {
+
+    static int[] new_ttls = { 0, 1, 127, 254, 255 };
+    static int[] bad_ttls = { -1, 256 };
+
+    public static void main(String[] args) throws Exception {
+        MulticastSocket socket = new MulticastSocket(6789);
+        int ttl = socket.getTimeToLive();
+        System.out.println("default ttl: " + ttl);
+        for (int i = 0; i < new_ttls.length; i++) {
+            socket.setTimeToLive(new_ttls[i]);
+            if (!(new_ttls[i] == socket.getTimeToLive())) {
+                throw new RuntimeException("test failure, set/get differ: " +
+                                           new_ttls[i] + " /  " +
+                                           socket.getTimeToLive());
+            }
+        }
+        for (int j = 0; j < bad_ttls.length; j++) {
+            boolean exception = false;
+            try {
+                socket.setTimeToLive(bad_ttls[j]);
+            } catch (IllegalArgumentException e) {
+                exception = true;
+            }
+            if (!exception) {
+                throw new RuntimeException("bad argument accepted: " + bad_ttls[j]);
+            }
+        }
+    }
+}