]> git.feebdaed.xyz Git - linuxyz.git/commitdiff
working ncat rust
authorseantywork <seantywork@gmail.com>
Thu, 24 Apr 2025 05:07:57 +0000 (14:07 +0900)
committerseantywork <seantywork@gmail.com>
Thu, 24 Apr 2025 05:07:57 +0000 (14:07 +0900)
0xetc/0xrs/ncat/2505-01.xyz.md
0xetc/0xrs/ncat/Cargo.toml
0xetc/0xrs/ncat/src/main.rs
0xetc/0xrs/ncat/src/ncat/ncat.rs [new file with mode: 0644]

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..5662dae9207a73e077c3d86f4e1e6c4f04079844 100644 (file)
@@ -0,0 +1,7 @@
+# 01 
+
+```shell
+
+tricky to use globals
+
+```
\ No newline at end of file
index cb4d65f7af4392ffe8fa63b8b99bf8819e5b6c88..2305a1410b429400ed235dc701a6b7b301c17cb5 100644 (file)
@@ -4,3 +4,4 @@ version = "0.1.0"
 edition = "2024"
 
 [dependencies]
+ctrlc = "3.4"
\ No newline at end of file
index 9d7d6f66fc8362e651744a39411b4bdea0293d06..49b3e0d0292010e0ae43d42f3032cf210c843df6 100644 (file)
@@ -1,12 +1,73 @@
 mod ncat;
 
 use std::{
-    fs,
-    net::{TcpListener, TcpStream},
-    thread,
-}
+    env, 
+    fs, 
+    net::{TcpListener, TcpStream}, 
+    process::{self, ExitCode}, 
+    thread
+};
+
+use ncat::ncat::{self as NCAT, NcatOptions};
+
+
+fn main() -> process::ExitCode {
+    
+    let args: Vec<String> = env::args().collect();
+
+    let ncat_opts: &mut NCAT::NcatOptions;
+
+    if args.len() < 2 {
+
+        println!("too few arguments");
+
+        return process::ExitCode::from(1u8);
+    }
+
+
+    match ctrlc::set_handler(move || {
+        NCAT::keyboard_interrupt();
+    }) {
+
+        Ok(()) => {
+
+
+        }
+
+        Err(error) => {
+
+            println!("failed to add signal handler: {}", error.to_string());
+
+        }
+
+    }
+
+    let mut args_v = Vec::<String>::new();
+
+    for i in 1..args.len() {
+
+        args_v.push(args[i].clone());
+
+    };
+
+    let mut args_result = NCAT::parse_args(&args_v);
+
+    match args_result {
+
+        Ok(mut boxno) => {
+
+            ncat_opts = boxno.as_mut();
+
+        }
+
+        Err(reason) => {
+
+            println!("failed to parse args: {}", reason);
+        }
+    }
+
+
 
 
-fn main() {
-    println!("Hello, world!");
+    return process::ExitCode::from(0u8);
 }
diff --git a/0xetc/0xrs/ncat/src/ncat/ncat.rs b/0xetc/0xrs/ncat/src/ncat/ncat.rs
new file mode 100644 (file)
index 0000000..94641cb
--- /dev/null
@@ -0,0 +1,90 @@
+
+use std::{
+    fmt::Error,
+    process,
+};
+
+
+pub struct NcatOptions {
+
+    mode_client: bool,
+    mode_listen: bool, 
+    _client_sock_ready: bool,
+    _client_sockfd: i32,
+    host: String,
+    port: String, 
+
+}
+
+impl NcatOptions {
+
+    pub fn new() -> Self {
+        Self { 
+            mode_client: false, 
+            mode_listen: false, 
+            _client_sock_ready: false, 
+            _client_sockfd: 0, 
+            host: "".to_string(), 
+            port: "".to_string() 
+        }
+
+    }
+
+}
+
+pub struct NcatComms {
+
+    datalen: u32,
+    data: Vec<u8>
+}
+
+impl NcatComms {
+
+
+    pub fn new() -> Self {
+        Self {
+
+            datalen: 0,
+            data: Vec::<u8>::new()
+        }
+    }
+}
+
+
+pub fn keyboard_interrupt(){
+
+    println!("SIGINT. EXIT.");
+
+    process::exit(0);
+
+}
+
+
+pub fn parse_args(args: &Vec<String>) -> Result<Box<NcatOptions>, String>{
+
+    let no = NcatOptions::new();
+
+    let retno = Box::new(no);
+
+    return Ok(retno);
+    
+}
+
+pub fn runner(ncat_opts: &mut NcatOptions) -> Result<(), String> {
+
+
+
+    return Ok(());
+}
+
+
+fn client(ncat_opts: &mut NcatOptions) -> Result<(), String> {
+
+    return Ok(());
+}
+
+
+fn listen_and_serve(ncat_opts: &mut NcatOptions) -> Result<(), String> {
+
+    return Ok(());
+}
\ No newline at end of file