/*
 * Copyright 2012 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.netty.channel.socket.nio;

import io.netty.util.internal.DetectionUtil;

import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.StandardProtocolFamily;
import java.nio.channels.DatagramChannel;

import junit.framework.Assert;

import org.junit.Test;

public class DefaultNioDatagramChannelConfigTest {

    @Test
    public void testMulticastOptions() throws IOException {
        if (DetectionUtil.javaVersion() < 7) {
            return;
        }
        DefaultNioDatagramChannelConfig config = new DefaultNioDatagramChannelConfig(DatagramChannel.open(StandardProtocolFamily.INET));
        NetworkInterface inf = NetworkInterface.getNetworkInterfaces().nextElement();
        config.setNetworkInterface(inf);
        Assert.assertEquals(inf, config.getNetworkInterface());
        
        InetAddress localhost = inf.getInetAddresses().nextElement();
        config.setInterface(localhost);
        Assert.assertEquals(localhost, config.getInterface());
        
        config.setTimeToLive(100);
        Assert.assertEquals(100, config.getTimeToLive());
        
        config.setLoopbackModeDisabled(false);
        Assert.assertEquals(false, config.isLoopbackModeDisabled());

    }
}

@@ -738,16 +738,46 @@
 eption;%0A
+import java.net.Inet4Address;%0A
 import j
@@ -789,32 +789,32 @@
 et.InetAddress;%0A
-
 import java.net.
@@ -912,16 +912,46 @@
 Channel;
+%0Aimport java.util.Enumeration;
 %0A%0Aimport
@@ -1211,106 +1211,648 @@
     
-DefaultNioDatagramChannelConfig config = new DefaultNioDatagramChannelConfig(DatagramChannel.open(
+%0A        StandardProtocolFamily family = null;%0A        NetworkInterface inf = null;%0A        Enumeration%3CNetworkInterface%3E interfaces = NetworkInterface.getNetworkInterfaces();%0A        while (interfaces.hasMoreElements()) %7B%0A            inf = interfaces.nextElement();%0A            Enumeration%3CInetAddress%3E addresses = inf.getInetAddresses();%0A            while(addresses.hasMoreElements()) %7B%0A                InetAddress addr = addresses.nextElement();%0A                if (addr instanceof Inet4Address) %7B%0A                    family = StandardProtocolFamily.INET;%0A                    break;%0A                %7D else %7B%0A                    family = 
 Stan
@@ -1874,18 +1874,17 @@
 ily.INET
-))
+6
 ;%0A      
@@ -1889,86 +1889,288 @@
     
-NetworkInterface inf = NetworkInterface.getNetworkInterfaces().nextElement(
+        %7D%0A            %7D%0A        %7D%0A        if (inf == null) %7B%0A            // No usable interface found so just skip the test%0A            return;%0A        %7D%0A        %0A        DefaultNioDatagramChannelConfig config = new DefaultNioDatagramChannelConfig(DatagramChannel.open(family)
 );%0A
+%0A
     
@@ -2270,33 +2270,37 @@
 ace());%0A        
+    
 %0A
-
         InetAddr
@@ -2456,33 +2456,37 @@
 ace());%0A        
+    
 %0A
-
         config.s
@@ -2562,33 +2562,37 @@
 ive());%0A        
+    
 %0A
-
         config.s
@@ -2622,16 +2622,16 @@
 false);%0A
-
         
@@ -2690,16 +2690,43 @@
 bled());
+%0A        %0A        %0A        
 %0A%0A    %7D%0A

Make sure the test also work on ipv6 interfaces