Started testing create_subnet function. Still WIP!!!

This commit is contained in:
Luke Else 2023-04-20 22:30:33 +01:00
parent 45c5227a19
commit ee116523d8
2 changed files with 11 additions and 1 deletions

View File

@ -1,5 +1,7 @@
use std::{io}; use std::{io};
use crate::networking::Network;
mod networking; mod networking;
@ -23,5 +25,7 @@ fn main() {
break; break;
} }
let networks = Network::create_subnet(&ip_and_cidr.0, ip_and_cidr.1);
println!("IP: {}, CIDR: {}", ip_and_cidr.0.to_string(), ip_and_cidr.1); println!("IP: {}, CIDR: {}", ip_and_cidr.0.to_string(), ip_and_cidr.1);
} }

View File

@ -55,6 +55,12 @@ impl Network {
//Get number of bits available for host in specific octet //Get number of bits available for host in specific octet
let mut most_sig_octet: usize = Default::default(); let mut most_sig_octet: usize = Default::default();
for (i, oct) in subnet_mask.iter().enumerate(){ for (i, oct) in subnet_mask.iter().enumerate(){
if *oct == 0 {
most_sig_octet = i-1;
network_bits = subnet_mask[most_sig_octet].count_ones() as u8;
break;
}
if *oct < 255 { if *oct < 255 {
most_sig_octet = i; most_sig_octet = i;
network_bits = oct.count_ones() as u8; network_bits = oct.count_ones() as u8;
@ -82,7 +88,7 @@ impl Network {
//Generate base address //Generate base address
let mut base_address = network_address; let mut base_address = network_address;
base_address[most_sig_octet] = 255 - num_networks; base_address[most_sig_octet] = 255 - num_networks;
for i in most_sig_octet+1..=4 { for i in most_sig_octet+1..4 {
base_address[i] = 0; base_address[i] = 0;
} }