Fnal upload of subnet_calculator before re-write
This commit is contained in:
parent
7f8f2a41fe
commit
44bafbd0e6
@ -12,6 +12,13 @@ pub enum NetworkingErr {
|
|||||||
InvalidIPErr
|
InvalidIPErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// enum to allow the identification of the class of the network
|
||||||
|
enum NetworkClass {
|
||||||
|
A = 8,
|
||||||
|
B = 16,
|
||||||
|
C = 24
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub struct Network {
|
pub struct Network {
|
||||||
network_address: IpAddr,
|
network_address: IpAddr,
|
||||||
@ -57,7 +64,6 @@ impl Network {
|
|||||||
for (i, oct) in subnet_mask.iter().enumerate(){
|
for (i, oct) in subnet_mask.iter().enumerate(){
|
||||||
if *oct == 0 {
|
if *oct == 0 {
|
||||||
most_sig_octet = i-1;
|
most_sig_octet = i-1;
|
||||||
network_bits = subnet_mask[most_sig_octet].count_ones() as u8;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,17 +77,18 @@ impl Network {
|
|||||||
return Err(NetworkingErr::InvalidSubnetMask);
|
return Err(NetworkingErr::InvalidSubnetMask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
host_bits = subnet_mask[most_sig_octet].count_zeros() as u8;
|
||||||
|
|
||||||
//Determine the number of networks needed for the subnet.
|
//Determine the number of networks needed for the subnet.
|
||||||
host_bits = subnet_mask.map(|o| o.count_zeros() as u8).iter().sum();
|
network_bits = subnet_mask.map(|o| o.count_zeros() as u8).iter().sum();
|
||||||
host_bits -= network_bits;
|
network_bits -= host_bits;
|
||||||
|
|
||||||
//Determine Spacing
|
//Determine Spacing -> Incorrect
|
||||||
let network_spacing = u8::pow(2, subnet_mask[most_sig_octet].count_ones());
|
let network_spacing = u8::pow(2, subnet_mask[most_sig_octet].count_zeros()+1);
|
||||||
|
|
||||||
//Determine number of networks in the subnet
|
//Determine number of networks in the subnet
|
||||||
let mut num_networks: u8 = 0;
|
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));
|
num_networks += u8::pow(2, u32::from(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user