diff options
author | Glenn L McGrath | 2004-01-17 05:03:31 +0000 |
---|---|---|
committer | Glenn L McGrath | 2004-01-17 05:03:31 +0000 |
commit | 036dbaa082f1974246d1d7d21a8e163559642485 (patch) | |
tree | 2488441544ab16f8e08d0955d323019e96ed3d4f /networking/tftp.c | |
parent | b03be7f5677b86acfe2f64b5a57e1f361e257f6c (diff) | |
download | busybox-036dbaa082f1974246d1d7d21a8e163559642485.zip busybox-036dbaa082f1974246d1d7d21a8e163559642485.tar.gz |
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.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/networking/tftp.c b/networking/tftp.c index a1a79a0..1468576 100644 --- a/networking/tftp.c +++ b/networking/tftp.c @@ -138,7 +138,7 @@ static char *tftp_option_get(char *buf, int len, char *option) #endif static inline int tftp(const int cmd, const struct hostent *host, - const char *remotefile, int localfd, const int port, int tftp_bufsize) + const char *remotefile, int localfd, const unsigned short port, int tftp_bufsize) { const int cmd_get = cmd & tftp_cmd_get; const int cmd_put = cmd & tftp_cmd_put; @@ -179,7 +179,7 @@ static inline int tftp(const int cmd, const struct hostent *host, bind(socketfd, (struct sockaddr *)&sa, len); sa.sin_family = host->h_addrtype; - sa.sin_port = htons(port); + sa.sin_port = port; memcpy(&sa.sin_addr, (struct in_addr *) host->h_addr, sizeof(sa.sin_addr)); @@ -332,7 +332,7 @@ static inline int tftp(const int cmd, const struct hostent *host, timeout = 0; - if (sa.sin_port == htons(port)) { + if (sa.sin_port == port) { sa.sin_port = from.sin_port; } if (sa.sin_port == from.sin_port) { @@ -487,7 +487,7 @@ int tftp_main(int argc, char **argv) struct hostent *host = NULL; char *localfile = NULL; char *remotefile = NULL; - int port = 69; + int port; int cmd = 0; int fd = -1; int flags = 0; @@ -564,10 +564,7 @@ int tftp_main(int argc, char **argv) } host = xgethostbyname(argv[optind]); - - if (optind + 2 == argc) { - port = atoi(argv[optind + 1]); - } + port = bb_lookup_port(argv[optind + 1], "udp", 69); #ifdef CONFIG_FEATURE_TFTP_DEBUG printf("using server \"%s\", remotefile \"%s\", " |