6713809: FTP fails from multi-homed system
authorjccollet
Tue, 01 Jul 2008 13:29:36 +0200
changeset 901 7c3638e8ff31
parent 795 b4e3c4974723
child 902 bbfb1e2369b2
6713809: FTP fails from multi-homed system Summary: Binds the data socket to the same address as the control socket Reviewed-by: michaelm
jdk/src/share/classes/sun/net/ftp/FtpClient.java
--- a/jdk/src/share/classes/sun/net/ftp/FtpClient.java	Sun Jun 29 00:25:59 2008 -0700
+++ b/jdk/src/share/classes/sun/net/ftp/FtpClient.java	Tue Jul 01 13:29:36 2008 +0200
@@ -352,6 +352,9 @@
                 s = new Socket(Proxy.NO_PROXY);
         } else
             s = new Socket();
+        // Bind the socket to the same address as the control channel. This
+        // is needed in case of multi-homed systems.
+        s.bind(new InetSocketAddress(serverSocket.getLocalAddress(),0));
         if (connectTimeout >= 0) {
             s.connect(dest, connectTimeout);
         } else {
@@ -417,8 +420,10 @@
             // since we can't accept a connection through SOCKS (yet)
             // throw an exception
             throw new FtpProtocolException("Passive mode failed");
-        } else
-            portSocket = new ServerSocket(0, 1);
+        }
+        // Bind the ServerSocket to the same address as the control channel
+        // This is needed for multi-homed systems
+        portSocket = new ServerSocket(0, 1, serverSocket.getLocalAddress());
         try {
             myAddress = portSocket.getInetAddress();
             if (myAddress.isAnyLocalAddress())