当前位置: 首页>>代码示例>>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;未经允许,请勿转载。