Path: blob/master/test/jdk/java/net/MulticastSocket/NetworkInterfaceEmptyGetInetAddressesTest.java
41149 views
/*1* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 817532526* @summary test NetworkInterface getInterfaceAddresses method on the NetworkInterface returned27* from the getNetworkInterface invocation on a MulticastSocket bound to a wildcard address.28*29*/3031import java.net.MulticastSocket;32import java.net.NetworkInterface;33import java.net.SocketException;3435public class NetworkInterfaceEmptyGetInetAddressesTest {3637static int exceptionCount = 0;3839public static void testMethods(NetworkInterface netIf) throws Exception {40testNetworkInterface_getInterfaceAddresses(netIf);4142if (exceptionCount > 0) {43throw new RuntimeException("Unexpected Exceptions in test");44}45}4647private static void testNetworkInterface_getInterfaceAddresses(48NetworkInterface netIf) {49try {50netIf.getInterfaceAddresses();51} catch (Exception ex) {52ex.printStackTrace();53incrementExceptionCount();54}55}5657private static void incrementExceptionCount() {58exceptionCount++;59}6061public static void main(String[] args) throws Exception {62MulticastSocket mcastSock = null;63try {64mcastSock = new MulticastSocket();65System.out.println("macst socket address == "66+ mcastSock.getLocalAddress());67NetworkInterface netIf = mcastSock.getNetworkInterface();68testMethods(netIf);69} finally {70if (mcastSock != null) {71mcastSock.close();72}73}74}75}767778