Fnal upload of subnet_calculator before re-write

This commit is contained in:
Luke Else 2023-04-25 20:16:28 +01:00
parent 7f8f2a41fe
commit 44bafbd0e6

View File

@ -12,6 +12,13 @@ pub enum NetworkingErr {
InvalidIPErr
}
/// enum to allow the identification of the class of the network
enum NetworkClass {
A = 8,
B = 16,
C = 24
}
#[allow(unused)]
pub struct Network {
network_address: IpAddr,
@ -57,7 +64,6 @@ impl Network {
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;
}
@ -71,17 +77,18 @@ impl Network {
return Err(NetworkingErr::InvalidSubnetMask);
}
}
host_bits = subnet_mask[most_sig_octet].count_zeros() as u8;
//Determine the number of networks needed for the subnet.
host_bits = subnet_mask.map(|o| o.count_zeros() as u8).iter().sum();
host_bits -= network_bits;
network_bits = subnet_mask.map(|o| o.count_zeros() as u8).iter().sum();
network_bits -= host_bits;
//Determine Spacing
let network_spacing = u8::pow(2, subnet_mask[most_sig_octet].count_ones());
//Determine Spacing -> Incorrect
let network_spacing = u8::pow(2, subnet_mask[most_sig_octet].count_zeros()+1);
//Determine number of networks in the subnet
let mut num_networks: u8 = 0;
for i in 1..network_bits {
for i in 1..=host_bits {
num_networks += u8::pow(2, u32::from(i));
}