diff --git a/src/main.rs b/src/main.rs index 61b0195..53a248c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,5 +10,7 @@ mod permutations; fn main() { // scanner::start_scan(100); - permutations::ipv4(None); + // permutations::ipv4(None); + + let ip = permutations::IPv4::new(0); } diff --git a/src/permutations.rs b/src/permutations.rs index db7cc35..163501a 100644 --- a/src/permutations.rs +++ b/src/permutations.rs @@ -1,5 +1,6 @@ use anyhow::{Result, anyhow}; use convert_base::Convert; +use crate::util; /* Algorithm: O(n) @@ -10,15 +11,18 @@ let i = 0 .. u32:max_value() # This is waaaay better than a stupid loop */ -struct IPv4 { - id: u32, - ip: Vec +pub struct IPv4 { + pub id: u32, + pub ip: Vec } impl IPv4 { - fn new(self: &mut Self, id: u32) -> Self { + pub fn new(id: u32) -> Self { let mut base = Convert::new(10, 256); - let ip = base.convert::(&id); + + let id_vec = util::number_to_vec(id); // push all digits into a vec + println!("########## {:?}", id_vec); + let ip = base.convert::(&id_vec); Self { id, ip } } diff --git a/src/util.rs b/src/util.rs index 3e6c9a6..e891c9d 100644 --- a/src/util.rs +++ b/src/util.rs @@ -24,7 +24,7 @@ fn numlen(num: u32) -> u8 { len } -fn get_digits(num: u32) -> Vec { +pub fn number_to_vec(num: u32) -> Vec { let out: Vec = Vec::new(); let len = numlen(num);