當前位置: 首頁>>代碼示例>>C#>>正文


C# IPAddress.MapToIPv6方法代碼示例

本文整理匯總了C#中System.Net.IPAddress.MapToIPv6方法的典型用法代碼示例。如果您正苦於以下問題:C# IPAddress.MapToIPv6方法的具體用法?C# IPAddress.MapToIPv6怎麽用?C# IPAddress.MapToIPv6使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Net.IPAddress的用法示例。


在下文中一共展示了IPAddress.MapToIPv6方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: IsNetworkAvailable

		static bool IsNetworkAvailable (out NetworkReachabilityFlags flags)
		{
			if (defaultRouteReachability == null) {
				var ipAddress = new IPAddress (0);
				defaultRouteReachability = new NetworkReachability (ipAddress.MapToIPv6 ());
				defaultRouteReachability.SetNotification (OnChange);
				defaultRouteReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
			}
			return defaultRouteReachability.TryGetFlags (out flags) && IsReachableWithoutRequiringConnection (flags);
		}
開發者ID:xamarin,項目名稱:monotouch-samples,代碼行數:10,代碼來源:reachability.cs

示例2: IsAdHocWiFiNetworkAvailable

		public static bool IsAdHocWiFiNetworkAvailable (out NetworkReachabilityFlags flags)
		{
			if (adHocWiFiNetworkReachability == null) {
				var ipAddress = new IPAddress (new byte[] { 169, 254, 0, 0 });
				adHocWiFiNetworkReachability = new NetworkReachability (ipAddress.MapToIPv6 ());
				adHocWiFiNetworkReachability.SetNotification (OnChange);
				adHocWiFiNetworkReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
			}

			return adHocWiFiNetworkReachability.TryGetFlags (out flags) && IsReachableWithoutRequiringConnection (flags);
		}
開發者ID:xamarin,項目名稱:monotouch-samples,代碼行數:11,代碼來源:reachability.cs

示例3: SignCookie

        public static string SignCookie(string input, long timestamp = long.MinValue, IPAddress remoteIp = null, uint validTime = uint.MaxValue)
        {
            if(input == null) throw new ArgumentNullException();
            if(hmacKey == null) throw new InvalidOperationException();

            var dataLen = cookieEncoding.GetByteCount(input) + DataOffset;
            var data = new byte[dataLen];
            var encodedLength = cookieEncoding.GetBytes(input, 0, input.Length, data, DataOffset);
            System.Diagnostics.Debug.Assert(encodedLength == (dataLen - DataOffset));
            
            data.PutInt64LE(TsOffset, timestamp == long.MinValue ? UnixTimestamp.CurrentMillisecondTimestamp : timestamp);
            data.PutUInt32LE(ValidityOffset, validTime);

            if(remoteIp == null) { //which means don't care
                remoteIp = IPAddress.IPv6Any; //all zeroes
            } else if(remoteIp.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) {
                remoteIp = remoteIp.MapToIPv6();
            }
            Array.Copy(remoteIp.GetAddressBytes(), 0, data, IpAddrOffset, IpAddrLength);

            Array.Copy(hmac.Value.ComputeHash(data, SigLength, data.Length - SigLength), data, SigLength);
            return Convert.ToBase64String(data).Replace('+', '.').Replace('/', '_').Replace('=', '-');
        }
開發者ID:Ledenel,項目名稱:OoiSharp,代碼行數:23,代碼來源:Cookie.cs

