Bugfix: u8 no longer overflows when there are no borrowed bits.
This commit is contained in:
parent
b8e4ff21b0
commit
924142e96c
@ -80,17 +80,21 @@ impl Network {
|
||||
// We know that this value is >0 at this point
|
||||
let num_networks = u8::pow(2, num_borrowed_bits as u32);
|
||||
|
||||
// Determine the networking gaps
|
||||
let network_spacing: u8 = u8::pow(2, 8 - num_borrowed_bits as u32);
|
||||
|
||||
//Create the subnets
|
||||
let mut networks = vec![IpAddr::from_arr(&base_network)?];
|
||||
|
||||
// Determine the networking gaps
|
||||
//If there is only 1 network, returning the base network will be sufficient
|
||||
if num_networks > 1 {
|
||||
let network_spacing: u8 = u8::pow(2, 8 - num_borrowed_bits as u32);
|
||||
|
||||
//Add remaming subnets (-1 is because we have already added the first address)
|
||||
for _ in 0..(num_networks-1) {
|
||||
base_network[most_sig_octet as usize] += network_spacing;
|
||||
networks.push(IpAddr::from_arr(&base_network.clone())?);
|
||||
}
|
||||
}
|
||||
|
||||
println!("{:#?}", networks);
|
||||
Ok(networks)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user