aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-11-03 21:20:18 +0000
committerEric Andersen <andersen@codepoet.org>2003-11-03 21:20:18 +0000
commit04d055f4e11469f74bdde38837deefab27edb2e9 (patch)
tree2fb308c0bb612180b7bf8280d1ee5e5a76ac184c /networking
parentf6067beaa9408730c4232620330453e756d6d4f9 (diff)
downloadbusybox-w32-04d055f4e11469f74bdde38837deefab27edb2e9.tar.gz
busybox-w32-04d055f4e11469f74bdde38837deefab27edb2e9.tar.bz2
busybox-w32-04d055f4e11469f74bdde38837deefab27edb2e9.zip
Fix rdate and ftpget/ftpput so they compile with the new xconnect.
I have checked rdate. Someone should also check ftpget/ftpput to be sure they still work.
Diffstat (limited to 'networking')
-rw-r--r--networking/ftpgetput.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index 41f45414a..56223dccb 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -43,6 +43,8 @@
43 43
44#include <netinet/in.h> 44#include <netinet/in.h>
45#include <netdb.h> 45#include <netdb.h>
46#include <sys/socket.h>
47#include <arpa/inet.h>
46 48
47#include "busybox.h" 49#include "busybox.h"
48 50
@@ -51,6 +53,7 @@ typedef struct ftp_host_info_s {
51 char *port; 53 char *port;
52 char *user; 54 char *user;
53 char *password; 55 char *password;
56 struct sockaddr_in *s_in;
54} ftp_host_info_t; 57} ftp_host_info_t;
55 58
56static char verbose_flag; 59static char verbose_flag;
@@ -97,10 +100,9 @@ static int ftpcmd(const char *s1, const char *s2, FILE *stream, char *buf)
97 return atoi(buf); 100 return atoi(buf);
98} 101}
99 102
100static int xconnect_ftpdata(const char *target_host, const char *buf) 103static int xconnect_ftpdata(ftp_host_info_t *server, const char *buf)
101{ 104{
102 char *buf_ptr; 105 char *buf_ptr;
103 char data_port[6];
104 unsigned short port_num; 106 unsigned short port_num;
105 107
106 buf_ptr = strrchr(buf, ','); 108 buf_ptr = strrchr(buf, ',');
@@ -111,8 +113,8 @@ static int xconnect_ftpdata(const char *target_host, const char *buf)
111 *buf_ptr = '\0'; 113 *buf_ptr = '\0';
112 port_num += atoi(buf_ptr + 1) * 256; 114 port_num += atoi(buf_ptr + 1) * 256;
113 115
114 sprintf(data_port, "%d", port_num); 116 server->s_in->sin_port=htons(port_num);
115 return(xconnect(target_host, data_port)); 117 return(xconnect(server->s_in));
116} 118}
117 119
118static FILE *ftp_login(ftp_host_info_t *server) 120static FILE *ftp_login(ftp_host_info_t *server)
@@ -122,7 +124,7 @@ static FILE *ftp_login(ftp_host_info_t *server)
122 int control_fd; 124 int control_fd;
123 125
124 /* Connect to the command socket */ 126 /* Connect to the command socket */
125 control_fd = xconnect(server->host, server->port); 127 control_fd = xconnect(server->s_in);
126 control_stream = fdopen(control_fd, "r+"); 128 control_stream = fdopen(control_fd, "r+");
127 if (control_stream == NULL) { 129 if (control_stream == NULL) {
128 bb_perror_msg_and_die("Couldnt open control stream"); 130 bb_perror_msg_and_die("Couldnt open control stream");
@@ -151,7 +153,8 @@ static FILE *ftp_login(ftp_host_info_t *server)
151} 153}
152 154
153#ifdef CONFIG_FTPGET 155#ifdef CONFIG_FTPGET
154static int ftp_recieve(FILE *control_stream, const char *host, const char *local_path, char *server_path) 156static int ftp_recieve(ftp_host_info_t *server, FILE *control_stream,
157 const char *local_path, char *server_path)
155{ 158{
156 char *filename; 159 char *filename;
157 char *local_file; 160 char *local_file;
@@ -168,7 +171,7 @@ static int ftp_recieve(FILE *control_stream, const char *host, const char *local
168 if (ftpcmd("PASV", NULL, control_stream, buf) != 227) { 171 if (ftpcmd("PASV", NULL, control_stream, buf) != 227) {
169 bb_error_msg_and_die("PASV error: %s", buf + 4); 172 bb_error_msg_and_die("PASV error: %s", buf + 4);
170 } 173 }
171 fd_data = xconnect_ftpdata(host, buf); 174 fd_data = xconnect_ftpdata(server, buf);
172 175
173 if (ftpcmd("SIZE ", server_path, control_stream, buf) == 213) { 176 if (ftpcmd("SIZE ", server_path, control_stream, buf) == 213) {
174 filesize = atol(buf + 4); 177 filesize = atol(buf + 4);
@@ -223,7 +226,8 @@ static int ftp_recieve(FILE *control_stream, const char *host, const char *local
223#endif 226#endif
224 227
225#ifdef CONFIG_FTPPUT 228#ifdef CONFIG_FTPPUT
226static int ftp_send(FILE *control_stream, const char *host, const char *server_path, char *local_path) 229static int ftp_send(ftp_host_info_t *server, FILE *control_stream,
230 const char *server_path, char *local_path)
227{ 231{
228 struct stat sbuf; 232 struct stat sbuf;
229 char buf[512]; 233 char buf[512];
@@ -235,7 +239,7 @@ static int ftp_send(FILE *control_stream, const char *host, const char *server_p
235 if (ftpcmd("PASV", NULL, control_stream, buf) != 227) { 239 if (ftpcmd("PASV", NULL, control_stream, buf) != 227) {
236 bb_error_msg_and_die("PASV error: %s", buf + 4); 240 bb_error_msg_and_die("PASV error: %s", buf + 4);
237 } 241 }
238 fd_data = xconnect_ftpdata(host, buf); 242 fd_data = xconnect_ftpdata(server, buf);
239 243
240 if (ftpcmd("CWD ", server_path, control_stream, buf) != 250) { 244 if (ftpcmd("CWD ", server_path, control_stream, buf) != 250) {
241 bb_error_msg_and_die("CWD error: %s", buf + 4); 245 bb_error_msg_and_die("CWD error: %s", buf + 4);
@@ -291,11 +295,12 @@ int ftpgetput_main(int argc, char **argv)
291 295
292 /* socket to ftp server */ 296 /* socket to ftp server */
293 FILE *control_stream; 297 FILE *control_stream;
298 struct sockaddr_in s_in;
294 299
295 /* continue a prev transfer (-c) */ 300 /* continue a prev transfer (-c) */
296 ftp_host_info_t *server; 301 ftp_host_info_t *server;
297 302
298 int (*ftp_action)(FILE *, const char *, const char *, char *) = NULL; 303 int (*ftp_action)(ftp_host_info_t *, FILE *, const char *, char *) = NULL;
299 304
300 struct option long_options[] = { 305 struct option long_options[] = {
301 {"username", 1, NULL, 'u'}, 306 {"username", 1, NULL, 'u'},
@@ -324,6 +329,7 @@ int ftpgetput_main(int argc, char **argv)
324 /* 329 /*
325 * Decipher the command line 330 * Decipher the command line
326 */ 331 */
332 server->port = "21";
327 while ((opt = getopt_long(argc, argv, "u:p:P:cv", long_options, &option_index)) != EOF) { 333 while ((opt = getopt_long(argc, argv, "u:p:P:cv", long_options, &option_index)) != EOF) {
328 switch(opt) { 334 switch(opt) {
329 case 'c': 335 case 'c':
@@ -353,11 +359,21 @@ int ftpgetput_main(int argc, char **argv)
353 bb_show_usage(); 359 bb_show_usage();
354 } 360 }
355 361
356 /* Connect/Setup/Configure the FTP session */ 362 /* We want to do exactly _one_ DNS lookup, since some
363 * sites (i.e. ftp.us.debian.org) use round-robin DNS
364 * and we want to connect to only one IP... */
365 server->s_in = &s_in;
357 server->host = argv[optind]; 366 server->host = argv[optind];
367 bb_lookup_host(&s_in, server->host, NULL);
368 if (verbose_flag) {
369 fprintf(stdout, "Connecting to %s[%s]:%s\n",
370 server->host, inet_ntoa(s_in.sin_addr), server->port);
371 }
372
373 /* Connect/Setup/Configure the FTP session */
358 control_stream = ftp_login(server); 374 control_stream = ftp_login(server);
359 375
360 return(ftp_action(control_stream, argv[optind], argv[optind + 1], argv[optind + 2])); 376 return(ftp_action(server, control_stream, argv[optind + 1], argv[optind + 2]));
361} 377}
362 378
363/* 379/*