cli
E. Almqvist 2 years ago
parent 6625d8869a
commit e1c3d15158
  1. 4
      src/main.rs
  2. 14
      src/permutations.rs
  3. 2
      src/util.rs

@ -10,5 +10,7 @@ mod permutations;
fn main() { fn main() {
// scanner::start_scan(100); // scanner::start_scan(100);
permutations::ipv4(None); // permutations::ipv4(None);
let ip = permutations::IPv4::new(0);
} }

@ -1,5 +1,6 @@
use anyhow::{Result, anyhow}; use anyhow::{Result, anyhow};
use convert_base::Convert; use convert_base::Convert;
use crate::util;
/* /*
Algorithm: O(n) Algorithm: O(n)
@ -10,15 +11,18 @@ let i = 0 .. u32:max_value()
# This is waaaay better than a stupid loop # This is waaaay better than a stupid loop
*/ */
struct IPv4 { pub struct IPv4 {
id: u32, pub id: u32,
ip: Vec<u8> pub ip: Vec<u8>
} }
impl IPv4 { impl IPv4 {
fn new(self: &mut Self, id: u32) -> Self { pub fn new(id: u32) -> Self {
let mut base = Convert::new(10, 256); let mut base = Convert::new(10, 256);
let ip = base.convert::<u32, u8>(&id);
let id_vec = util::number_to_vec(id); // push all digits into a vec
println!("########## {:?}", id_vec);
let ip = base.convert::<u8, u8>(&id_vec);
Self { id, ip } Self { id, ip }
} }

@ -24,7 +24,7 @@ fn numlen(num: u32) -> u8 {
len len
} }
fn get_digits(num: u32) -> Vec<u8> { pub fn number_to_vec(num: u32) -> Vec<u8> {
let out: Vec<u8> = Vec::new(); let out: Vec<u8> = Vec::new();
let len = numlen(num); let len = numlen(num);

Loading…
Cancel
Save