diff --git a/Cargo.toml b/Cargo.toml index ffc4a96..78b3d13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -# packet = "0.1.4" anyhow = "1" log = "0.4" convert-base = "1.1.2" diff --git a/src/ipv4.rs b/src/ipv4.rs index 1247e02..a0c5b11 100644 --- a/src/ipv4.rs +++ b/src/ipv4.rs @@ -1,8 +1,8 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -use anyhow::{Result, anyhow}; -use convert_base::Convert; use crate::util; +use anyhow::{anyhow, Result}; +use convert_base::Convert; /* Algorithm: O(n) @@ -17,7 +17,7 @@ let i = 0 .. u32:max_value() pub struct IPv4 { pub id: u64, pub ip: Vec, - pub ignore: bool + pub ignore: bool, } impl IPv4 { @@ -29,7 +29,7 @@ impl IPv4 { // In case we are missing some digits if ip.len() < 4 { - for i in 0..(4-ip.len()) { + for i in 0..(4 - ip.len()) { ip.insert(0, 0); } } @@ -37,11 +37,15 @@ impl IPv4 { // Reverse it so that we start from the top ip = ip.into_iter().rev().collect(); - Self { id, ip, ignore: false } + Self { + id, + ip, + ignore: false, + } } pub fn to_ipaddr(self: &mut Self) -> Result { - if let [a, b, c, d] = self.ip[0..3] { + if let [a, b, c, d] = self.ip[0..3] { Ok(IpAddr::V4(Ipv4Addr::new(a, b, c, d))) } else { Err(anyhow!("Unable to unpack IPv4 address")) @@ -61,15 +65,20 @@ pub fn get_all(ignorelist: Option>) -> Result> { // Get all of the "ids" let ids: Vec = (0..u32::max_value()).collect(); - let ips: Vec = ids.iter().map(|&ip| { - // Make IP - let mut ip = IPv4::new(ip as u64); + let ips: Vec = ids + .iter() + .map(|&ip| { + // Make IP + let mut ip = IPv4::new(ip as u64); - // Make the IP "ignored" if it is in the ignorelist - if ignorelist.len() > 0 && ignorelist.contains(&ip.id) { ip.ignore = true; } + // Make the IP "ignored" if it is in the ignorelist + if ignorelist.len() > 0 && ignorelist.contains(&ip.id) { + ip.ignore = true; + } - ip - }).collect(); + ip + }) + .collect(); Ok(ips) } diff --git a/src/main.rs b/src/main.rs index a490ae4..ea3067d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,9 +4,9 @@ //unused_imports, // TODO: rm )] -mod util; -mod scanner; mod ipv4; +mod scanner; +mod util; use ipv4::IPv4; diff --git a/src/scanner.rs b/src/scanner.rs index 94d4574..988e487 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -1,7 +1,10 @@ -use std::{net::{TcpStream, SocketAddr}, thread::JoinHandle}; +use crate::ipv4; use log::info; use std::thread; -use crate::ipv4; +use std::{ + net::{SocketAddr, TcpStream}, + thread::JoinHandle, +}; async fn check_ack(dest: &SocketAddr) -> bool { if let Ok(res) = TcpStream::connect(dest) { @@ -18,14 +21,13 @@ pub fn start_scan(depth: u32) { for i in 0..depth { let thread = thread::spawn(|| { - println!("hi"); + println!("hi"); // do scan }); threads.push(thread); } } - /* depth: u32 @@ -36,4 +38,3 @@ pre: ALL_IPS: Vec> = ... */ - diff --git a/src/util.rs b/src/util.rs index c602bd1..689f57b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -10,8 +10,8 @@ uint ulong_len(ulong n) { // get the nth_digit length of a number */ fn nth_digit(num: u64, idx: u32) -> u8 { - // ((num % (10**(idx+1))) - (num % (10**idx)))/(10**idx) - (((num % (10_u64.pow(idx+1))) - (num % (10_u64.pow(idx))))/(10_u64.pow(idx))) as u8 + // ((num % (10**(idx+1))) - (num % (10**idx)))/(10**idx) + (((num % (10_u64.pow(idx + 1))) - (num % (10_u64.pow(idx)))) / (10_u64.pow(idx))) as u8 } fn numlen(mut num: u64) -> u8 { @@ -35,7 +35,7 @@ pub fn number_to_vec(num: u64) -> Vec { for idx in 0..len { let digit = nth_digit(num, idx as u32); - out.push(digit); + out.push(digit); } out