create_subnet function now works when the CIDR borrows 8 or less bits, need to figure out a way to have it so that we can modify the other octest sequentially
This commit is contained in:
parent
2dcbd405e4
commit
aad67836df
@ -7,11 +7,6 @@ mod networking;
|
||||
|
||||
#[allow(unused_variables, unused_mut, unused_assignments)]
|
||||
fn main() {
|
||||
|
||||
let networks = Network::create_subnet(&networking::ip::IpAddr::V4(192, 222, 222, 222), 25);
|
||||
if networks.is_err() {
|
||||
println!("Hello!");
|
||||
}
|
||||
println!("Enter the IP and cidr for your given network");
|
||||
|
||||
let ip_and_cidr: (networking::ip::IpAddr, u8);
|
||||
|
@ -55,7 +55,7 @@ impl Network {
|
||||
//Get number of host and network bits.
|
||||
let network_class = Network::get_network_class(network_address)?;
|
||||
let network_address = network_address.to_arr()?;
|
||||
let subnet_mask = Network::gen_subnet_mask(cidr)?.to_arr()?;
|
||||
//let subnet_mask = Network::gen_subnet_mask(cidr)?.to_arr()?;
|
||||
|
||||
// If the CIDR < class network enum associated value, then there is an invalid subnet.
|
||||
if cidr <= network_class as u8 {
|
||||
@ -89,11 +89,14 @@ impl Network {
|
||||
let network_spacing: u8 = u8::pow(2, 8 - num_borrowed_bits as u32);
|
||||
|
||||
//Create the subnets
|
||||
let mut networks = vec![];
|
||||
for i in 0..num_networks {
|
||||
networks.push(IpAddr::from_arr(&base_network.clone())?);
|
||||
let mut networks = vec![IpAddr::from_arr(&base_network)?];
|
||||
|
||||
//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