< prev index next >

test/java/net/Inet6Address/B6206527.java

Print this page

        

*** 23,36 **** --- 23,40 ---- /** * @test 1.1 05/01/05 * @bug 6206527 * @summary "cannot assign address" when binding ServerSocket on Suse 9 + * @library /lib/testlibrary + * @build jdk.testlibrary.NetworkConfiguration + * @run main B6206527 */ import java.net.*; import java.util.*; + import jdk.testlibrary.NetworkConfiguration; public class B6206527 { public static void main (String[] args) throws Exception { Inet6Address addr = getLocalAddr();
*** 51,73 **** System.out.println ("trying LL addr: " + addr); ss = new ServerSocket(); ss.bind(new InetSocketAddress(addr, 0)); } ! public static Inet6Address getLocalAddr () throws Exception { ! Enumeration e = NetworkInterface.getNetworkInterfaces(); ! while (e.hasMoreElements()) { ! NetworkInterface ifc = (NetworkInterface) e.nextElement(); ! Enumeration addrs = ifc.getInetAddresses(); ! while (addrs.hasMoreElements()) { ! InetAddress a = (InetAddress)addrs.nextElement(); ! if (a instanceof Inet6Address) { ! Inet6Address ia6 = (Inet6Address) a; ! if (ia6.isLinkLocalAddress()) { ! return ia6; ! } ! } ! } ! } ! return null; } } --- 55,68 ---- System.out.println ("trying LL addr: " + addr); ss = new ServerSocket(); ss.bind(new InetSocketAddress(addr, 0)); } ! public static Inet6Address getLocalAddr() throws Exception { ! Optional<Inet6Address> oaddr = NetworkConfiguration.probe() ! .ip6Addresses() ! .filter(a -> a.isLinkLocalAddress()) ! .findFirst(); ! ! return oaddr.orElseGet(() -> null); } }
< prev index next >