wok-6.x 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 | edd31fe73ba8 |
children | 3f64a45a68c2 |
files | busybox/receipt busybox/stuff/busybox-1.10.1-tftp.u |
line diff
1.1 --- a/busybox/receipt Wed Apr 23 12:19:27 2008 +0200 1.2 +++ b/busybox/receipt Wed Apr 23 15:25:01 2008 +0000 1.3 @@ -22,6 +22,7 @@ 1.4 patch -p1 < ../stuff/$PACKAGE-$VERSION-cpio-mkdir.u 1.5 patch -p1 < ../stuff/$PACKAGE-$VERSION-cpio-mtime.u 1.6 patch -p1 < ../stuff/$PACKAGE-$VERSION-unlzma.u 1.7 + patch -p1 < ../stuff/$PACKAGE-$VERSION-tftp.u 1.8 cp ../stuff/$PACKAGE-$VERSION.config .config 1.9 make oldconfig 1.10 make && make install
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/busybox/stuff/busybox-1.10.1-tftp.u Wed Apr 23 15:25:01 2008 +0000 2.3 @@ -0,0 +1,113 @@ 2.4 +--- busybox-1.10.1/networking/tftp.c 2.5 ++++ busybox-1.10.1/networking/tftp.c 2.6 +@@ -121,9 +121,8 @@ 2.7 + return blksize; 2.8 + } 2.9 + 2.10 +-static char *tftp_get_blksize(char *buf, int len) 2.11 ++static char *tftp_get_option(const char *option, char *buf, int len) 2.12 + { 2.13 +-#define option "blksize" 2.14 + int opt_val = 0; 2.15 + int opt_found = 0; 2.16 + int k; 2.17 +@@ -155,7 +154,6 @@ 2.18 + } 2.19 + 2.20 + return NULL; 2.21 +-#undef option 2.22 + } 2.23 + 2.24 + #endif 2.25 +@@ -165,6 +163,7 @@ 2.26 + len_and_sockaddr *peer_lsa, 2.27 + const char *local_file, 2.28 + USE_TFTP(const char *remote_file,) 2.29 ++ USE_FEATURE_TFTP_BLOCKSIZE(void *tsize,) 2.30 + int blksize) 2.31 + { 2.32 + #if !ENABLE_TFTP 2.33 +@@ -253,7 +252,7 @@ 2.34 + 2.35 + if (!ENABLE_TFTP || our_lsa) { 2.36 + #if ENABLE_FEATURE_TFTP_BLOCKSIZE 2.37 +- if (blksize != TFTP_BLKSIZE_DEFAULT) { 2.38 ++ if (blksize != TFTP_BLKSIZE_DEFAULT || tsize) { 2.39 + /* Create and send OACK packet. */ 2.40 + /* For the download case, block_nr is still 1 - 2.41 + * we expect 1st ACK from peer to be for (block_nr-1), 2.42 +@@ -313,10 +312,20 @@ 2.43 + 2.44 + #if ENABLE_FEATURE_TFTP_BLOCKSIZE 2.45 + add_blksize_opt: 2.46 +- /* add "blksize", <nul>, blksize, <nul> */ 2.47 +- strcpy(cp, "blksize"); 2.48 +- cp += sizeof("blksize"); 2.49 +- cp += snprintf(cp, 6, "%d", blksize) + 1; 2.50 ++ if (blksize != TFTP_BLKSIZE_DEFAULT) { 2.51 ++ /* add "blksize", <nul>, blksize, <nul> */ 2.52 ++ strcpy(cp, "blksize"); 2.53 ++ cp += sizeof("blksize"); 2.54 ++ cp += snprintf(cp, 6, "%d", blksize) + 1; 2.55 ++ } 2.56 ++ if (tsize) { 2.57 ++ struct stat st; 2.58 ++ /* add "tsize", <nul>, size, <nul> */ 2.59 ++ strcpy(cp, "tsize"); 2.60 ++ cp += sizeof("tsize"); 2.61 ++ fstat(local_fd,&st); 2.62 ++ cp += snprintf(cp, 8, "%u", (int) st.st_size) + 1; 2.63 ++ } 2.64 + #endif 2.65 + /* First packet is built, so skip packet generation */ 2.66 + goto send_pkt; 2.67 +@@ -450,7 +459,7 @@ 2.68 + /* server seems to support options */ 2.69 + char *res; 2.70 + 2.71 +- res = tftp_get_blksize(&rbuf[2], len - 2); 2.72 ++ res = tftp_get_option("blksize", &rbuf[2], len - 2); 2.73 + if (res) { 2.74 + blksize = tftp_blksize_check(res, blksize); 2.75 + if (blksize < 0) { 2.76 +@@ -596,6 +605,7 @@ 2.77 + result = tftp_protocol( 2.78 + NULL /* our_lsa*/, peer_lsa, 2.79 + local_file, remote_file, 2.80 ++ USE_FEATURE_TFTP_BLOCKSIZE(NULL,) 2.81 + blksize); 2.82 + 2.83 + if (result != EXIT_SUCCESS && NOT_LONE_DASH(local_file) && CMD_GET(opt)) { 2.84 +@@ -631,6 +641,7 @@ 2.85 + const char *error_msg; 2.86 + int opt, result, opcode; 2.87 + int blksize = TFTP_BLKSIZE_DEFAULT; 2.88 ++ USE_FEATURE_TFTP_BLOCKSIZE(char *tsize = NULL;) 2.89 + 2.90 + INIT_G(); 2.91 + 2.92 +@@ -676,7 +687,7 @@ 2.93 + char *opt_str = mode + sizeof("octet"); 2.94 + int opt_len = block_buf + result - opt_str; 2.95 + if (opt_len > 0) { 2.96 +- res = tftp_get_blksize(opt_str, opt_len); 2.97 ++ res = tftp_get_option("blksize", opt_str, opt_len); 2.98 + if (res) { 2.99 + blksize = tftp_blksize_check(res, 65564); 2.100 + if (blksize < 0) { 2.101 +@@ -685,6 +696,7 @@ 2.102 + goto do_proto; 2.103 + } 2.104 + } 2.105 ++ tsize = tftp_get_option("tsize", opt_str, opt_len); 2.106 + } 2.107 + } 2.108 + #endif 2.109 +@@ -710,6 +722,7 @@ 2.110 + result = tftp_protocol( 2.111 + our_lsa, peer_lsa, 2.112 + local_file, USE_TFTP(NULL /*remote_file*/,) 2.113 ++ USE_FEATURE_TFTP_BLOCKSIZE(tsize,) 2.114 + blksize 2.115 + ); 2.116 +