[Toybox] FTP commands
ibid.ag at gmail.com
ibid.ag at gmail.com
Thu Dec 12 17:39:56 PST 2013
On Thu, Dec 12, 2013 at 02:25:38PM +0530, Ashwini Sharma wrote:
> Hi,
>
> The input parameter port was kept as string, so that the
> user can also give service name like "ftp" instead of numeric PORT.
>
> Which will be resolved by getaddrinfo() using /etc/services.
>
> regards,
> Ashwini
>
Thanks for the explanation.
Unfortunately it doesn't always work that way:
//TT.port is initialized to "ftp" if not set
static void get_sockaddr(char *host)
{
struct addrinfo hints, *result;
char *ptr;
int status, port;
errno = 0;
port = strtoul(TT.port, &ptr, 10); // <- may set errno if non-numeric port
if (errno || port > 65535) error_exit("Invalid port, Range
is [0-65535]"); // <- we hit this by default on musl
memset(&hints, 0 , sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
status = getaddrinfo(host, TT.port, &hints,
&result);
if (status) error_exit("bad address '%s' : %s",
host, gai_strerror(status));
memcpy(TT.buf, result->ai_addr, result->ai_addrlen);
freeaddrinfo(result);
}
I'm thinking that should be
- port = strtoul(TT.port, &ptr, 10);
+ if (isdigit(TT.port[0])) port = strtoul(TT.port, &ptr, 10);
and initialize port to 0, if we want to keep support for -P ftp.
(I don't imagine anyone using -P ssh or any non-numeric port other
than "ftp".)
OK, yes that works...
Attaching my full diff, which also addresses a couple nitpicks:
-Rob adds new applets to toys/pending/, default n.
They get default y when he thinks they're ready.
-Any user-supplied value is all-caps in the help messages, so
we have -u USER -p PASSWORD -P PORT
Thanks,
Isaac Dunham
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ftpget.diff
Type: text/x-diff
Size: 1225 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20131212/087914c1/attachment-0002.diff>
More information about the Toybox
mailing list