summaryrefslogtreecommitdiff
path: root/networking/tftp.c
diff options
context:
space:
mode:
authorDenis Vlasenko2007-01-12 14:57:37 +0000
committerDenis Vlasenko2007-01-12 14:57:37 +0000
commit2c91652bbcc82c794c26230806058b04f1711033 (patch)
tree1195f7c7fba68bdaf175d85432bf60a60a8c29f0 /networking/tftp.c
parent6536a9b5833febe719988526a095a9cacb8a1042 (diff)
downloadbusybox-2c91652bbcc82c794c26230806058b04f1711033.zip
busybox-2c91652bbcc82c794c26230806058b04f1711033.tar.gz
next part of ipv6-ization. dnsd code is "interesting"...
Diffstat (limited to 'networking/tftp.c')
-rw-r--r--networking/tftp.c40
1 files changed, 14 insertions, 26 deletions
diff --git a/networking/tftp.c b/networking/tftp.c
index 43e835a..9aa87d5 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;
}