1 --- busybox-1.4.1/include/libbb.h Wed Jan 24 22:34:48 2007
2 +++ busybox-1.4.1-tftp/include/libbb.h Sat Mar 3 00:02:34 2007
5 /* "new" (ipv4+ipv6) API */
6 typedef struct len_and_sockaddr {
11 struct sockaddr_in sin;
12 --- busybox-1.4.1/networking/tftp.c Wed Jan 24 22:34:34 2007
13 +++ busybox-1.4.1-tftp/networking/tftp.c Sat Mar 3 00:02:56 2007
15 #if ENABLE_FEATURE_TFTP_GET && ENABLE_FEATURE_TFTP_PUT
18 - const len_and_sockaddr *peer_lsa,
19 + len_and_sockaddr *peer_lsa,
20 const char *remotefile, const int localfd,
21 unsigned port, int tftp_bufsize)
25 USE_FEATURE_TFTP_BLOCKSIZE(int want_option_ack = 0;)
28 + len_and_sockaddr *const from = alloca(offsetof(len_and_sockaddr, sa) + peer_lsa->len);
30 /* Can't use RESERVE_CONFIG_BUFFER here since the allocation
31 * size varies meaning BUFFERS_GO_ON_STACK would fail */
32 /* We must keep the transmit and receive buffers seperate */
34 char *xbuf = xmalloc(tftp_bufsize += 4);
35 char *rbuf = xmalloc(tftp_bufsize);
38 + port = org_port = htons(port);
40 socketfd = xsocket(peer_lsa->sa.sa_family, SOCK_DGRAM, 0);
49 /* first create the opcode part */
50 + /* (this 16bit store is aligned) */
51 *((uint16_t*)cp) = htons(opcode);
55 /* add ack and data */
57 if (CMD_GET(cmd) ? (opcode == TFTP_ACK) : (opcode == TFTP_DATA)) {
58 + /* TODO: unaligned access! */
59 *((uint16_t*)cp) = htons(block_nr);
63 FD_SET(socketfd, &rfds);
65 switch (select(socketfd + 1, &rfds, NULL, NULL, &tv)) {
66 - struct sockaddr *from;
71 - fromlen = peer_lsa->len;
72 - from = alloca(fromlen);
73 - memset(from, 0, fromlen);
75 + from->len = peer_lsa->len;
76 + memset(&from->sa, 0, peer_lsa->len);
77 len = recvfrom(socketfd, rbuf, tftp_bufsize, 0,
79 + &from->sa, &from->len);
81 bb_perror_msg("recvfrom");
84 -#if ENABLE_FEATURE_IPV6
85 - if (from->sa_family == AF_INET6)
86 - if (((struct sockaddr_in6*)from)->sin6_port != port)
89 - if (from->sa_family == AF_INET)
90 - if (((struct sockaddr_in*)from)->sin_port != port)
92 + from_port = get_nport(from);
93 + if (port == org_port) {
94 + /* Our first query went to port 69
95 + * but reply will come from different one.
96 + * Remember and use this new port */
98 + set_nport(peer_lsa, from_port);
100 + if (port != from_port)
108 /* process received packet */
109 + /* (both accesses seems to be aligned) */
111 opcode = ntohs( ((uint16_t*)rbuf)[0] );
112 tmp = ntohs( ((uint16_t*)rbuf)[1] );