wok diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/busybox/stuff/busybox-1.10.1-tftp.u	Wed Apr 23 15:25:01 2008 +0000
     1.3 @@ -0,0 +1,113 @@
     1.4 +--- busybox-1.10.1/networking/tftp.c	
     1.5 ++++ busybox-1.10.1/networking/tftp.c	
     1.6 +@@ -121,9 +121,8 @@
     1.7 + 	return blksize;
     1.8 + }
     1.9 + 
    1.10 +-static char *tftp_get_blksize(char *buf, int len)
    1.11 ++static char *tftp_get_option(const char *option, char *buf, int len)
    1.12 + {
    1.13 +-#define option "blksize"
    1.14 + 	int opt_val = 0;
    1.15 + 	int opt_found = 0;
    1.16 + 	int k;
    1.17 +@@ -155,7 +154,6 @@
    1.18 + 	}
    1.19 + 
    1.20 + 	return NULL;
    1.21 +-#undef option
    1.22 + }
    1.23 + 
    1.24 + #endif
    1.25 +@@ -165,6 +163,7 @@
    1.26 + 		len_and_sockaddr *peer_lsa,
    1.27 + 		const char *local_file,
    1.28 + 		USE_TFTP(const char *remote_file,)
    1.29 ++		USE_FEATURE_TFTP_BLOCKSIZE(void *tsize,)
    1.30 + 		int blksize)
    1.31 + {
    1.32 + #if !ENABLE_TFTP
    1.33 +@@ -253,7 +252,7 @@
    1.34 + 
    1.35 + 	if (!ENABLE_TFTP || our_lsa) {
    1.36 + #if ENABLE_FEATURE_TFTP_BLOCKSIZE
    1.37 +-		if (blksize != TFTP_BLKSIZE_DEFAULT) {
    1.38 ++		if (blksize != TFTP_BLKSIZE_DEFAULT || tsize) {
    1.39 + 			/* Create and send OACK packet. */
    1.40 + 			/* For the download case, block_nr is still 1 -
    1.41 + 			 * we expect 1st ACK from peer to be for (block_nr-1),
    1.42 +@@ -313,10 +312,20 @@
    1.43 + 
    1.44 + #if ENABLE_FEATURE_TFTP_BLOCKSIZE
    1.45 +  add_blksize_opt:
    1.46 +-		/* add "blksize", <nul>, blksize, <nul> */
    1.47 +-		strcpy(cp, "blksize");
    1.48 +-		cp += sizeof("blksize");
    1.49 +-		cp += snprintf(cp, 6, "%d", blksize) + 1;
    1.50 ++		if (blksize != TFTP_BLKSIZE_DEFAULT) {
    1.51 ++			/* add "blksize", <nul>, blksize, <nul> */
    1.52 ++			strcpy(cp, "blksize");
    1.53 ++			cp += sizeof("blksize");
    1.54 ++			cp += snprintf(cp, 6, "%d", blksize) + 1;
    1.55 ++		}
    1.56 ++		if (tsize) {
    1.57 ++			struct stat st;
    1.58 ++			/* add "tsize", <nul>, size, <nul> */
    1.59 ++			strcpy(cp, "tsize");
    1.60 ++			cp += sizeof("tsize");
    1.61 ++			fstat(local_fd,&st);
    1.62 ++			cp += snprintf(cp, 8, "%u", (int) st.st_size) + 1;
    1.63 ++		}
    1.64 + #endif
    1.65 + 		/* First packet is built, so skip packet generation */
    1.66 + 		goto send_pkt;
    1.67 +@@ -450,7 +459,7 @@
    1.68 + 				/* server seems to support options */
    1.69 + 				char *res;
    1.70 + 
    1.71 +-				res = tftp_get_blksize(&rbuf[2], len - 2);
    1.72 ++				res = tftp_get_option("blksize", &rbuf[2], len - 2);
    1.73 + 				if (res) {
    1.74 + 					blksize = tftp_blksize_check(res, blksize);
    1.75 + 					if (blksize < 0) {
    1.76 +@@ -596,6 +605,7 @@
    1.77 + 	result = tftp_protocol(
    1.78 + 			NULL /* our_lsa*/, peer_lsa,
    1.79 + 			local_file, remote_file,
    1.80 ++			USE_FEATURE_TFTP_BLOCKSIZE(NULL,)
    1.81 + 			blksize);
    1.82 + 
    1.83 + 	if (result != EXIT_SUCCESS && NOT_LONE_DASH(local_file) && CMD_GET(opt)) {
    1.84 +@@ -631,6 +641,7 @@
    1.85 + 	const char *error_msg;
    1.86 + 	int opt, result, opcode;
    1.87 + 	int blksize = TFTP_BLKSIZE_DEFAULT;
    1.88 ++	USE_FEATURE_TFTP_BLOCKSIZE(char *tsize = NULL;)
    1.89 + 
    1.90 + 	INIT_G();
    1.91 + 
    1.92 +@@ -676,7 +687,7 @@
    1.93 + 		char *opt_str = mode + sizeof("octet");
    1.94 + 		int opt_len = block_buf + result - opt_str;
    1.95 + 		if (opt_len > 0) {
    1.96 +-			res = tftp_get_blksize(opt_str, opt_len);
    1.97 ++			res = tftp_get_option("blksize", opt_str, opt_len);
    1.98 + 			if (res) {
    1.99 + 				blksize = tftp_blksize_check(res, 65564);
   1.100 + 				if (blksize < 0) {
   1.101 +@@ -685,6 +696,7 @@
   1.102 + 					goto do_proto;
   1.103 + 				}
   1.104 + 			}
   1.105 ++			tsize = tftp_get_option("tsize", opt_str, opt_len);
   1.106 + 		}
   1.107 + 	}
   1.108 + #endif
   1.109 +@@ -710,6 +722,7 @@
   1.110 + 	result = tftp_protocol(
   1.111 + 		our_lsa, peer_lsa,
   1.112 + 		local_file, USE_TFTP(NULL /*remote_file*/,)
   1.113 ++		USE_FEATURE_TFTP_BLOCKSIZE(tsize,)
   1.114 + 		blksize
   1.115 + 	);
   1.116 +