diff --git a/src/ipv4.rs b/src/ipv4.rs index 96db3ae..989463a 100644 --- a/src/ipv4.rs +++ b/src/ipv4.rs @@ -61,8 +61,8 @@ pub struct IPv4Range { } impl IPv4Range { - pub fn new(from: u32, to: u32, id_ignore: Option>) -> Self { - to = to.clamp(0, u32::max_value()); + pub fn new(from: u32, to: u32, id_ignore: &mut Vec) -> Self { + let to = to.clamp(0, u32::max_value()); if from >= to { panic!("Range size must be >= 1! from: {} >= to: {}", from, to); @@ -71,7 +71,7 @@ impl IPv4Range { Self { id_start: from, id_end: to, - id_ignore: id_ignore.unwrap_or(Vec::new()), + id_ignore } } } diff --git a/src/main.rs b/src/main.rs index dfdfa57..bcaadd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,10 +6,8 @@ mod util; use clap::Parser; use cli::Args; -use scanner::start_scan; - fn main() { - let args = Args::parse(); + let _args = Args::parse(); - let _results = start_scan(args.port, args.threads as u32, None).unwrap(); + //let _results = start_scan(args.port, args.threads as u32, None).unwrap(); } diff --git a/src/scanner.rs b/src/scanner.rs index abcb893..0cdaee1 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -37,35 +37,50 @@ fn create_scan_thread( }) } -pub fn start_scan( +fn create_scan_worker( + thread_id: u32, + ips_per_thread: u32, + target_port: u16, + ignorelist: &mut Vec, +) -> JoinHandle> { + let (f, t) = ( + (thread_id * ips_per_thread), + ((thread_id + 1) * ips_per_thread), + ); + let range = IPv4Range::new(f, t, ignorelist); + create_scan_thread(thread_id, range, target_port) +} + +fn start_scan( from: u32, to: u32, target_port: u16, num_threads: u32, - ignorelist: Option>, + ignorelist: Option<&mut Vec>, ) -> Result<()> { println!("Starting wwmap..."); - //let ip_list = get_all(ignorelist)?; let ips_per_thread = (((to - from) as f32) / num_threads as f32) as u32; - let ips_left = num_threads * ips_per_thread; // how many ips we have left after the first threads + let ips_left = (to - from) - (num_threads * ips_per_thread); // how many ips we have left after the first threads // container for all of our threads let mut threads: Vec>> = Vec::new(); for thread_id in 0..num_threads { - // Calculate ranges & stuff - let (f, t) = ( - (thread_id * ips_per_thread), - ((thread_id + 1) * ips_per_thread), - ); - let range = IPv4Range::new(f, t, ignorelist); + let thread_ignorelist = ignorelist.unwrap_or(&mut Vec::new()); // Create a worker - let worker = create_scan_thread(thread_id, range, target_port); + let worker = create_scan_worker( + thread_id, + ips_per_thread, + target_port, + thread_ignorelist + ); threads.push(worker); } + if ips_left > 0 {} + // container for all the results let mut result_list: Vec = Vec::new();