5511N/A/*
5511N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
5511N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5511N/A *
5511N/A * This code is free software; you can redistribute it and/or modify it
5511N/A * under the terms of the GNU General Public License version 2 only, as
5511N/A * published by the Free Software Foundation.
5511N/A *
5511N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5511N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5511N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5511N/A * version 2 for more details (a copy is included in the LICENSE file that
5511N/A * accompanied this code).
5511N/A *
5511N/A * You should have received a copy of the GNU General Public License version
5511N/A * 2 along with this work; if not, write to the Free Software Foundation,
5511N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5511N/A *
5511N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5511N/A * or visit www.oracle.com if you need additional information or have any
5511N/A * questions.
5511N/A */
5511N/A
5511N/A/**
5511N/A * @test
5511N/A * @bug 6210227
5511N/A * @summary REGRESSION: Socket.getLocalAddress() returns address of 0.0.0.0 on outbound TCP
5511N/A */
5511N/A
5511N/Aimport java.util.*;
5511N/Aimport java.net.*;
5511N/A
5511N/Apublic class B6210227 {
5511N/A public static void main(String[] args) throws Exception
5511N/A {
5511N/A ServerSocket ss = new ServerSocket(0);
5511N/A int port = ss.getLocalPort();
5511N/A
5511N/A byte[] bad = {0,0,0,0};
5511N/A try {
5511N/A InetSocketAddress isa = new InetSocketAddress(InetAddress.getLocalHost(), port);
5511N/A Socket s = new Socket();
5511N/A s.connect( isa, 1000 );
5511N/A InetAddress iaLocal = s.getLocalAddress(); // if this comes back as 0.0. 0.0 this would demonstrate issue
5511N/A String sLocalHostname = iaLocal.getHostName();
5511N/A if (Arrays.equals (iaLocal.getAddress(), bad)) {
5511N/A throw new RuntimeException ("0.0.0.0 returned");
5511N/A }
5511N/A System.out.println("local hostname is "+sLocalHostname );
5511N/A } catch(Exception e) {
5511N/A System.out.println("Exception happened");
5511N/A throw e;
5511N/A } finally {
5511N/A ss.close();
5511N/A }
5511N/A }
5511N/A}
5511N/A