From b35a7b90949e19afca22c8cf5699bdc112ae2f6a Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Sun, 24 Mar 2019 16:33:33 +0100 Subject: Support blksize2 option (non-standard) --- README | 3 +++ 1 file changed, 3 insertions(+) (limited to 'README') diff --git a/README b/README index 08b08c7..44d584b 100644 --- a/README +++ b/README @@ -10,6 +10,9 @@ Currently supported: - RFC 2348 (Blocksize Option) - RFC 2349 (Timeout Interval and Transfer Size Options) +Non-standard options: +- blksize2: block size as a power of 2 + Use cargo to build the binaries (output dir is target/release/): $ cargo build --release -- cgit v1.2.3 From 37a011424d9f19e1801b25460d7a2db95220948e Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Sun, 24 Mar 2019 16:43:22 +0100 Subject: Support utimeout option (non-standard) --- README | 1 + src/lib.rs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'README') diff --git a/README b/README index 44d584b..3045fcd 100644 --- a/README +++ b/README @@ -12,6 +12,7 @@ Currently supported: Non-standard options: - blksize2: block size as a power of 2 +- utimeout: timeout in microseconds Use cargo to build the binaries (output dir is target/release/): diff --git a/src/lib.rs b/src/lib.rs index ec092a4..61e7059 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ pub enum Mode { #[derive(Clone, Copy)] pub struct TftpOptions { blksize: usize, - timeout: u8, + timeout: Duration, tsize: u64, } @@ -53,7 +53,7 @@ pub struct Tftp { fn default_options() -> TftpOptions { TftpOptions { blksize: 512, - timeout: 3, + timeout: Duration::from_secs(3), tsize: 0, } } @@ -333,7 +333,14 @@ impl Tftp { }, "timeout" => match val.parse() { Ok(t) if t >= 1 => { - self.options.timeout = t; + self.options.timeout = Duration::from_secs(t); + true + } + _ => false, + }, + "utimeout" => match val.parse() { + Ok(t) if t >= 1 => { + self.options.timeout = Duration::from_micros(t); true } _ => false, @@ -349,7 +356,7 @@ impl Tftp { } }); - sock.set_read_timeout(Some(Duration::from_secs(u64::from(self.options.timeout))))?; + sock.set_read_timeout(Some(self.options.timeout))?; Ok(()) } -- cgit v1.2.3 From 16c6dd8f7116271508974d8acf04da1f1bf0afc9 Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Thu, 29 Aug 2019 21:48:44 +0200 Subject: Drop -d parameter and allow appending directory at end of command line --- README | 4 +--- src/tftpd.rs | 13 +++---------- test.sh | 2 +- 3 files changed, 5 insertions(+), 14 deletions(-) (limited to 'README') diff --git a/README b/README index 3045fcd..e6a5f44 100644 --- a/README +++ b/README @@ -39,12 +39,10 @@ Server: $ ./rtftpd --help RusTFTP - ./rtftpd [options] + ./rtftpd [options] [directory] Options: -h, --help display usage information - -d, --directory DIRECTORY - directory to serve (default: current directory) -p, --port PORT port to listen on (default: 69) -u, --uid UID user id to run as (default: 65534) -g, --gid GID group id to run as (default: 65534) diff --git a/src/tftpd.rs b/src/tftpd.rs index 5342145..102063d 100644 --- a/src/tftpd.rs +++ b/src/tftpd.rs @@ -306,7 +306,7 @@ fn usage(opts: &Options, program: &str, error: Option) { println!("{}\n", err); } let version = rtftp::VERSION.unwrap_or(""); - println!("{}", opts.usage(format!("RusTFTP {}\n\n{} [options]", version, program).as_str())); + println!("{}", opts.usage(format!("RusTFTP {}\n\n{} [options] [directory]", version, program).as_str())); } fn parse_commandline(args: &[String]) -> Option { @@ -314,7 +314,6 @@ fn parse_commandline(args: &[String]) -> Option { let mut conf: Configuration = Default::default(); let mut opts = Options::new(); opts.optflag("h", "help", "display usage information"); - opts.optopt("d", "directory", "directory to serve (default: current directory)", "DIRECTORY"); opts.optopt("p", "port", format!("port to listen on (default: {})", conf.port).as_ref(), "PORT"); opts.optopt("u", "uid", format!("user id to run as (default: {})", conf.uid).as_ref(), "UID"); opts.optopt("g", "gid", format!("group id to run as (default: {})", conf.gid).as_ref(), "GID"); @@ -341,14 +340,8 @@ fn parse_commandline(args: &[String]) -> Option { usage(&opts, &program, Some(String::from("Only one of r (read-only) and w (write-only) allowed"))); return None; } - if matches.opt_present("d") { - conf.dir = match matches.opt_str("d") { - Some(d) => Path::new(&d).to_path_buf(), - None => { - usage(&opts, &program, None); - return None; - } - }; + if matches.free.len() > 0 { + conf.dir = Path::new(&matches.free[0]).to_path_buf(); } Some(conf) diff --git a/test.sh b/test.sh index 61fa6d0..7ee1800 100755 --- a/test.sh +++ b/test.sh @@ -52,7 +52,7 @@ tftpc() { } rtftpd() { - $SSD --background --exec "$RTFTPD" --start -- -p $PORT -d "$SERVERDIR" 1>/dev/null + $SSD --background --exec "$RTFTPD" --start -- -p $PORT "$SERVERDIR" 1>/dev/null } rtftpc() { -- cgit v1.2.3