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


C# IPAddress.GetAddress方法代碼示例

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


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

示例1: GetHosts

        internal virtual NbtAddress[] GetHosts()
        {
            try
            {
                _waitResponse = false;

                byte[] bAddrBytes = laddr.GetAddressBytes();

                for (int i = 1; i <= 254; i++)
                {
                    NodeStatusRequest request;
                    NodeStatusResponse response;

                    byte[] addrBytes = {
                        bAddrBytes[0],
                        bAddrBytes[1],
                        bAddrBytes[2],
                        (byte)i
                    };

                    IPAddress addr = new IPAddress(addrBytes);

                    response = new NodeStatusResponse(new NbtAddress(NbtAddress.UnknownName,
                        addr.GetAddress(), false, 0x20));
                    request = new NodeStatusRequest(new Name(NbtAddress.AnyHostsName, unchecked(0x20), null));
                    request.Addr = addr;
                    Send(request, response, 0);
                }

            }
            catch (IOException ioe)
            {
                if (_log.Level > 1)
                {
                    Runtime.PrintStackTrace(ioe, _log);
                }
                throw new UnknownHostException(ioe);
            }

            _autoResetWaitReceive = new AutoResetEvent(false);
            _thread = new Thread(this);
            _thread.SetDaemon(true);
            _thread.Start();

            _autoResetWaitReceive.WaitOne();

            List<NbtAddress> result = new List<NbtAddress>();

            foreach (var key in _responseTable.Keys)
            {
                NodeStatusResponse resp = (NodeStatusResponse)_responseTable[key];

                if (resp.Received && resp.ResultCode == 0)
                {
                    foreach (var entry in resp.AddressArray)
                    {
                        if (entry.HostName.HexCode == 0x20)
                        {
                            result.Add(entry);
                        }
                    }
                }
            }

            _responseTable.Clear();

            _waitResponse = true;

            return result.Count > 0 ? result.ToArray() : null;
        }
開發者ID:istupakov,項目名稱:SharpCifs,代碼行數:70,代碼來源:NameServiceClient.cs

示例2: GetHostByAddr

        public static IPHostEntry GetHostByAddr(IPAddress address)
        {
            // TODO #2891: Optimize this (or decide if this legacy code can be removed):
            int addressAsInt = unchecked((int)address.GetAddress());

#if BIGENDIAN
            // TODO #2891: above code needs testing for BIGENDIAN.

            addressAsInt = (int)(((uint)addressAsInt << 24) | (((uint)addressAsInt & 0x0000FF00) << 8) |
                (((uint)addressAsInt >> 8) & 0x0000FF00) | ((uint)addressAsInt >> 24));
#endif

            IntPtr nativePointer =
                Interop.Winsock.gethostbyaddr(
                    ref addressAsInt,
                    Marshal.SizeOf<int>(),
                    ProtocolFamily.InterNetwork);
            
            if (nativePointer != IntPtr.Zero)
            {
                return NativeToHostEntry(nativePointer);
            }

            throw new SocketException();
        }
開發者ID:dotnet,項目名稱:corefx,代碼行數:25,代碼來源:NameResolutionPal.Windows.cs


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