2340N/A/*
2362N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2340N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2340N/A *
2340N/A * This code is free software; you can redistribute it and/or modify it
2340N/A * under the terms of the GNU General Public License version 2 only, as
2340N/A * published by the Free Software Foundation.
2340N/A *
2340N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2340N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2340N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2340N/A * version 2 for more details (a copy is included in the LICENSE file that
2340N/A * accompanied this code).
2340N/A *
2340N/A * You should have received a copy of the GNU General Public License version
2340N/A * 2 along with this work; if not, write to the Free Software Foundation,
2340N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2340N/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.
2340N/A */
2340N/A
2340N/A/* @test
2340N/A * @bug 6718504
2340N/A * @summary IN6_IS_ADDR_ANY tests only 12 bytes of 16-byte address
2340N/A */
2340N/A
2340N/Aimport java.net.DatagramSocket;
2340N/Aimport java.net.InetAddress;
2340N/Aimport java.net.Inet6Address;
2340N/Aimport java.net.NetworkInterface;
2340N/Aimport java.net.SocketException;
2340N/Aimport java.util.*;
2340N/A
2340N/Apublic class LocalSocketAddress {
2340N/A public static void main(String[] args) throws SocketException {
2340N/A InetAddress IPv6LoopbackAddr = null;
2340N/A DatagramSocket soc = null;
2340N/A
2340N/A try {
2340N/A List<NetworkInterface> nics = Collections.list(NetworkInterface.getNetworkInterfaces());
2340N/A for (NetworkInterface nic : nics) {
2340N/A if (!nic.isLoopback())
2340N/A continue;
2340N/A
2340N/A List<InetAddress> addrs = Collections.list(nic.getInetAddresses());
2340N/A for (InetAddress addr : addrs) {
2340N/A if (addr instanceof Inet6Address) {
2340N/A IPv6LoopbackAddr = addr;
2340N/A break;
2340N/A }
2340N/A }
2340N/A }
2340N/A
2340N/A if (IPv6LoopbackAddr == null) {
2340N/A System.out.println("IPv6 is not available, exiting test.");
2340N/A return;
2340N/A }
2340N/A
2340N/A soc = new DatagramSocket(0, IPv6LoopbackAddr);
2340N/A
2340N/A if (!IPv6LoopbackAddr.equals(soc.getLocalAddress())) {
2340N/A throw new RuntimeException("Bound address is " + soc.getLocalAddress() +
2340N/A ", but should be " + IPv6LoopbackAddr);
2340N/A }
2340N/A } finally {
2340N/A if (soc != null) { soc.close(); }
2340N/A }
2340N/A }
2340N/A}