diff options
| author | Reiner Herrmann <reiner@reiner-h.de> | 2019-03-03 14:02:17 +0100 |
|---|---|---|
| committer | Reiner Herrmann <reiner@reiner-h.de> | 2019-03-03 14:02:17 +0100 |
| commit | a62e0c10aed3639aedb0c228c7685926b391aae8 (patch) | |
| tree | 3b37b1de5cc323d1755005439084aa6ff0a39e7c /src/tftpc.rs | |
| parent | 960ea9072b03cf265a113c2ff978c0d2fb4735a3 (diff) | |
Implement Transfer Size Option (RFC 2349, part 2)
Diffstat (limited to 'src/tftpc.rs')
| -rw-r--r-- | src/tftpc.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/tftpc.rs b/src/tftpc.rs index fdc3853..294475c 100644 --- a/src/tftpc.rs +++ b/src/tftpc.rs @@ -90,9 +90,10 @@ impl Tftpc { Some(remote) } - fn append_option_req(&self, buf: &mut Vec<u8>) { + fn append_option_req(&self, buf: &mut Vec<u8>, fsize: u64) { self.tftp.append_option(buf, "blksize", &format!("{}", 1428)); self.tftp.append_option(buf, "timeout", &format!("{}", 3)); + self.tftp.append_option(buf, "tsize", &format!("{}", fsize)); } fn handle_wrq(&mut self, sock: &UdpSocket) -> Result<(), io::Error> { @@ -107,11 +108,18 @@ impl Tftpc { } None => return Err(io::Error::new(io::ErrorKind::InvalidInput, "Invalid path/filename")), }; + let metadata = match file.metadata() { + Ok(m) => m, + Err(_) => return Err(io::Error::new(io::ErrorKind::InvalidInput, "Invalid path/filename")), + }; + if !metadata.is_file() { + return Err(io::Error::new(io::ErrorKind::InvalidInput, "Invalid path/filename")); + } let mut buf = Vec::with_capacity(512); buf.extend((rtftp::Opcodes::WRQ as u16).to_be_bytes().iter()); self.tftp.append_option(&mut buf, filename, "octet"); - self.append_option_req(&mut buf); + self.append_option_req(&mut buf, metadata.len()); let mut remote = None; for _ in 1 .. 3 { @@ -160,7 +168,7 @@ impl Tftpc { let mut buf = Vec::with_capacity(512); buf.extend((rtftp::Opcodes::RRQ as u16).to_be_bytes().iter()); self.tftp.append_option(&mut buf, filename, "octet"); - self.append_option_req(&mut buf); + self.append_option_req(&mut buf, 0); let mut remote = None; for _ in 1 .. 3 { |
