From 2c91652bbcc82c794c26230806058b04f1711033 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Fri, 12 Jan 2007 14:57:37 +0000 Subject: next part of ipv6-ization. dnsd code is "interesting"... --- networking/tftp.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) (limited to 'networking/tftp.c') diff --git a/networking/tftp.c b/networking/tftp.c index 43e835a5d..9aa87d57e 100644 --- a/networking/tftp.c +++ b/networking/tftp.c @@ -240,10 +240,8 @@ static int tftp( } } - /* send packet */ - timeout = TFTP_NUM_RETRIES; /* re-initialize */ do { len = cp - xbuf; @@ -260,13 +258,12 @@ static int tftp( break; } - if (finished && (opcode == TFTP_ACK)) { break; } /* receive packet */ - + recv_again: tv.tv_sec = TFTP_TIMEOUT; tv.tv_usec = 0; @@ -288,25 +285,16 @@ static int tftp( bb_perror_msg("recvfrom"); break; } - timeout = 0; - if (from->sa_family == peer_lsa->sa.sa_family) { #if ENABLE_FEATURE_IPV6 - if (from->sa_family == AF_INET6 - && ((struct sockaddr_in6*)from)->sin6_port == port - ) - break; + if (from->sa_family == AF_INET6) + if (((struct sockaddr_in6*)from)->sin6_port != port) + goto recv_again; #endif - /* Non-internet sockets are ok */ - if (from->sa_family != AF_INET) - break; - if (((struct sockaddr_in*)from)->sin_port == port) - break; - } - /* family doesn't match, or - * it is INET[v6] and port doesn't match - - * fall-through for bad packets! - * (discard the packet - treat as timeout) */ - timeout = TFTP_NUM_RETRIES; + if (from->sa_family == AF_INET) + if (((struct sockaddr_in*)from)->sin_port != port) + goto recv_again; + timeout = 0; + break; case 0: bb_error_msg("timeout"); timeout--; @@ -436,11 +424,11 @@ static int tftp( } } -#if ENABLE_FEATURE_CLEAN_UP - close(socketfd); - free(xbuf); - free(rbuf); -#endif + if (ENABLE_FEATURE_CLEAN_UP) { + close(socketfd); + free(xbuf); + free(rbuf); + } return finished ? EXIT_SUCCESS : EXIT_FAILURE; } -- cgit v1.2.3