summaryrefslogtreecommitdiff
path: root/apps/netutils/ftpc/ftpc_socket.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-06-05 14:08:26 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-06-05 14:08:26 +0000
commitab784567291b1925d616ea9b9d2577f42d2699a5 (patch)
tree7d4f4e1976f7a03adc136358ded5a2f866cf9285 /apps/netutils/ftpc/ftpc_socket.c
parentb20e2a5a26d3c9bbbea0dbea71227085bb8a135a (diff)
downloadnuttx-ab784567291b1925d616ea9b9d2577f42d2699a5.tar.gz
nuttx-ab784567291b1925d616ea9b9d2577f42d2699a5.tar.bz2
nuttx-ab784567291b1925d616ea9b9d2577f42d2699a5.zip
More FTP bug fixes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3669 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/netutils/ftpc/ftpc_socket.c')
-rw-r--r--apps/netutils/ftpc/ftpc_socket.c114
1 files changed, 52 insertions, 62 deletions
diff --git a/apps/netutils/ftpc/ftpc_socket.c b/apps/netutils/ftpc/ftpc_socket.c
index bfa8ec7c1..d245c812d 100644
--- a/apps/netutils/ftpc/ftpc_socket.c
+++ b/apps/netutils/ftpc/ftpc_socket.c
@@ -209,81 +209,71 @@ void ftpc_sockcopy(FAR struct ftpc_socket_s *dest,
* Name: ftpc_sockaccept
*
* Description:
- * Accept a connection on the data socket (unless passive mode then this
- * function does nothing).
+ * Accept a connection on the data socket. This function is onlly used
+ * in active mode.
+ *
+ * In active mode FTP the client connects from a random port (N>1023) to the
+ * FTP server's command port, port 21. Then, the client starts listening to
+ * port N+1 and sends the FTP command PORT N+1 to the FTP server. The server
+ * will then connect back to the client's specified data port from its local
+ * data port, which is port 20. In passive mode FTP the client initiates
+ * both connections to the server, solving the problem of firewalls filtering
+ * the incoming data port connection to the client from the server. When
+ * opening an FTP connection, the client opens two random ports locally
+ * (N>1023 and N+1). The first port contacts the server on port 21, but
+ * instead of then issuing a PORT command and allowing the server to connect
+ * back to its data port, the client will issue the PASV command. The result
+ * of this is that the server then opens a random unprivileged port (P >
+ * 1023) and sends the PORT P command back to the client. The client then
+ * initiates the connection from port N+1 to port P on the server to transfer
+ * data.
*
****************************************************************************/
-int ftpc_sockaccept(struct ftpc_socket_s *sock, bool passive)
+int ftpc_sockaccept(FAR struct ftpc_socket_s *sock)
{
struct sockaddr addr;
socklen_t addrlen;
- /* In active mode FTP the client connects from a random port (N>1023) to the
- * FTP server's command port, port 21. Then, the client starts listening to
- * port N+1 and sends the FTP command PORT N+1 to the FTP server. The server
- * will then connect back to the client's specified data port from its local
- * data port, which is port 20. In passive mode FTP the client initiates
- * both connections to the server, solving the problem of firewalls filtering
- * the incoming data port connection to the client from the server. When
- * opening an FTP connection, the client opens two random ports locally
- * (N>1023 and N+1). The first port contacts the server on port 21, but
- * instead of then issuing a PORT command and allowing the server to connect
- * back to its data port, the client will issue the PASV command. The result
- * of this is that the server then opens a random unprivileged port (P >
- * 1023) and sends the PORT P command back to the client. The client then
- * initiates the connection from port N+1 to port P on the server to transfer
- * data.
+ /* Any previous socket should have been uninitialized (0) or explicitly
+ * closed (-1). But the path to this function may include a call to
+ * ftpc_sockinit(). If so... close that socket and call accept to
+ * get a new one.
*/
- if (!passive)
+ if (sock->sd > 0)
{
- /* Any previous socket should have been uninitialized (0) or explicitly
- * closed (-1). But the path to this function may include a call to
- * ftpc_sockinit(). If so... close that socket and call accept to
- * get a new one.
- */
-
- if (sock->sd > 0)
- {
- ftpc_sockclose(sock);
- }
-
- addrlen = sizeof(addr);
- sock->sd = accept(sock->sd, &addr, &addrlen);
- if (sock->sd == -1)
- {
- ndbg("accept() failed: %d\n", errno);
- return ERROR;
- }
-
- memcpy(&sock->laddr, &addr, sizeof(sock->laddr));
-
- /* Create in/out C buffer I/O streams on the data channel. First,
- * create the incoming buffered stream.
- */
-
- sock->instream = fdopen(sock->sd, "r");
- if (!sock->instream)
- {
- ndbg("fdopen() failed: %d\n", errno);
- goto errout_with_sd;
- }
-
- /* Create the outgoing stream */
-
- sock->outstream = fdopen(sock->sd, "w");
- if (!sock->outstream)
- {
- ndbg("fdopen() failed: %d\n", errno);
- goto errout_with_instream;
- }
+ ftpc_sockclose(sock);
+ }
+
+ addrlen = sizeof(addr);
+ sock->sd = accept(sock->sd, &addr, &addrlen);
+ if (sock->sd == -1)
+ {
+ ndbg("accept() failed: %d\n", errno);
+ return ERROR;
}
- else
+
+ memcpy(&sock->laddr, &addr, sizeof(sock->laddr));
+
+ /* Create in/out C buffer I/O streams on the data channel. First,
+ * create the incoming buffered stream.
+ */
+
+ sock->instream = fdopen(sock->sd, "r");
+ if (!sock->instream)
{
- /* Should already be set up from ftpc_sockinit() call */
+ ndbg("fdopen() failed: %d\n", errno);
+ goto errout_with_sd;
+ }
+
+ /* Create the outgoing stream */
- DEBUGASSERT(sock->sd >= 0 && sock->instream && sock->outstream);
+ sock->outstream = fdopen(sock->sd, "w");
+ if (!sock->outstream)
+ {
+ ndbg("fdopen() failed: %d\n", errno);
+ goto errout_with_instream;
}
return OK;