Code example for NetworkInterface

Methods: getInetAddresses

0
                             InetAddress.getByName("0.0.0.0"),
                             firstAddress);
            } 
 
            mss.setNetworkInterface(networkInterface1);
            assertEquals("getNetworkInterface did not return interface set by setNeworkInterface", 
                         networkInterface1, mss.getNetworkInterface());
 
            if (atLeastTwoInterfaces) {
                mss.setNetworkInterface(networkInterface2);
                assertEquals("getNetworkInterface did not return network interface set by second setNetworkInterface call", 
                             networkInterface2, mss.getNetworkInterface());
            } 
 
            groupPort = Support_PortManager.getNextPortForUDP();
            mss = new MulticastSocket(groupPort);
            if (IPV6networkInterface1 != null) {
                mss.setNetworkInterface(IPV6networkInterface1);
                assertEquals("getNetworkInterface did not return interface set by setNeworkInterface", 
                             IPV6networkInterface1,
                             mss.getNetworkInterface());
            } 
 
            // validate that we get the expected response when we set via 
            // setInterface 
            groupPort = Support_PortManager.getNextPortForUDP();
            mss = new MulticastSocket(groupPort);
            Enumeration addresses = networkInterface1.getInetAddresses();
            if (addresses.hasMoreElements()) {
                firstAddress = (InetAddress) addresses.nextElement();
                mss.setInterface(firstAddress);
                assertEquals("getNetworkInterface did not return interface set by setInterface", 
                             networkInterface1,
                             mss.getNetworkInterface());
            } 
        } 
    }