Mercurial > hg > openjdk > icedtea > jdk7 > jdk
changeset 2479:0c27202d66c1
6718504: IN6_IS_ADDR_ANY tests only 12 bytes of 16-byte address
Reviewed-by: alanb
author | chegar |
---|---|
date | Tue, 27 Apr 2010 09:42:51 +0100 |
parents | edde2f60415b |
children | b833a422c776 |
files | src/windows/native/java/net/net_util_md.h test/java/net/DatagramSocket/LocalSocketAddress.java |
diffstat | 2 files changed, 73 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/windows/native/java/net/net_util_md.h Thu Apr 22 12:45:36 2010 +0800 +++ b/src/windows/native/java/net/net_util_md.h Tue Apr 27 09:42:51 2010 +0100 @@ -222,7 +222,8 @@ #define IN6_IS_ADDR_ANY(a) \ (((a)->s6_words[0] == 0) && ((a)->s6_words[1] == 0) && \ ((a)->s6_words[2] == 0) && ((a)->s6_words[3] == 0) && \ - ((a)->s6_words[4] == 0) && ((a)->s6_words[5] == 0)) + ((a)->s6_words[4] == 0) && ((a)->s6_words[5] == 0) && \ + ((a)->s6_words[6] == 0) && ((a)->s6_words[7] == 0)) #endif #ifndef IPV6_V6ONLY
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/net/DatagramSocket/LocalSocketAddress.java Tue Apr 27 09:42:51 2010 +0100 @@ -0,0 +1,71 @@ +/* + * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* @test + * @bug 6718504 + * @summary IN6_IS_ADDR_ANY tests only 12 bytes of 16-byte address + */ + +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.Inet6Address; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.*; + +public class LocalSocketAddress { + public static void main(String[] args) throws SocketException { + InetAddress IPv6LoopbackAddr = null; + DatagramSocket soc = null; + + try { + List<NetworkInterface> nics = Collections.list(NetworkInterface.getNetworkInterfaces()); + for (NetworkInterface nic : nics) { + if (!nic.isLoopback()) + continue; + + List<InetAddress> addrs = Collections.list(nic.getInetAddresses()); + for (InetAddress addr : addrs) { + if (addr instanceof Inet6Address) { + IPv6LoopbackAddr = addr; + break; + } + } + } + + if (IPv6LoopbackAddr == null) { + System.out.println("IPv6 is not available, exiting test."); + return; + } + + soc = new DatagramSocket(0, IPv6LoopbackAddr); + + if (!IPv6LoopbackAddr.equals(soc.getLocalAddress())) { + throw new RuntimeException("Bound address is " + soc.getLocalAddress() + + ", but should be " + IPv6LoopbackAddr); + } + } finally { + if (soc != null) { soc.close(); } + } + } +}