aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2019-03-03 14:48:55 +0100
committerReiner Herrmann <reiner@reiner-h.de>2019-03-03 14:48:55 +0100
commit150d6635b5ed86ecdd517942cb09be444a1b132e (patch)
tree177ea00671a249174e03999bc4530edc51c7e0ae
parent205beb79e1642a92371c17b53c24c064290e5612 (diff)
Make requested blksize configurable
-rw-r--r--README1
-rw-r--r--src/tftpc.rs14
2 files changed, 14 insertions, 1 deletions
diff --git a/README b/README
index 318917b..97b7f70 100644
--- a/README
+++ b/README
@@ -26,6 +26,7 @@ Client:
-h, --help display usage information
-g, --get FILE download file from remote server
-p, --put FILE upload file to remote server
+ -b, --blksize SIZE negotiate a different block size (default: 1428)
Server:
diff --git a/src/tftpc.rs b/src/tftpc.rs
index 294475c..a006962 100644
--- a/src/tftpc.rs
+++ b/src/tftpc.rs
@@ -24,6 +24,7 @@ struct Configuration {
mode: Mode,
filename: PathBuf,
remote: SocketAddr,
+ blksize: usize,
}
struct Tftpc {
@@ -91,7 +92,7 @@ impl Tftpc {
}
fn append_option_req(&self, buf: &mut Vec<u8>, fsize: u64) {
- self.tftp.append_option(buf, "blksize", &format!("{}", 1428));
+ self.tftp.append_option(buf, "blksize", &format!("{}", self.conf.blksize));
self.tftp.append_option(buf, "timeout", &format!("{}", 3));
self.tftp.append_option(buf, "tsize", &format!("{}", fsize));
}
@@ -230,11 +231,13 @@ fn parse_commandline<'a>(args: &'a Vec<String>) -> Result<Configuration, &'a str
let program = args[0].clone();
let mut mode = None;
let mut filename = None;
+ let mut blksize = 1428;
let mut opts = Options::new();
opts.optflag("h", "help", "display usage information");
opts.optopt("g", "get", "download file from remote server", "FILE");
opts.optopt("p", "put", "upload file to remote server", "FILE");
+ opts.optopt("b", "blksize", format!("negotiate a different block size (default: {})", blksize).as_ref(), "SIZE");
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(err) => {
@@ -281,10 +284,19 @@ fn parse_commandline<'a>(args: &'a Vec<String>) -> Result<Configuration, &'a str
}
};
+ blksize = match matches.opt_get_default::<usize>("b", blksize) {
+ Ok(b) => b,
+ Err(err) => {
+ usage(opts, program, Some(err.to_string()));
+ return Err("blksize");
+ }
+ };
+
Ok(Configuration{
mode: mode.unwrap(),
filename: filename.unwrap(),
remote: remote.unwrap(),
+ blksize: blksize,
})
}