aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-12-20 03:19:27 +0000
committerbug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-12-20 03:19:27 +0000
commitcd1cf219f47cd6caa310c0bf57a884d57eafe70a (patch)
tree23732228a99d203f505c0bbaf3074b978b1ec4e4
parentdd797e19af7a7c3ee42c6fc37a4d09c883cf6b67 (diff)
downloadbusybox-w32-cd1cf219f47cd6caa310c0bf57a884d57eafe70a.tar.gz
busybox-w32-cd1cf219f47cd6caa310c0bf57a884d57eafe70a.tar.bz2
busybox-w32-cd1cf219f47cd6caa310c0bf57a884d57eafe70a.zip
display the port number number correctly, other minor optimisations
git-svn-id: svn://busybox.net/trunk/busybox@8141 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--networking/ftpgetput.c50
1 files changed, 20 insertions, 30 deletions
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index cc7a2a754..9eb54d6f0 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -49,34 +49,14 @@
49#include "busybox.h" 49#include "busybox.h"
50 50
51typedef struct ftp_host_info_s { 51typedef struct ftp_host_info_s {
52 char *host;
53 char *port;
54 char *user; 52 char *user;
55 char *password; 53 char *password;
56 struct sockaddr_in *s_in; 54 struct sockaddr_in *s_in;
57} ftp_host_info_t; 55} ftp_host_info_t;
58 56
59static char verbose_flag; 57static char verbose_flag = 0;
60static char do_continue = 0; 58static char do_continue = 0;
61 59
62static ftp_host_info_t *ftp_init(void)
63{
64 ftp_host_info_t *host;
65
66 host = xcalloc(1, sizeof(ftp_host_info_t));
67
68 /* Set the default port */
69 if (getservbyname("ftp", "tcp")) {
70 host->port = "ftp";
71 } else {
72 host->port = "21";
73 }
74 host->user = "anonymous";
75 host->password = "busybox@";
76
77 return(host);
78}
79
80static int ftpcmd(const char *s1, const char *s2, FILE *stream, char *buf) 60static int ftpcmd(const char *s1, const char *s2, FILE *stream, char *buf)
81{ 61{
82 if (verbose_flag) { 62 if (verbose_flag) {
@@ -306,6 +286,7 @@ int ftpgetput_main(int argc, char **argv)
306{ 286{
307 /* content-length of the file */ 287 /* content-length of the file */
308 unsigned long opt; 288 unsigned long opt;
289 char *port = "ftp";
309 290
310 /* socket to ftp server */ 291 /* socket to ftp server */
311 FILE *control_stream; 292 FILE *control_stream;
@@ -316,27 +297,37 @@ int ftpgetput_main(int argc, char **argv)
316 297
317 int (*ftp_action)(ftp_host_info_t *, FILE *, const char *, char *) = NULL; 298 int (*ftp_action)(ftp_host_info_t *, FILE *, const char *, char *) = NULL;
318 299
300 /* Check to see if the command is ftpget or ftput */
319#ifdef CONFIG_FTPPUT 301#ifdef CONFIG_FTPPUT
302# ifdef CONFIG_FTPGET
320 if (bb_applet_name[3] == 'p') { 303 if (bb_applet_name[3] == 'p') {
321 ftp_action = ftp_send; 304 ftp_action = ftp_send;
322 } 305 }
306# else
307 ftp_action = ftp_send;
308# endif
323#endif 309#endif
324#ifdef CONFIG_FTPGET 310#ifdef CONFIG_FTPGET
311# ifdef CONFIG_FTPPUT
325 if (bb_applet_name[3] == 'g') { 312 if (bb_applet_name[3] == 'g') {
326 ftp_action = ftp_recieve; 313 ftp_action = ftp_recieve;
327 } 314 }
315# else
316 ftp_action = ftp_recieve;
317# endif
328#endif 318#endif
329 319
330 /* Set default values */ 320 /* Set default values */
331 server = ftp_init(); 321 server = xmalloc(sizeof(ftp_host_info_t));
322 server->user = "anonymous";
323 server->password = "busybox@";
332 verbose_flag = 0; 324 verbose_flag = 0;
333 325
334 /* 326 /*
335 * Decipher the command line 327 * Decipher the command line
336 */ 328 */
337 server->port = "21";
338 bb_applet_long_options = ftpgetput_long_options; 329 bb_applet_long_options = ftpgetput_long_options;
339 opt = bb_getopt_ulflags(argc, argv, "cvu:p:P:", &server->user, &server->password, &server->port); 330 opt = bb_getopt_ulflags(argc, argv, "cvu:p:P:", &server->user, &server->password, &port);
340 if (opt & FTPGETPUT_OPT_CONTINUE) { 331 if (opt & FTPGETPUT_OPT_CONTINUE) {
341 do_continue = 1; 332 do_continue = 1;
342 } 333 }
@@ -355,12 +346,11 @@ int ftpgetput_main(int argc, char **argv)
355 * sites (i.e. ftp.us.debian.org) use round-robin DNS 346 * sites (i.e. ftp.us.debian.org) use round-robin DNS
356 * and we want to connect to only one IP... */ 347 * and we want to connect to only one IP... */
357 server->s_in = &s_in; 348 server->s_in = &s_in;
358 server->host = argv[optind]; 349 bb_lookup_host(&s_in, argv[optind]);
359 bb_lookup_host(&s_in, server->host); 350 s_in.sin_port = bb_lookup_port(port, 21);
360 s_in.sin_port = bb_lookup_port(server->port, 21);
361 if (verbose_flag) { 351 if (verbose_flag) {
362 fprintf(stdout, "Connecting to %s[%s]:%s\n", 352 printf("Connecting to %s[%s]:%d\n",
363 server->host, inet_ntoa(s_in.sin_addr), server->port); 353 argv[optind], inet_ntoa(s_in.sin_addr), ntohs(s_in.sin_port));
364 } 354 }
365 355
366 /* Connect/Setup/Configure the FTP session */ 356 /* Connect/Setup/Configure the FTP session */