Exemplo n.º 1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (AddressType != global::AcFunDanmu.AccessPoint.Types.AddressType.KIpv4)
            {
                hash ^= AddressType.GetHashCode();
            }
            if (Port != 0)
            {
                hash ^= Port.GetHashCode();
            }
            if (IpV4 != 0)
            {
                hash ^= IpV4.GetHashCode();
            }
            if (IpV6.Length != 0)
            {
                hash ^= IpV6.GetHashCode();
            }
            if (Domain.Length != 0)
            {
                hash ^= Domain.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 2
0
        public override bool Equals(object o)
        {
            if (((Ip)o).InetKind == InetKind)
            {
                if (InetKind == InetKind.V4)
                {
                    if (IpV4 == null && ((Ip)o).IpV4 == null)
                    {
                        return(true);
                    }
                    return(IpV4 != null && !IpV4.Where((t, i) => ((Ip)o).IpV4[i] != t).Any());
                }
                if (IpV6 == null && ((Ip)o).IpV6 == null)
                {
                    return(true);
                }

                if (ScopeId != ((Ip)o).ScopeId)
                {
                    return(false);
                }

                return(IpV6 != null && !IpV6.Where((t, i) => ((Ip)o).IpV6[i] != t).Any());
            }
            return(false);
        }
Exemplo n.º 3
0
        public override void ToStream(Stream output)
        {
            output.Write(TLUtils.SignatureToBytes(Signature));

            Ip.ToStream(output);
            IpV6.ToStream(output);
            Port.ToStream(output);
            PeerTag.ToStream(output);
        }
Exemplo n.º 4
0
 public override byte[] ToBytes()
 {
     return(TLUtils.Combine(
                TLUtils.SignatureToBytes(Signature),
                Ip.ToBytes(),
                IpV6.ToBytes(),
                Port.ToBytes(),
                PeerTag.ToBytes()));
 }
Exemplo n.º 5
0
 public void test_classhmethod_parse_u128()
 {
     foreach (var kp in setup().valid_ipv6)
     {
         var ip  = kp.Key;
         var num = kp.Value;
         // println!(">>>{}==={}", ip, num);
         Assert.Equal(IPAddress.parse(ip).unwrap().to_s(), IpV6.from_int(num, 128).unwrap().to_s());
     }
 }
Exemplo n.º 6
0
 public void test_classmethod_parse_hex()
 {
     Assert.Equal(setup().ip.to_string(), IpV6.from_str(setup().hex, 16, 64).unwrap().to_string());
 }
Exemplo n.º 7
0
 public void test_method_broadcast_u128()
 {
     Assert.Equal(IpV6.from_int(BigInteger.Parse("42540766411282592875350729025363378175"), 64).unwrap(),
                  setup().ip.broadcast());
 }
Exemplo n.º 8
0
 public void test_method_network_u128()
 {
     Assert.Equal(IpV6.from_int(BigInteger.Parse("42540766411282592856903984951653826560"), 64).unwrap(),
                  setup().ip.network());
 }
Exemplo n.º 9
0
 //ネットワークバイトオーダ
 public byte[] NetBytes()
 {
     CheckInitialise();
     return(InetKind == InetKind.V4 ? IpV4.ToArray() : IpV6.ToArray());
 }
Exemplo n.º 10
0
        override public string ToString()
        {
            CheckInitialise();

            if (InetKind == InetKind.V4)
            {
                if (Any)
                {
                    return("INADDR_ANY");
                }
                return(string.Format("{0}.{1}.{2}.{3}", IpV4[0], IpV4[1], IpV4[2], IpV4[3]));
            }
            if (Any)
            {
                return("IN6ADDR_ANY_INIT");
            }

            if (IpV6.Max() == 0)
            {
                return("::0");
            }

            var sb    = new StringBuilder();
            var state = State.Unused;

            for (var i = 0; i < 8; i++)
            {
                var h = Convert.ToUInt16(IpV6[i * 2]);
                var l = Convert.ToUInt16(IpV6[i * 2 + 1]);
                var u = (UInt16)((h << 8) | l);
                if (u == 0)
                {
                    if (state == State.Unused) // 未使用の場合
                    {
                        state = State.Using;   // 使用中に設定する
                        sb.Append(":");
                    }
                    else if (state == State.Finish)     // 使用済の場合、0を表記する
                    {
                        sb.AppendFormat(":{0:x}", u);
                    }

                    //if (flg == 0) {//未使用の場合
                    //    flg = 1;//使用中に設定する
                    //    sb.Append(":");
                    //} else if (flg == 1) {//使用中の場合
                    //    //処理なし
                    //} else {//使用済の場合、0を表記する
                    //    sb.AppendFormat(":{0:x}", u);
                    //}
                }
                else
                {
                    if (state == State.Using) // 使用中の場合は
                    {
                        state = State.Finish; // 使用済に設定する
                    }
                    sb.Append(i == 0 ? String.Format("{0:x}", u) : String.Format(":{0:x}", u));

                    //if (flg == 1) {//使用中の場合は
                    //    flg = 2;//使用済に設定する
                    //}
                    //sb.AppendFormat(i == 0 ? "{0:x}" : ":{0:x}", u);
                }
            }
            if (state == State.Using)   // 使用中で終了した場合は:を足す
            {
                sb.Append(":");
            }
            //Ver5.4.9
            if (ScopeId != 0)
            {
                sb.AppendFormat("%{0}", ScopeId);
            }
            return(sb.ToString());
        }