diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-11-03 21:20:18 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-11-03 21:20:18 +0000 |
commit | 04d055f4e11469f74bdde38837deefab27edb2e9 (patch) | |
tree | 2fb308c0bb612180b7bf8280d1ee5e5a76ac184c | |
parent | f6067beaa9408730c4232620330453e756d6d4f9 (diff) | |
download | busybox-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.
-rw-r--r-- | include/libbb.h | 4 | ||||
-rw-r--r-- | libbb/xconnect.c | 4 | ||||
-rw-r--r-- | networking/ftpgetput.c | 40 | ||||
-rw-r--r-- | util-linux/rdate.c | 4 |
4 files changed, 34 insertions, 18 deletions
diff --git a/include/libbb.h b/include/libbb.h index 53062de4d..945dc95bc 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -295,8 +295,8 @@ extern struct hostent *xgethostbyname2(const char *name, int af); | |||
295 | extern int create_icmp_socket(void); | 295 | extern int create_icmp_socket(void); |
296 | extern int create_icmp6_socket(void); | 296 | extern int create_icmp6_socket(void); |
297 | extern int xconnect(struct sockaddr_in *s_addr); | 297 | extern int xconnect(struct sockaddr_in *s_addr); |
298 | extern int bb_getport(char *port); | 298 | extern int bb_getport(const char *port); |
299 | extern void bb_lookup_host(struct sockaddr_in *s_in, char *host, char *port); | 299 | extern void bb_lookup_host(struct sockaddr_in *s_in, const char *host, const char *port); |
300 | 300 | ||
301 | //#warning wrap this? | 301 | //#warning wrap this? |
302 | char *dirname (char *path); | 302 | char *dirname (char *path); |
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index 27459791e..2cbc8400b 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
@@ -18,7 +18,7 @@ | |||
18 | #include <arpa/inet.h> | 18 | #include <arpa/inet.h> |
19 | #include "libbb.h" | 19 | #include "libbb.h" |
20 | 20 | ||
21 | int bb_getport(char *port) | 21 | int bb_getport(const char *port) |
22 | { | 22 | { |
23 | int port_nr; | 23 | int port_nr; |
24 | char *endptr; | 24 | char *endptr; |
@@ -41,7 +41,7 @@ int bb_getport(char *port) | |||
41 | return port_nr; | 41 | return port_nr; |
42 | } | 42 | } |
43 | 43 | ||
44 | void bb_lookup_host(struct sockaddr_in *s_in, char *host, char *port) | 44 | void bb_lookup_host(struct sockaddr_in *s_in, const char *host, const char *port) |
45 | { | 45 | { |
46 | struct hostent *he; | 46 | struct hostent *he; |
47 | 47 | ||
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 | ||
56 | static char verbose_flag; | 59 | static 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 | ||
100 | static int xconnect_ftpdata(const char *target_host, const char *buf) | 103 | static 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 | ||
118 | static FILE *ftp_login(ftp_host_info_t *server) | 120 | static 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 |
154 | static int ftp_recieve(FILE *control_stream, const char *host, const char *local_path, char *server_path) | 156 | static 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 |
226 | static int ftp_send(FILE *control_stream, const char *host, const char *server_path, char *local_path) | 229 | static 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 | /* |
diff --git a/util-linux/rdate.c b/util-linux/rdate.c index a822f42ff..c9a7ffeab 100644 --- a/util-linux/rdate.c +++ b/util-linux/rdate.c | |||
@@ -47,7 +47,7 @@ static void socket_timeout(int sig) | |||
47 | static time_t askremotedate(const char *host) | 47 | static time_t askremotedate(const char *host) |
48 | { | 48 | { |
49 | unsigned long int nett, localt; | 49 | unsigned long int nett, localt; |
50 | struct sockaddr_in addr s_in; | 50 | struct sockaddr_in s_in; |
51 | int fd; | 51 | int fd; |
52 | 52 | ||
53 | bb_lookup_host(&s_in, host, "time"); | 53 | bb_lookup_host(&s_in, host, "time"); |
@@ -56,7 +56,7 @@ static time_t askremotedate(const char *host) | |||
56 | alarm(10); | 56 | alarm(10); |
57 | signal(SIGALRM, socket_timeout); | 57 | signal(SIGALRM, socket_timeout); |
58 | 58 | ||
59 | fd = xconnect(s_in); | 59 | fd = xconnect(&s_in); |
60 | 60 | ||
61 | if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */ | 61 | if (safe_read(fd, (void *)&nett, 4) != 4) /* read time from server */ |
62 | bb_error_msg_and_die("%s did not send the complete time", host); | 62 | bb_error_msg_and_die("%s did not send the complete time", host); |