rev |
line source |
pascal@668
|
1 --- busybox-1.10.1/networking/tftp.c
|
pascal@668
|
2 +++ busybox-1.10.1/networking/tftp.c
|
pascal@672
|
3 @@ -39,7 +39,7 @@
|
pascal@672
|
4 #define TFTP_ERROR 5
|
pascal@672
|
5 #define TFTP_OACK 6
|
pascal@672
|
6
|
pascal@672
|
7 -/* error codes sent over network (we use only 0, 3 and 8) */
|
pascal@672
|
8 +/* error codes sent over network (we use only 0, 1, 3 and 8) */
|
pascal@672
|
9 /* generic (error message is included in the packet) */
|
pascal@672
|
10 #define ERR_UNSPEC 0
|
pascal@672
|
11 #define ERR_NOFILE 1
|
pascal@668
|
12 @@ -121,9 +121,8 @@
|
pascal@668
|
13 return blksize;
|
pascal@668
|
14 }
|
pascal@668
|
15
|
pascal@668
|
16 -static char *tftp_get_blksize(char *buf, int len)
|
pascal@668
|
17 +static char *tftp_get_option(const char *option, char *buf, int len)
|
pascal@668
|
18 {
|
pascal@668
|
19 -#define option "blksize"
|
pascal@668
|
20 int opt_val = 0;
|
pascal@668
|
21 int opt_found = 0;
|
pascal@668
|
22 int k;
|
pascal@668
|
23 @@ -155,7 +154,6 @@
|
pascal@668
|
24 }
|
pascal@668
|
25
|
pascal@668
|
26 return NULL;
|
pascal@668
|
27 -#undef option
|
pascal@668
|
28 }
|
pascal@668
|
29
|
pascal@668
|
30 #endif
|
pascal@668
|
31 @@ -165,6 +163,7 @@
|
pascal@668
|
32 len_and_sockaddr *peer_lsa,
|
pascal@668
|
33 const char *local_file,
|
pascal@668
|
34 USE_TFTP(const char *remote_file,)
|
pascal@668
|
35 + USE_FEATURE_TFTP_BLOCKSIZE(void *tsize,)
|
pascal@668
|
36 int blksize)
|
pascal@668
|
37 {
|
pascal@668
|
38 #if !ENABLE_TFTP
|
pascal@672
|
39 @@ -243,9 +242,9 @@
|
pascal@672
|
40 if (NOT_LONE_DASH(local_file))
|
pascal@672
|
41 local_fd = xopen(local_file, open_mode);
|
pascal@672
|
42 } else {
|
pascal@672
|
43 - local_fd = open_or_warn(local_file, open_mode);
|
pascal@672
|
44 + local_fd = open(local_file, open_mode);
|
pascal@672
|
45 if (local_fd < 0) {
|
pascal@672
|
46 - /*error_pkt_reason = ERR_NOFILE/ERR_ACCESS?*/
|
pascal@672
|
47 + error_pkt_reason = ERR_NOFILE;
|
pascal@672
|
48 strcpy(error_pkt_str, "can't open file");
|
pascal@672
|
49 goto send_err_pkt;
|
pascal@672
|
50 }
|
pascal@668
|
51 @@ -253,7 +252,7 @@
|
pascal@668
|
52
|
pascal@668
|
53 if (!ENABLE_TFTP || our_lsa) {
|
pascal@668
|
54 #if ENABLE_FEATURE_TFTP_BLOCKSIZE
|
pascal@668
|
55 - if (blksize != TFTP_BLKSIZE_DEFAULT) {
|
pascal@668
|
56 + if (blksize != TFTP_BLKSIZE_DEFAULT || tsize) {
|
pascal@668
|
57 /* Create and send OACK packet. */
|
pascal@668
|
58 /* For the download case, block_nr is still 1 -
|
pascal@668
|
59 * we expect 1st ACK from peer to be for (block_nr-1),
|
pascal@668
|
60 @@ -313,10 +312,20 @@
|
pascal@668
|
61
|
pascal@668
|
62 #if ENABLE_FEATURE_TFTP_BLOCKSIZE
|
pascal@668
|
63 add_blksize_opt:
|
pascal@668
|
64 - /* add "blksize", <nul>, blksize, <nul> */
|
pascal@668
|
65 - strcpy(cp, "blksize");
|
pascal@668
|
66 - cp += sizeof("blksize");
|
pascal@668
|
67 - cp += snprintf(cp, 6, "%d", blksize) + 1;
|
pascal@668
|
68 + if (tsize) {
|
pascal@668
|
69 + struct stat st;
|
pascal@668
|
70 + /* add "tsize", <nul>, size, <nul> */
|
pascal@668
|
71 + strcpy(cp, "tsize");
|
pascal@668
|
72 + cp += sizeof("tsize");
|
pascal@668
|
73 + fstat(local_fd,&st);
|
pascal@672
|
74 + cp += snprintf(cp, 10, "%u", (int) st.st_size) + 1;
|
pascal@672
|
75 + }
|
pascal@672
|
76 + if (blksize != TFTP_BLKSIZE_DEFAULT) {
|
pascal@672
|
77 + /* add "blksize", <nul>, blksize, <nul> */
|
pascal@672
|
78 + strcpy(cp, "blksize");
|
pascal@672
|
79 + cp += sizeof("blksize");
|
pascal@672
|
80 + cp += snprintf(cp, 6, "%d", blksize) + 1;
|
pascal@668
|
81 + }
|
pascal@668
|
82 #endif
|
pascal@668
|
83 /* First packet is built, so skip packet generation */
|
pascal@668
|
84 goto send_pkt;
|
pascal@668
|
85 @@ -450,7 +459,7 @@
|
pascal@668
|
86 /* server seems to support options */
|
pascal@668
|
87 char *res;
|
pascal@668
|
88
|
pascal@668
|
89 - res = tftp_get_blksize(&rbuf[2], len - 2);
|
pascal@668
|
90 + res = tftp_get_option("blksize", &rbuf[2], len - 2);
|
pascal@668
|
91 if (res) {
|
pascal@668
|
92 blksize = tftp_blksize_check(res, blksize);
|
pascal@668
|
93 if (blksize < 0) {
|
pascal@668
|
94 @@ -596,6 +605,7 @@
|
pascal@668
|
95 result = tftp_protocol(
|
pascal@668
|
96 NULL /* our_lsa*/, peer_lsa,
|
pascal@668
|
97 local_file, remote_file,
|
pascal@668
|
98 + USE_FEATURE_TFTP_BLOCKSIZE(NULL,)
|
pascal@668
|
99 blksize);
|
pascal@668
|
100
|
pascal@668
|
101 if (result != EXIT_SUCCESS && NOT_LONE_DASH(local_file) && CMD_GET(opt)) {
|
pascal@668
|
102 @@ -631,6 +641,7 @@
|
pascal@668
|
103 const char *error_msg;
|
pascal@668
|
104 int opt, result, opcode;
|
pascal@668
|
105 int blksize = TFTP_BLKSIZE_DEFAULT;
|
pascal@668
|
106 + USE_FEATURE_TFTP_BLOCKSIZE(char *tsize = NULL;)
|
pascal@668
|
107
|
pascal@668
|
108 INIT_G();
|
pascal@668
|
109
|
pascal@668
|
110 @@ -676,7 +687,7 @@
|
pascal@668
|
111 char *opt_str = mode + sizeof("octet");
|
pascal@668
|
112 int opt_len = block_buf + result - opt_str;
|
pascal@668
|
113 if (opt_len > 0) {
|
pascal@668
|
114 - res = tftp_get_blksize(opt_str, opt_len);
|
pascal@668
|
115 + res = tftp_get_option("blksize", opt_str, opt_len);
|
pascal@668
|
116 if (res) {
|
pascal@668
|
117 blksize = tftp_blksize_check(res, 65564);
|
pascal@668
|
118 if (blksize < 0) {
|
pascal@668
|
119 @@ -685,6 +696,7 @@
|
pascal@668
|
120 goto do_proto;
|
pascal@668
|
121 }
|
pascal@668
|
122 }
|
pascal@668
|
123 + tsize = tftp_get_option("tsize", opt_str, opt_len);
|
pascal@668
|
124 }
|
pascal@668
|
125 }
|
pascal@668
|
126 #endif
|
pascal@668
|
127 @@ -710,6 +722,7 @@
|
pascal@668
|
128 result = tftp_protocol(
|
pascal@668
|
129 our_lsa, peer_lsa,
|
pascal@668
|
130 local_file, USE_TFTP(NULL /*remote_file*/,)
|
pascal@668
|
131 + USE_FEATURE_TFTP_BLOCKSIZE(tsize,)
|
pascal@668
|
132 blksize
|
pascal@668
|
133 );
|
pascal@668
|
134
|