Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5076965

(so) SocketChannel does not report local address after binding to a wildcard

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.4.2
    • Fix Version/s: 6
    • Component/s: core-libs
    • Subcomponent:
    • Resolved In Build:
      b59
    • CPU:
      sparc
    • OS:
      solaris_8

      Description

      Name: rmT116609 Date: 07/21/2004


      FULL PRODUCT VERSION :
      java version "1.4.2_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
      Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      SunOS kupala 5.8 Generic_117000-03 sun4u sparc SUNW,Sun-Fire-15000

      evo:~/tmp> uname -a
      Linux dshaffer-l 2.4.21-215-smp4G #1 SMP Tue Apr 27 00:56:55 UTC 2004 i686
      evo:~/tmp> cat /etc/SuSE-release
      SuSE Linux 9.0 (i586)
      VERSION = 9.0


      A DESCRIPTION OF THE PROBLEM :
      Socket channels bound to a wildcard local address do not show the actual address bound to even after a connection is established.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the given program and run it.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      sock Local address is: /127.0.0.1
      sockChan Local address is: /127.0.0.1
      sockChan2 Local address is: /127.0.0.1
      sockChan3 Local address is: /127.0.0.1


      ACTUAL -
      sock Local address is: /127.0.0.1
      sockChan Local address is: /127.0.0.1
      sockChan2 Local address is: /127.0.0.1
      sockChan3 Local address is: /0:0:0:0:0:0:0:0


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------


      import java.net.*;
      import java.nio.channels.SocketChannel;

      public class SocketChannelTest {
          //Shows SocketChannel local address issue
          public static void main(String[] args) throws Exception{
              ServerSocket ssock = new ServerSocket(3000);

              //A standard socket behaves as expected, returning a local address of
              // "/127.0.0.1"
              Socket sock = new Socket("localhost", 3000);
              System.err.println("sock Local address is: " + sock.getLocalAddress());
              sock.close();

              //A SocketChannel with no explicit bind behaves as expected, returning a
              //local address of "/127.0.0.1"
              SocketChannel sockChan = SocketChannel.open();
              sockChan.connect(new InetSocketAddress("localhost", 3000));
              System.err.println("sockChan Local address is: " + sockChan.socket().getLocalAddress());
              sockChan.close();

              //A SocketChannel that explicitly binds an interface behaves as
              //expected, returning a local address of "/127.0.0.1"
              SocketChannel sockChan2 = SocketChannel.open();
              sockChan2.socket().bind(new InetSocketAddress("localhost", 4000));
              sockChan2.connect(new InetSocketAddress("localhost", 3000));
              System.err.println("sockChan2 Local address is: " + sockChan2.socket().getLocalAddress());
              sockChan2.close();

              //However, a SocketChannel that explicitly binds to a wildcard interface
              //does not correctly return its local address... Instead it returns
              // "/0:0:0:0:0:0:0:0"
              SocketChannel sockChan3 = SocketChannel.open();
              sockChan3.socket().bind(new InetSocketAddress(5000));
              sockChan3.connect(new InetSocketAddress("localhost", 3000));
              System.err.println("sockChan3 Local address is: " + sockChan3.socket().getLocalAddress());
              sockChan3.close();

              ssock.close();
          }
      }

      ---------- END SOURCE ----------
      (Incident Review ID: 286672)
      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              sherman Xueming Shen
              Reporter:
              rmandalasunw Ranjith Mandala (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: