Пример #1
0
        ///  Gives the prefix in IPv4 dotted decimal format,
        ///  i.e. the canonical netmask we're all used to
        ///
        ///    prefix = IPAddress::prefix::Prefix32.new 24
        ///
        ///    prefix.to_ip
        ///      ///  "255.255.255.0"
        ///
        public static Result <Prefix> create(uint num)
        {
            if (0 <= num && num <= 32)
            {
                var ip_bits = IpBits.V4;
                var bits    = ip_bits.bits;
                return(Result <Prefix> .Ok(new Prefix(num, ip_bits, Prefix.new_netmask(num, bits),

                                                      (p, _num) => create(_num))));
            }
            return(Result <Prefix> .Err(string.Format("Prefix must be in range 0..32, got: {0}", num)));
        }
Пример #2
0
 ///
 ///  Creates a new prefix object for 128 bits IPv6 addresses
 ///
 ///    prefix = IPAddressPrefix128.new 64
 ///      ///  64
 ///
 public static Result <Prefix> create(uint num)
 {
     if (num <= 128)
     {
         //static _FROM: &'static (Fn(&Prefix, usize) -> Result<Prefix, String>) = &from;
         //static _TO_IP_STR: &'static (Fn(&Vec<u16>) -> String) = &Prefix128::to_ip_str;
         var ip_bits = IpBits.V6;
         var bits    = ip_bits.bits;
         return(Result <Prefix> .Ok(new Prefix(
                                        num,
                                        ip_bits,
                                        Prefix.new_netmask(num, bits),
                                        (p, _num) => { return create(_num); }
                                        )));
     }
     return(Result <Prefix> .Err(string.Format("Prefix must be in range 0..128, got: «{0}»", num)));
 }
Пример #3
0
 public bool equal(Prefix other)
 {
     return(this.ip_bits.version == other.ip_bits.version &&
            this.num == other.num);
 }
Пример #4
0
 public Result <Prefix> sub_prefix(Prefix other)
 {
     return(this.sub(other.get_prefix()));
 }
Пример #5
0
 public Result <Prefix> add_prefix(Prefix other)
 {
     return(this.from(this.get_prefix() + other.get_prefix()));
 }
Пример #6
0
 public Result <Prefix> from(Prefix my, uint num)
 {
     return(create(num));
 }