summaryrefslogtreecommitdiff
path: root/networking/tftp.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2004-01-17 05:03:31 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2004-01-17 05:03:31 +0000
commit036dbaa082f1974246d1d7d21a8e163559642485 (patch)
tree2488441544ab16f8e08d0955d323019e96ed3d4f /networking/tftp.c
parentb03be7f5677b86acfe2f64b5a57e1f361e257f6c (diff)
downloadbusybox-w32-036dbaa082f1974246d1d7d21a8e163559642485.tar.gz
busybox-w32-036dbaa082f1974246d1d7d21a8e163559642485.tar.bz2
busybox-w32-036dbaa082f1974246d1d7d21a8e163559642485.zip
Modify bb_lookup_port to allow the protocol to be specified, allowing
/etc/services support for inetd, netcat and tftp.
Diffstat (limited to 'networking/tftp.c')
-rw-r--r--networking/tftp.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/networking/tftp.c b/networking/tftp.c
index a1a79a09c..146857686 100644
--- a/networking/tftp.c
+++ b/networking/tftp.c
@@ -138,7 +138,7 @@ static char *tftp_option_get(char *buf, int len, char *option)
138#endif 138#endif
139 139
140static inline int tftp(const int cmd, const struct hostent *host, 140static inline int tftp(const int cmd, const struct hostent *host,
141 const char *remotefile, int localfd, const int port, int tftp_bufsize) 141 const char *remotefile, int localfd, const unsigned short port, int tftp_bufsize)
142{ 142{
143 const int cmd_get = cmd & tftp_cmd_get; 143 const int cmd_get = cmd & tftp_cmd_get;
144 const int cmd_put = cmd & tftp_cmd_put; 144 const int cmd_put = cmd & tftp_cmd_put;
@@ -179,7 +179,7 @@ static inline int tftp(const int cmd, const struct hostent *host,
179 bind(socketfd, (struct sockaddr *)&sa, len); 179 bind(socketfd, (struct sockaddr *)&sa, len);
180 180
181 sa.sin_family = host->h_addrtype; 181 sa.sin_family = host->h_addrtype;
182 sa.sin_port = htons(port); 182 sa.sin_port = port;
183 memcpy(&sa.sin_addr, (struct in_addr *) host->h_addr, 183 memcpy(&sa.sin_addr, (struct in_addr *) host->h_addr,
184 sizeof(sa.sin_addr)); 184 sizeof(sa.sin_addr));
185 185
@@ -332,7 +332,7 @@ static inline int tftp(const int cmd, const struct hostent *host,
332 332
333 timeout = 0; 333 timeout = 0;
334 334
335 if (sa.sin_port == htons(port)) { 335 if (sa.sin_port == port) {
336 sa.sin_port = from.sin_port; 336 sa.sin_port = from.sin_port;
337 } 337 }
338 if (sa.sin_port == from.sin_port) { 338 if (sa.sin_port == from.sin_port) {
@@ -487,7 +487,7 @@ int tftp_main(int argc, char **argv)
487 struct hostent *host = NULL; 487 struct hostent *host = NULL;
488 char *localfile = NULL; 488 char *localfile = NULL;
489 char *remotefile = NULL; 489 char *remotefile = NULL;
490 int port = 69; 490 int port;
491 int cmd = 0; 491 int cmd = 0;
492 int fd = -1; 492 int fd = -1;
493 int flags = 0; 493 int flags = 0;
@@ -564,10 +564,7 @@ int tftp_main(int argc, char **argv)
564 } 564 }
565 565
566 host = xgethostbyname(argv[optind]); 566 host = xgethostbyname(argv[optind]);
567 567 port = bb_lookup_port(argv[optind + 1], "udp", 69);
568 if (optind + 2 == argc) {
569 port = atoi(argv[optind + 1]);
570 }
571 568
572#ifdef CONFIG_FEATURE_TFTP_DEBUG 569#ifdef CONFIG_FEATURE_TFTP_DEBUG
573 printf("using server \"%s\", remotefile \"%s\", " 570 printf("using server \"%s\", remotefile \"%s\", "