本文整理汇总了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);
}
示例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);
}
示例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('=', '-');
}
示例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;
}
}
示例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);
}
示例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();
}
示例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));
}
}
}
示例8: MapToIPv6
public IPAddress MapToIPv6(IPAddress address)
{
return address.MapToIPv6();
}
示例9: IPAddressToBytes
public static byte[] IPAddressToBytes(IPAddress ipAddress)
{
if (!ipAddress.IsIPv4MappedToIPv6)
ipAddress=ipAddress.MapToIPv6();
return ipAddress.GetAddressBytes();
}