fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "cli")]
{
use clap::Parser;
use rping::cli::Cli;
use rping::utils::tcp_flood;
use std::thread;
let args = Cli::parse();
if args.size < 44 {
return Err("Packet length should be at least 44 bytes(IP + TCP headers)!".into());
}
if !args.target.is_empty() {
let mut handles = vec![];
for _ in 0..args.threads {
let args_clone = args.clone();
let handle = thread::spawn(move || {
if let Err(err) = tcp_flood(
args_clone.size,
&args_clone.target,
args_clone.port.try_into().unwrap(),
&args_clone.flag.to_ascii_lowercase(),
args_clone.duration,
args_clone.number,
&args_clone.iface,
) {
eprintln!("Thread failed: {:?}", err);
}
});
handles.push(handle);
}
let mut errors = Vec::new();
for handle in handles {
if let Err(err) = handle.join() {
errors.push(err);
}
}
if !errors.is_empty() {
eprintln!("Some threads failed to join:");
for err in errors {
eprintln!("Error: {:?}", err);
}
eprintln!("Please file an issue on GitHub (https://github.com/wiseaidev/rping) with details about the error.");
return Err("One or more threads failed to join".into());
} else {
println!("\nFlooding completed successfully!");
return Ok(());
}
}
}
Ok(())
}