don't fail if BR2_USE_UPDATES tries to update non-checkout
[buildroot.git] / package / busybox / busybox-1.4.1-tftp.patch
blob6faf5c72820bb1ed68a57fa3b3176abfa41e46ce
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
3 @@ -290,7 +290,7 @@
5 /* "new" (ipv4+ipv6) API */
6 typedef struct len_and_sockaddr {
7 - int len;
8 + socklen_t len;
9 union {
10 struct sockaddr sa;
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
14 @@ -132,7 +132,7 @@
15 #if ENABLE_FEATURE_TFTP_GET && ENABLE_FEATURE_TFTP_PUT
16 const int cmd,
17 #endif
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)
23 @@ -149,6 +149,9 @@
25 USE_FEATURE_TFTP_BLOCKSIZE(int want_option_ack = 0;)
27 + unsigned org_port;
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 */
33 @@ -156,7 +159,7 @@
34 char *xbuf = xmalloc(tftp_bufsize += 4);
35 char *rbuf = xmalloc(tftp_bufsize);
37 - port = htons(port);
38 + port = org_port = htons(port);
40 socketfd = xsocket(peer_lsa->sa.sa_family, SOCK_DGRAM, 0);
42 @@ -167,10 +170,10 @@
45 while (1) {
47 cp = xbuf;
49 /* first create the opcode part */
50 + /* (this 16bit store is aligned) */
51 *((uint16_t*)cp) = htons(opcode);
52 cp += 2;
54 @@ -222,6 +225,7 @@
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);
60 cp += 2;
61 block_nr++;
62 @@ -273,28 +277,26 @@
63 FD_SET(socketfd, &rfds);
65 switch (select(socketfd + 1, &rfds, NULL, NULL, &tv)) {
66 - struct sockaddr *from;
67 - socklen_t fromlen;
69 + unsigned from_port;
70 case 1:
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,
78 - from, &fromlen);
79 + &from->sa, &from->len);
80 if (len < 0) {
81 bb_perror_msg("recvfrom");
82 break;
84 -#if ENABLE_FEATURE_IPV6
85 - if (from->sa_family == AF_INET6)
86 - if (((struct sockaddr_in6*)from)->sin6_port != port)
87 - goto recv_again;
88 -#endif
89 - if (from->sa_family == AF_INET)
90 - if (((struct sockaddr_in*)from)->sin_port != port)
91 - goto recv_again;
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 */
97 + port = from_port;
98 + set_nport(peer_lsa, from_port);
99 + }
100 + if (port != from_port)
101 + goto recv_again;
102 timeout = 0;
103 break;
104 case 0:
105 @@ -317,6 +319,7 @@
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] );