コード例 #1
0
 internal static unsafe partial int GetAddrInfoExW(
     string pName,
     string?pServiceName,
     int dwNamespace,
     IntPtr lpNspId,
     AddressInfoEx *pHints,
     AddressInfoEx **ppResult,
     IntPtr timeout,
     NativeOverlapped *lpOverlapped,
コード例 #2
0
 internal static extern unsafe int GetAddrInfoExW(
     [In] string pName,
     [In] string?pServiceName,
     [In] int dwNamespace,
     [In] IntPtr lpNspId,
     [In] AddressInfoEx *pHints,
     [Out] AddressInfoEx **ppResult,
     [In] IntPtr timeout,
     [In] NativeOverlapped *lpOverlapped,
     [In] delegate *unmanaged <int, int, NativeOverlapped *, void> lpCompletionRoutine,
コード例 #3
0
 internal static extern unsafe int GetAddrInfoExW(
     [In] string pName,
     [In] string pServiceName,
     [In] int dwNamespace,
     [In] IntPtr lpNspId,
     [In] AddressInfoEx *pHints,
     [Out] AddressInfoEx **ppResult,
     [In] IntPtr timeout,
     [In] NativeOverlapped *lpOverlapped,
     [In] LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine,
     [Out] IntPtr *lpNameHandle);
コード例 #4
0
 internal static extern unsafe void FreeAddrInfoExW(AddressInfoEx *pAddrInfo);
コード例 #5
0
        private static unsafe void ProcessResult(SocketError errorCode, GetAddrInfoExContext *context)
        {
            try
            {
                GetAddrInfoExState state = GetAddrInfoExState.FromHandleAndFree(context->QueryStateHandle);

                if (errorCode != SocketError.Success)
                {
                    state.CompleteAsyncResult(new SocketException((int)errorCode));
                    return;
                }

                AddressInfoEx *result        = context->Result;
                string         canonicalName = null;

                List <IPAddress> addresses = new List <IPAddress>();

                while (result != null)
                {
                    if (canonicalName == null && result->ai_canonname != IntPtr.Zero)
                    {
                        canonicalName = Marshal.PtrToStringUni(result->ai_canonname);
                    }

                    var socketAddress = new ReadOnlySpan <byte>(result->ai_addr, result->ai_addrlen);

                    if (result->ai_family == AddressFamily.InterNetwork)
                    {
                        if (socketAddress.Length == SocketAddressPal.IPv4AddressSize)
                        {
                            addresses.Add(CreateIPv4Address(socketAddress));
                        }
                    }
                    else if (SocketProtocolSupportPal.OSSupportsIPv6 && result->ai_family == AddressFamily.InterNetworkV6)
                    {
                        if (socketAddress.Length == SocketAddressPal.IPv6AddressSize)
                        {
                            addresses.Add(CreateIPv6Address(socketAddress));
                        }
                    }

                    result = result->ai_next;
                }

                if (canonicalName == null)
                {
                    canonicalName = state.HostName;
                }

                state.CompleteAsyncResult(new IPHostEntry
                {
                    HostName    = canonicalName,
                    Aliases     = Array.Empty <string>(),
                    AddressList = addresses.ToArray()
                });
            }
            finally
            {
                GetAddrInfoExContext.FreeContext(context);
            }
        }
コード例 #6
0
 internal static unsafe partial void FreeAddrInfoExW(AddressInfoEx *pAddrInfo);