Skip to content

Commit 24abf66

Browse files
committed
Add description.
1 parent 8e25124 commit 24abf66

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

src/networking/nc/mod.rs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use super::{MesaError};
2626

2727

2828
pub(crate) const NAME: &str = "nc";
29-
pub(crate) const DESCRIPTION: &str = "netcat";
29+
pub(crate) const DESCRIPTION: &str = "arbitrary TCP and UDP connections and listens";
3030

3131
const BUFSIZE: usize = 16384;
3232
const PRINT_DEBUG_INFO: bool = false;
@@ -182,6 +182,7 @@ impl NcOptions {
182182
portlist: portlist,
183183
family: family,
184184
kflag: matches.is_present("k"),
185+
// TODO: implement
185186
// sflag: sflag,
186187
s_addr: s_addr,
187188
pflag: pflag,
@@ -276,20 +277,20 @@ impl <'a> NcCore<'a> {
276277
/* both inputs are gone, buffers are empty, we are done */
277278
if self.stdin_gone() && self.netin_gone() &&
278279
self.stdinbuf_empty() && self.netinbuf_empty() {
279-
self.sock.shutdown(std::net::Shutdown::Both)?;
280+
// TODO: self.sock.shutdown(std::net::Shutdown::Both)?;
280281
return Ok(());
281282
}
282283

283284
/* both outputs are gone, we can't continue */
284285
if self.stdout_gone() && self.netout_gone() {
285-
self.sock.shutdown(std::net::Shutdown::Both)?;
286+
// TODO: self.sock.shutdown(std::net::Shutdown::Both)?;
286287
return Ok(());
287288
}
288289

289290
/* listen and net in gone, queues empty, done */
290291
if self.opts.lflag && self.netin_gone() &&
291292
self.stdinbuf_empty() && self.netinbuf_empty() {
292-
self.sock.shutdown(std::net::Shutdown::Both)?;
293+
// TODO: self.sock.shutdown(std::net::Shutdown::Both)?;
293294
return Ok(());
294295
}
295296

@@ -329,7 +330,7 @@ impl <'a> NcCore<'a> {
329330
// if no stdout, stop watching net in
330331
if self.stdout_gone() {
331332
if !self.netin_gone() {
332-
self.sock.shutdown(std::net::Shutdown::Read)?;
333+
// TODO: self.sock.shutdown(std::net::Shutdown::Read)?;
333334
}
334335
self.remove_stdin()?;
335336
}
@@ -393,7 +394,7 @@ impl <'a> NcCore<'a> {
393394
if self.stdin_gone() && self.stdinbuf_empty() {
394395
if !self.netout_gone() {
395396
// TODO: check && opts.Nflag {
396-
self.sock.shutdown(std::net::Shutdown::Write)?;
397+
// TODO: self.sock.shutdown(std::net::Shutdown::Write)?;
397398
}
398399
self.remove_netout()?;
399400
}
@@ -548,6 +549,7 @@ impl <'a> NcCore<'a> {
548549
if len > 0 {
549550
self.stdinbufpos -= len;
550551
if self.stdinbufpos > 0 {
552+
// TODO: improve efficiency
551553
self.stdinbuf_bac.copy_from_slice(&self.stdinbuf[len..len+self.stdinbufpos]);
552554
self.stdinbuf.copy_from_slice(&self.stdinbuf_bac);
553555
}
@@ -595,6 +597,7 @@ impl <'a> NcCore<'a> {
595597
if len > 0 {
596598
self.netinbufpos -= len;
597599
if self.netinbufpos > 0 {
600+
// TODO: improve efficiency
598601
self.netinbuf_bac.copy_from_slice(&self.netinbuf[len..len+self.netinbufpos]);
599602
self.netinbuf.copy_from_slice(&self.netinbuf_bac);
600603
}
@@ -636,7 +639,7 @@ impl <'a> NcCore<'a> {
636639
if event.token() == NcCore::TK_NET {
637640
debug_info("STDOUT HUP");
638641
// TODO: check Nflag
639-
self.sock.shutdown(std::net::Shutdown::Write)?;
642+
// TODO: self.sock.shutdown(std::net::Shutdown::Write)?;
640643
self.remove_netout()?
641644
}
642645

@@ -728,6 +731,7 @@ fn remote_connect(opts: &NcOptions, port: u16) -> Result<Socket, MesaError>{
728731

729732
if opts.s_addr.is_some() || opts.pflag {
730733
// TODO: implement
734+
unimplemented!();
731735
}
732736

733737
// TODO: maybe sometimes no timeout
@@ -876,7 +880,7 @@ fn unix_client(opts: &NcOptions) -> Result<(), MesaError> {
876880

877881
fn nonunix_client(opts: &NcOptions) -> Result<(), MesaError> {
878882
for port in &opts.portlist {
879-
let mut sock = match remote_connect(opts, port.clone()) {
883+
let mut sock = match remote_connect(opts, *port) {
880884
Ok(expr) => expr,
881885
Err(_) => continue,
882886
};
@@ -899,35 +903,46 @@ where
899903
let mut help_msg: Vec<u8> = Vec::new();
900904
let app = util_app!(NAME)
901905
.arg(Arg::with_name("l")
902-
.short("l"))
906+
.short("l")
907+
.help("Used to specify that nc should listen for an incoming connection rather than initiate a connection to a remote host. It is an error to use this option in conjunction with the -p, -s, or -z options. Additionally, any timeouts specified with the -w option are ignored."))
903908
.arg(Arg::with_name("i")
904909
.short("i")
905910
.value_name("interval")
911+
.help("Specifies a delay time interval between lines of text sent and received. Also causes a delay time between connections to multiple ports.")
906912
.takes_value(true))
907913
.arg(Arg::with_name("s")
908914
.short("s")
909915
.value_name("source_ip_address")
910-
.takes_value(true))
916+
.takes_value(true)
917+
.help("Specifies the IP of the interface which is used to send the packets. It is an error to use this option in conjunction with the -l option."))
911918
.arg(Arg::with_name("d")
912-
.short("d"))
919+
.short("d")
920+
.help("Do not attempt to read from stdin."))
913921
.arg(Arg::with_name("U")
914-
.short("U"))
922+
.short("U")
923+
.help("Specifies to use Unix Domain Sockets."))
915924
.arg(Arg::with_name("u")
916-
.short("u"))
925+
.short("u")
926+
.help("Use UDP instead of the default option of TCP."))
917927
.arg(Arg::with_name("v")
918-
.short("v"))
928+
.short("v")
929+
.help("Have nc give more verbose output."))
919930
.arg(Arg::with_name("k")
920-
.short("k"))
931+
.short("k")
932+
.help("Forces nc to stay listening for another connection after its current connection is completed. It is an error to use this option without the -l option."))
921933
.arg(Arg::with_name("z")
922-
.short("z"))
934+
.short("z")
935+
.help("Specifies that nc should just scan for listening daemons, without sending any data to them. It is an error to use this option in conjunction with the -l option."))
923936
.arg(Arg::with_name("positionals")
924-
.multiple(true));
937+
.value_name("[hostname] [port[s]]")
938+
.multiple(true)
939+
.required(true));
925940

926941
app.write_help(&mut help_msg)?;
927942
let help_msg = String::from_utf8(help_msg)?;
928943
let matches = app.get_matches_from_safe(args)?;
929944

930-
// println!("matches = {:?}", matches);
945+
debug_info(&format!("matches = {:?}", matches));
931946
let opts = NcOptions::parse(matches, &help_msg)?;
932947

933948
if opts.lflag {

0 commit comments

Comments
 (0)