当前位置: 首页>>代码示例>>C#>>正文


C# IPAddress.GetHashCode方法代码示例

本文整理汇总了C#中System.Net.IPAddress.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# IPAddress.GetHashCode方法的具体用法?C# IPAddress.GetHashCode怎么用?C# IPAddress.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.IPAddress的用法示例。


在下文中一共展示了IPAddress.GetHashCode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: addIPAddress

 public bool addIPAddress( IPAddress ip )
 {
     int new_hash = ip.GetHashCode();
     if (ip_hashes.Contains(new_hash))
         return false;
     ip_addresses.Add(ip);
     ip_hashes.Add(new_hash);
     return true;
 }
开发者ID:Ch0wW,项目名称:XBSlink,代码行数:9,代码来源:xbs_node.cs

示例2: GetIDByAddress

 /// <summary>
 /// 根据IP地址生成PeerID
 /// </summary>
 /// <param name="ip">IP地址</param>
 /// <returns>得到的PeerID</returns>
 public static PeerID GetIDByAddress(IPAddress ip)
 {
     return new PeerID(ip.GetHashCode());
 }
开发者ID:burstinair,项目名称:burst.net,代码行数:9,代码来源:NetUtil.cs

示例3: GetByName

        /// <exception cref="UnknownHostException"></exception>
        internal virtual NbtAddress GetByName(Name name, IPAddress addr)
        {
            int n;

            NameQueryRequest request = new NameQueryRequest(name);
            NameQueryResponse response = new NameQueryResponse();
            if (addr != null)
            {
                request.Addr = addr;
                request.IsBroadcast = (addr.GetAddressBytes()[3] == unchecked(unchecked(0xFF)));
                n = RetryCount;
                do
                {
                    try
                    {
                        Send(request, response, RetryTimeout);
                    }
                    catch (IOException ioe)
                    {
                        if (_log.Level > 1)
                        {
                            Runtime.PrintStackTrace(ioe, _log);
                        }
                        throw new UnknownHostException(ioe);
                    }
                    if (response.Received && response.ResultCode == 0
                        && response.IsResponse)
                    {
                        int last = response.AddrEntry.Length - 1;
                        response.AddrEntry[last].HostName.SrcHashCode = addr.GetHashCode();
                        return response.AddrEntry[last];
                    }
                }
                while (--n > 0 && request.IsBroadcast);
                throw new UnknownHostException();
            }
            for (int i = 0; i < _resolveOrder.Length; i++)
            {
                try
                {
                    switch (_resolveOrder[i])
                    {
                        case ResolverLmhosts:
                            {
                                NbtAddress ans = Lmhosts.GetByName(name);
                                if (ans != null)
                                {
                                    ans.HostName.SrcHashCode = 0;
                                    // just has to be different
                                    // from other methods
                                    return ans;
                                }
                                break;
                            }

                        case ResolverWins:
                        case ResolverBcast:
                            {
                                if (_resolveOrder[i] == ResolverWins && name.name != NbtAddress.MasterBrowserName
                                     && name.HexCode != unchecked(0x1d))
                                {
                                    request.Addr = NbtAddress.GetWinsAddress();
                                    request.IsBroadcast = false;
                                }
                                else
                                {
                                    request.Addr = Baddr;
                                    request.IsBroadcast = true;
                                }
                                n = RetryCount;
                                while (n-- > 0)
                                {
                                    try
                                    {
                                        Send(request, response, RetryTimeout);
                                    }
                                    catch (IOException ioe)
                                    {
                                        if (_log.Level > 1)
                                        {
                                            Runtime.PrintStackTrace(ioe, _log);
                                        }
                                        throw new UnknownHostException(ioe);
                                    }
                                    if (response.Received && response.ResultCode == 0
                                        && response.IsResponse)
                                    {

                                        response.AddrEntry[0].HostName.SrcHashCode = request.Addr.GetHashCode();
                                        return response.AddrEntry[0];
                                    }
                                    if (_resolveOrder[i] == ResolverWins)
                                    {
                                        break;
                                    }
                                }
                                break;
                            }
                    }
//.........这里部分代码省略.........
开发者ID:istupakov,项目名称:SharpCifs,代码行数:101,代码来源:NameServiceClient.cs

示例4: NetTest2_IPAddressBasic

        public MFTestResults NetTest2_IPAddressBasic()
        {
            /// <summary>
            /// 1. Creates 30 Random IPs between 0.0.0.0 and 255.255.255.127
            /// 2. Verifies that they can be constructed
            /// 3. Verifies that they have the correct data (GetAddressBytes)
            /// 4. Verifies ToString and GetHashcode
            /// </summary>
            ///
            bool testResult = true;
            try
            {
                Random random = new Random();
                for (int i = 0; i <= 30; i++)
                {
                    int[] IPInts = { random.Next(256), random.Next(256), 
                        random.Next(256), random.Next(128) };
                    Log.Comment("Random IP " + IPInts[0] + "." + IPInts[1]
                        + "." + IPInts[2] + "." + IPInts[3]);
                    IPAddress address = new IPAddress((long)(
                        IPInts[0]
                        + IPInts[1] * 256
                        + IPInts[2] * 256 * 256
                        + IPInts[3] * 256 * 256 * 256));

                    if (address == null)
                        throw new Exception("Address is null");

                    Type typeOfAddress = address.GetType();
                    if (typeOfAddress != Type.GetType("System.Net.IPAddress"))
                        throw new Exception("Type is incorrect");

                    byte[] targetBytes = { (byte)IPInts[0], (byte)IPInts[1], 
                        (byte)IPInts[2], (byte)IPInts[3] };
                    byte[] addressBytes = address.GetAddressBytes();
                    if (addressBytes.Length != 4)
                        throw new Exception("GetAddressBytes returns wrong size");

                    for (int j = 0; j < 4; j++)
                        if (addressBytes[j] != targetBytes[j])
                            throw new Exception("GetAddressBytes returns wrong bytes");
                    IPAddress address2 = new IPAddress((long)(
                            IPInts[0]
                            + IPInts[1] * 256
                            + IPInts[2] * 256 * 256
                            + IPInts[3] * 256 * 256 * 256));

                    if (address.ToString() != address2.ToString())
                        throw new Exception("ToString returns differently for same data");

                    if (address.GetHashCode() != address2.GetHashCode())
                        throw new Exception("GetHasCode returns differently for same data");

                    address2 = new IPAddress((long)(
                        (IPInts[0] % 2 + 1)
                        + (IPInts[1] % 2 + 1 )* 256
                        + (IPInts[2] % 2 + 1 )* 256 * 256
                        + (IPInts[3] % 2 + 1 )* 256 * 256 * 256));
                    if (address.GetHashCode() == address2.GetHashCode())
                        throw new Exception("GetHasCode returns same for " + address.ToString() 
                            + " as " + address2.ToString());
                }
            }
            catch (Exception e)
            {
                Log.Comment("Caught exception: " + e.Message);
                testResult = false;
            }
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:70,代码来源:NetTests.cs

示例5: IsWins

		public static bool IsWins(IPAddress svr)
		{
			for (int i = 0; svr != null && i < Nbns.Length; i++)
			{
				if (svr.GetHashCode() == Nbns[i].GetHashCode())
				{
					return true;
				}
			}
			return false;
		}
开发者ID:Cyber-Forensic,项目名称:Potato,代码行数:11,代码来源:NbtAddress.cs

示例6: DoNameQuery

		/// <exception cref="UnknownHostException"></exception>
		internal static NbtAddress DoNameQuery(Name name, IPAddress svr)
		{
			NbtAddress addr;
			if (name.HexCode == unchecked(0x1d) && svr == null)
			{
				svr = Client.Baddr;
			}
			// bit of a hack but saves a lookup
			name.SrcHashCode = svr != null ? svr.GetHashCode() : 0;
			addr = GetCachedAddress(name);
			if (addr == null)
			{
				if ((addr = (NbtAddress)CheckLookupTable(name)) == null)
				{
					try
					{
						addr = Client.GetByName(name, svr);
					}
					catch (UnknownHostException)
					{
						addr = UnknownAddress;
					}
					finally
					{
						CacheAddress(name, addr);
						UpdateLookupTable(name);
					}
				}
			}
			if (addr == UnknownAddress)
			{
				throw new UnknownHostException(name.ToString());
			}
			return addr;
		}
开发者ID:Cyber-Forensic,项目名称:Potato,代码行数:36,代码来源:NbtAddress.cs


注:本文中的System.Net.IPAddress.GetHashCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。