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