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