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

ServerSocket.getInetAddress() returns incorrect IP address.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.1.3
    • core-libs
    • x86, sparc
    • solaris_2.5.1, windows_nt



      Name: rlT66838 Date: 07/18/97


      ServerSocket.getInetAddress() returns a different value
      depending on how it was constructed. If it was constructed
      with an explicit InetAddress then it returns the correct
      value. If the InetAddress is not specified then the value
      returned is "0.0.0.0", when it should instead contain the
      host's IP address. This is even more complicated on
      multi-home machines where it is less obvious to which IP
      address the socket is bound (it should be the one returned
      by InetAddress.getLocalHost())

      The following test program illustrates the problem.
      Compile and run with no arguments.

      import java.io.*;
      import java.net.*;
       
      public class Test {
        public static void main(String[] args) {
          try {
            ServerSocket server = new ServerSocket(0);
            System.out.println("default address: " + server);
            server = new ServerSocket(0, 50, InetAddress.getLocalHost());
            System.out.println("explicit address: " + server);
          }
          catch(Exception e) {
            e.printStackTrace();
          }
        }
      }

      The output on my machine is:

      default address: ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=53261]
      explicit address: ServerSocket[addr=adams/206.64.15.42,port=0,localport=53262]

      The output should have been:

      default address: ServerSocket[addr=adams/206.64.15.42,port=0,localport=53261]
      explicit address: ServerSocket[addr=adams/206.64.15.42,port=0,localport=53262]


      ======================================================================

            brenaudsunw Benjamin Renaud (Inactive)
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: