无类别域间路由
use ipnet::{IpNet, Ipv4Net, Ipv6Net};use std::net::{Ipv4Addr, Ipv6Addr};use std::str::FromStr;fn main() -> std::io::Result<()> {let _v4 = Ipv4Net::new(Ipv4Addr::new(10, 1, 1, 0), 24).unwrap();let _v6 = Ipv6Net::new(Ipv6Addr::new(0xfd, 0, 0, 0, 0, 0, 0, 0), 24).unwrap();let _v4 = Ipv4Net::from_str("10.1.1.0/24").unwrap();let _v6 = Ipv6Net::from_str("fd00::/24").unwrap();let v4 = "10.1.1.0/24".parse::<Ipv4Net>().unwrap();let _v6: Ipv6Net = "fd00::/24".parse().unwrap();let _net = IpNet::from(v4);let net: IpNet = IpNet::from_str("10.1.1.0/24").unwrap();println!("net :{}, hostmask: {}", net, net.hostmask());println!("net :{}, netmask: {}", net, net.netmask());Ok(())}
