509N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
509N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
509N/A *
509N/A * This code is free software; you can redistribute it and/or modify it
509N/A * under the terms of the GNU General Public License version 2 only, as
509N/A * published by the Free Software Foundation.
509N/A *
509N/A * This code is distributed in the hope that it will be useful, but WITHOUT
509N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
509N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
509N/A * version 2 for more details (a copy is included in the LICENSE file that
509N/A * accompanied this code).
509N/A *
509N/A * You should have received a copy of the GNU General Public License version
509N/A * 2 along with this work; if not, write to the Free Software Foundation,
509N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
509N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
509N/A */
509N/A
509N/A/* @test
509N/A * @bug 6717876
509N/A * @summary Make java.net.NetworkInterface.getIndex() public
509N/A */
509N/A
509N/Aimport java.net.*;
509N/Aimport java.util.Enumeration;
509N/A
509N/Apublic class IndexTest {
509N/A public static void main(String[] args) throws Exception {
509N/A Enumeration<NetworkInterface> netifs = NetworkInterface.getNetworkInterfaces();
509N/A NetworkInterface nif = null;
509N/A while (netifs.hasMoreElements()) {
509N/A nif = netifs.nextElement();
509N/A int index = nif.getIndex();
509N/A if (index >= 0) {
509N/A NetworkInterface nif2 = NetworkInterface.getByIndex(index);
509N/A if (! nif.equals(nif2)) {
509N/A throw new RuntimeException("both interfaces should be equal");
509N/A }
509N/A }
509N/A }
509N/A try {
509N/A nif = NetworkInterface.getByIndex(-1);
509N/A throw new RuntimeException("Should have thrown IllegalArgumentException");
509N/A } catch (IllegalArgumentException e) {
509N/A // OK
509N/A }
509N/A // In all likelyhood, this interface should not exist.
509N/A nif = NetworkInterface.getByIndex(Integer.MAX_VALUE - 1);
509N/A if (nif != null) {
509N/A throw new RuntimeException("getByIndex() should have returned null");
509N/A }
509N/A }
509N/A}