无类别域间路由

    1. use ipnet::{IpNet, Ipv4Net, Ipv6Net};
    2. use std::net::{Ipv4Addr, Ipv6Addr};
    3. use std::str::FromStr;
    4. fn main() -> std::io::Result<()> {
    5. let _v4 = Ipv4Net::new(Ipv4Addr::new(10, 1, 1, 0), 24).unwrap();
    6. let _v6 = Ipv6Net::new(Ipv6Addr::new(0xfd, 0, 0, 0, 0, 0, 0, 0), 24).unwrap();
    7. let _v4 = Ipv4Net::from_str("10.1.1.0/24").unwrap();
    8. let _v6 = Ipv6Net::from_str("fd00::/24").unwrap();
    9. let v4 = "10.1.1.0/24".parse::<Ipv4Net>().unwrap();
    10. let _v6: Ipv6Net = "fd00::/24".parse().unwrap();
    11. let _net = IpNet::from(v4);
    12. let net: IpNet = IpNet::from_str("10.1.1.0/24").unwrap();
    13. println!("net :{}, hostmask: {}", net, net.hostmask());
    14. println!("net :{}, netmask: {}", net, net.netmask());
    15. Ok(())
    16. }