From 036dbaa082f1974246d1d7d21a8e163559642485 Mon Sep 17 00:00:00 2001 From: Glenn L McGrath Date: Sat, 17 Jan 2004 05:03:31 +0000 Subject: Modify bb_lookup_port to allow the protocol to be specified, allowing /etc/services support for inetd, netcat and tftp. --- networking/tftp.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'networking/tftp.c') 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) #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\", " -- cgit v1.2.3