示例4: VerifyCookie

        public static string VerifyCookie(string input, out long signTime, IPAddress remoteIp = null, uint validTime = uint.MaxValue)
        {
            if(hmacKey == null) throw new InvalidOperationException();

            signTime = long.MinValue;
            if(input == null) {
                return null;
            }
            if(input.Length < 80) { //Minimum length (60 byte sig+metadata)
                return null;
            }
            if((input.Length & 3) != 0) { //Length of a base64 string must be of multiples of 4
                return null;
            }
            
            try {
                var data = Convert.FromBase64String(input.Replace('.', '+').Replace('_', '/').Replace('-', '=')); //throws FormatException

                var computed = hmac.Value.ComputeHash(data, SigLength, data.Length - SigLength); //Compute signature
                int trash = 0;
                for(int i = 0; i < SigLength; i++) {    //Compare the sig. (Avoiding timing attack)
                    trash |= data[i] ^ computed[i];
                }
                if(trash != 0) {    //sig mismatch, reject.
                    return null;
                }

                signTime = data.GetInt64LE(TsOffset);
                var currentTs = UnixTimestamp.CurrentMillisecondTimestamp;
                if(signTime > currentTs) {    //Reject anything with a timestamp from the future
                    return null;
                }
                
                //Compute the validity period for this verification.
                //Subtract 1 to treat value 0 (defined as infinite) as greatest.
                validTime = Math.Min(data.GetUInt32LE(ValidityOffset) - 1, validTime - 1);
                if(validTime != uint.MaxValue) {
                    if((signTime + validTime) < currentTs) { //Should be <=, but we've subtracted 1 from the original value.
                        return null;
                    }
                }

                //all zeroes denotes don't care.
                if(!data.TrueForRange(IpAddrOffset, IpAddrLength, x => x == 0)) {
                    if(remoteIp == null) { //No remote ip provided while a verification is required, reject.
                        return null;
                    }
                    if(remoteIp.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) {
                        remoteIp = remoteIp.MapToIPv6();
                    }
                    var ip = remoteIp.GetAddressBytes();
                    if(!ArrayEx.RangeEquals(data, IpAddrOffset, ip, 0, IpAddrLength)) {
                        return null;
                    }
                }

                return cookieEncoding.GetString(data, DataOffset, data.Length - DataOffset); //throws ArgumentException
            } catch(FormatException) {
                return null;
            } catch(ArgumentException) {
                return null;
            }
        }
開發者ID:Ledenel,項目名稱:OoiSharp,代碼行數:63,代碼來源:Cookie.cs

示例5: TryFromIPAddress

		public static TryResult<Value128> TryFromIPAddress(IPAddress value)
		{
			// Check input value
			if (value == null)
			{
				return convertFailResult;
			}

			// Map to IPv6
			var bytes = value.MapToIPv6().GetAddressBytes();

			// Try convert from byte array
			return TryFromByteArray(bytes, 0);
		}
開發者ID:stas-sultanov,項目名稱:SXN.Core,代碼行數:14,代碼來源:Value128Converter.cs

示例6: IPAddressToBytes

        public static byte[] IPAddressToBytes(IPAddress ipAddress)
        {
            // if address is IPv4, map it onto IPv6
            if (!ipAddress.IsIPv4MappedToIPv6)
                ipAddress = ipAddress.MapToIPv6();

            return ipAddress.GetAddressBytes();
        }
開發者ID:cole2295,項目名稱:BitSharp,代碼行數:8,代碼來源:Messaging.cs

示例7: LoadState

 public static void LoadState(Stream stream)
 {
     unconnectedPeers.Clear();
     using (BinaryReader reader = new BinaryReader(stream, Encoding.ASCII, true))
     {
         int count = reader.ReadInt32();
         for (int i = 0; i < count; i++)
         {
             IPAddress address = new IPAddress(reader.ReadBytes(4));
             int port = reader.ReadUInt16();
             unconnectedPeers.Add(new IPEndPoint(address.MapToIPv6(), port));
         }
     }
 }
開發者ID:EppoFq,項目名稱:AntShares,代碼行數:14,代碼來源:LocalNode.cs

示例8: MapToIPv6

			public IPAddress MapToIPv6(IPAddress address)
			{
				return address.MapToIPv6();
			}
開發者ID:crowar,項目名稱:NBitcoin,代碼行數:4,代碼來源:IpExtensions.cs

示例9: IPAddressToBytes

        public static byte[] IPAddressToBytes(IPAddress ipAddress)
        {
            if (!ipAddress.IsIPv4MappedToIPv6)
                ipAddress=ipAddress.MapToIPv6();

            return ipAddress.GetAddressBytes();
        }
開發者ID:ArsenShnurkov,項目名稱:BitSharp,代碼行數:7,代碼來源:Messaging.cs


注:本文中的System.Net.IPAddress.MapToIPv6方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。