From 00db336a00adfde2b05f0d039e379f6e45fdd0ec Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 21 Feb 2011 10:58:15 +0000 Subject: 2011-02-21 Sebastian Huber * libnetworking/lib/ftpfs.c: Workaround for some firewalls. --- cpukit/ChangeLog | 4 +++ cpukit/libnetworking/lib/ftpfs.c | 57 +++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 30 deletions(-) (limited to 'cpukit') diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 214320e93a..e20dbd43c4 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,7 @@ +2011-02-21 Sebastian Huber + + * libnetworking/lib/ftpfs.c: Workaround for some firewalls. + 2011-02-18 Joel Sherrill * sapi/include/confdefs.h, score/Makefile.am, diff --git a/cpukit/libnetworking/lib/ftpfs.c b/cpukit/libnetworking/lib/ftpfs.c index 00467e5e9b..0f2183409c 100644 --- a/cpukit/libnetworking/lib/ftpfs.c +++ b/cpukit/libnetworking/lib/ftpfs.c @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2009, 2010 + * Copyright (c) 2009, 2010, 2011 * embedded brains GmbH * Obere Lagerstr. 30 * D-82178 Puchheim @@ -347,40 +347,37 @@ static rtems_ftpfs_reply rtems_ftpfs_send_command_with_parser( bool verbose ) { - const char *const eol = "\r\n"; - int rv = 0; - - /* Send command */ - rv = send(socket, cmd, strlen(cmd), 0); - if (rv < 0) { - return RTEMS_FTPFS_REPLY_ERROR; - } - if (verbose) { - write(STDERR_FILENO, cmd, strlen(cmd)); - } + rtems_ftpfs_reply reply = RTEMS_FTPFS_REPLY_ERROR; + size_t cmd_len = strlen(cmd); + size_t arg_len = arg != NULL ? strlen(arg) : 0; + size_t len = cmd_len + arg_len + 2; + char *buf = malloc(len); + + if (buf != NULL) { + ssize_t n = 0; + char *buf_arg = buf + cmd_len; + char *buf_eol = buf_arg + arg_len; + + memcpy(buf, cmd, cmd_len); + memcpy(buf_arg, arg, arg_len); + buf_eol [0] = '\r'; + buf_eol [1] = '\n'; + + /* Send */ + n = send(socket, buf, len, 0); + if (n == (ssize_t) len) { + if (verbose) { + write(STDERR_FILENO, buf, len); + } - /* Send command argument if necessary */ - if (arg != NULL) { - rv = send(socket, arg, strlen(arg), 0); - if (rv < 0) { - return RTEMS_FTPFS_REPLY_ERROR; - } - if (verbose) { - write(STDERR_FILENO, arg, strlen(arg)); + /* Reply */ + reply = rtems_ftpfs_get_reply(socket, parser, parser_arg, verbose); } - } - /* Send end of line */ - rv = send(socket, eol, 2, 0); - if (rv < 0) { - return RTEMS_FTPFS_REPLY_ERROR; - } - if (verbose) { - write(STDERR_FILENO, &eol [1], 1); + free(buf); } - /* Return reply */ - return rtems_ftpfs_get_reply(socket, parser, parser_arg, verbose); + return reply; } static rtems_ftpfs_reply rtems_ftpfs_send_command( -- cgit v1.2.3