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

FtpClient class sends wrong IP-address to server with PORT command

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.3.0
    • core-libs
    • x86
    • windows_98



      Name: boT120536 Date: 01/21/2001


      java version "1.3.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
      Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)


      1. Exact steps to reproduce the problem.
      This problem can ONLY be reproduced on a computer with more than one network
      card (a modem also considered as being a network card). I use fixed IP-
      addresses for my 2 LAN-NIC's (192.168.x.x-range or 10.0.x.x-range). My modem
      uses DHCP. This bug cannot be reproduced on a computer with only one NIC or
      only a modem. I originally discovered this bug in JDK 1.1.8, but apparently
      nobody discovered it until now, so it's still there in Java 1.3.

      2. Java SOURCE CODE that demonstrates the problem, if possible.
      This little program just downloads a zip-file from a FTP-server (anonymous) to
      a local disk.

      import java.net.*;
      import java.io.*;
      public class FtpDownload
      {
       public static void main(String[] args)
       {
        try
        {
         URL location = new URL
      ("ftp://ftp.simtel.net/pub/simtelnet/win95/inet/1cftp780.zip");
         InputStream in = location.openStream();
         OutputStream out = new FileOutputStream("1cftp780.zip");
         int k;
         while ((k = in.read()) != -1) out.write(k);
         out.close();
         in.close();
        }
        catch (Exception e) {}
       }
      }

      3. Exact text of any error message(s) that appeared.
      FtpProtocolException: PORT

      4. Any trace information.
      I traced the network traffic with a network monitor program. I found an error
      in the information which was send by my java-made application. The PORT command
      sends an IP-address to the FTP-server. The FTPClient didn't send the IP-address
      of my modem to the FTP-server, but the address of one of my NIC's (a local
      address... 192.168.0.5).
      I looked into the java-source of 'FtpClient.class' and I found out that
      in "protected Socket openDataConnection(String s)", the first line is:

      InetAddress inetaddress = InetAddress.getLocalHost();

      This is not correct! This doesn't work when there are multiple NIC's (with
      multiple IP-addresses) installed in a computer. The FtpClient-class inherits
      TransferProtocolClient, which inherits from NetworkClient. In NetworkClient
      there is a Socket called "serverSocket", which makes the initial contact with
      the FTP-server. So the statement should not use InetAddress.getLocalHost(), but
      it should be:

      InetAddress inetaddress = serverSocket.getLocalAddress();

      This determines which IP-address must be send to the server correctly. I tested
      it with my modem, which worked fine. I also tested it with a FTP-server on my
      local network.

      5. Include additional configuration information that you think is relevant to
      the problem
      Well, you must have more than one IP-address assigned to your computer to
      reproduce this bug. I think it can be reproduced on all computers with a NIC
      and a modem. It's not reproducable on a computer which routes all IP-packets to
      one NIC.
      (Review ID: 115292)
      ======================================================================

            jccollet Jean-Christophe Collet (Inactive)
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: