wok view busybox/stuff/busybox-1.10.1-tftp.u @ rev 668

busybox/tftp: add tsize option
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Apr 23 15:25:01 2008 +0000 (2008-04-23)
parents
children 7dfa359d2345
line source
1 --- busybox-1.10.1/networking/tftp.c
2 +++ busybox-1.10.1/networking/tftp.c
3 @@ -121,9 +121,8 @@
4 return blksize;
5 }
7 -static char *tftp_get_blksize(char *buf, int len)
8 +static char *tftp_get_option(const char *option, char *buf, int len)
9 {
10 -#define option "blksize"
11 int opt_val = 0;
12 int opt_found = 0;
13 int k;
14 @@ -155,7 +154,6 @@
15 }
17 return NULL;
18 -#undef option
19 }
21 #endif
22 @@ -165,6 +163,7 @@
23 len_and_sockaddr *peer_lsa,
24 const char *local_file,
25 USE_TFTP(const char *remote_file,)
26 + USE_FEATURE_TFTP_BLOCKSIZE(void *tsize,)
27 int blksize)
28 {
29 #if !ENABLE_TFTP
30 @@ -253,7 +252,7 @@
32 if (!ENABLE_TFTP || our_lsa) {
33 #if ENABLE_FEATURE_TFTP_BLOCKSIZE
34 - if (blksize != TFTP_BLKSIZE_DEFAULT) {
35 + if (blksize != TFTP_BLKSIZE_DEFAULT || tsize) {
36 /* Create and send OACK packet. */
37 /* For the download case, block_nr is still 1 -
38 * we expect 1st ACK from peer to be for (block_nr-1),
39 @@ -313,10 +312,20 @@
41 #if ENABLE_FEATURE_TFTP_BLOCKSIZE
42 add_blksize_opt:
43 - /* add "blksize", <nul>, blksize, <nul> */
44 - strcpy(cp, "blksize");
45 - cp += sizeof("blksize");
46 - cp += snprintf(cp, 6, "%d", blksize) + 1;
47 + if (blksize != TFTP_BLKSIZE_DEFAULT) {
48 + /* add "blksize", <nul>, blksize, <nul> */
49 + strcpy(cp, "blksize");
50 + cp += sizeof("blksize");
51 + cp += snprintf(cp, 6, "%d", blksize) + 1;
52 + }
53 + if (tsize) {
54 + struct stat st;
55 + /* add "tsize", <nul>, size, <nul> */
56 + strcpy(cp, "tsize");
57 + cp += sizeof("tsize");
58 + fstat(local_fd,&st);
59 + cp += snprintf(cp, 8, "%u", (int) st.st_size) + 1;
60 + }
61 #endif
62 /* First packet is built, so skip packet generation */
63 goto send_pkt;
64 @@ -450,7 +459,7 @@
65 /* server seems to support options */
66 char *res;
68 - res = tftp_get_blksize(&rbuf[2], len - 2);
69 + res = tftp_get_option("blksize", &rbuf[2], len - 2);
70 if (res) {
71 blksize = tftp_blksize_check(res, blksize);
72 if (blksize < 0) {
73 @@ -596,6 +605,7 @@
74 result = tftp_protocol(
75 NULL /* our_lsa*/, peer_lsa,
76 local_file, remote_file,
77 + USE_FEATURE_TFTP_BLOCKSIZE(NULL,)
78 blksize);
80 if (result != EXIT_SUCCESS && NOT_LONE_DASH(local_file) && CMD_GET(opt)) {
81 @@ -631,6 +641,7 @@
82 const char *error_msg;
83 int opt, result, opcode;
84 int blksize = TFTP_BLKSIZE_DEFAULT;
85 + USE_FEATURE_TFTP_BLOCKSIZE(char *tsize = NULL;)
87 INIT_G();
89 @@ -676,7 +687,7 @@
90 char *opt_str = mode + sizeof("octet");
91 int opt_len = block_buf + result - opt_str;
92 if (opt_len > 0) {
93 - res = tftp_get_blksize(opt_str, opt_len);
94 + res = tftp_get_option("blksize", opt_str, opt_len);
95 if (res) {
96 blksize = tftp_blksize_check(res, 65564);
97 if (blksize < 0) {
98 @@ -685,6 +696,7 @@
99 goto do_proto;
100 }
101 }
102 + tsize = tftp_get_option("tsize", opt_str, opt_len);
103 }
104 }
105 #endif
106 @@ -710,6 +722,7 @@
107 result = tftp_protocol(
108 our_lsa, peer_lsa,
109 local_file, USE_TFTP(NULL /*remote_file*/,)
110 + USE_FEATURE_TFTP_BLOCKSIZE(tsize,)
111 blksize
112 );