From 725af70eba8f147eff27cdb6691d354be33d7e99 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 14 Jun 2021 15:58:44 -0700 Subject: [PATCH] Use GeneratedDllImport in System.Net.NameResolution --- .../Unix/System.Native/Interop.HostEntry.cs | 4 ++-- .../Windows/WinSock/Interop.GetAddrInfoExW.cs | 24 +++++++++---------- .../Windows/WinSock/Interop.GetAddrInfoW.cs | 16 ++++++------- .../Windows/WinSock/Interop.GetNameInfoW.cs | 4 ++-- .../Windows/WinSock/Interop.gethostname.cs | 4 ++-- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.HostEntry.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.HostEntry.cs index d197637043e8a..98372054ec046 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.HostEntry.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.HostEntry.cs @@ -32,8 +32,8 @@ internal unsafe struct HostEntry internal int IPAddressCount; // Number of IP addresses in the list } - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetHostEntryForName")] - internal static extern unsafe int GetHostEntryForName(string address, AddressFamily family, HostEntry* entry); + [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetHostEntryForName", CharSet = CharSet.Ansi)] + internal static unsafe partial int GetHostEntryForName(string address, AddressFamily family, HostEntry* entry); [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FreeHostEntry")] internal static extern unsafe void FreeHostEntry(HostEntry* entry); diff --git a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.GetAddrInfoExW.cs b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.GetAddrInfoExW.cs index 8129b25332f4d..8501c538ba0e0 100644 --- a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.GetAddrInfoExW.cs +++ b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.GetAddrInfoExW.cs @@ -17,18 +17,18 @@ internal static partial class Winsock internal const int NS_ALL = 0; - [DllImport(Libraries.Ws2_32, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] - 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 lpCompletionRoutine, - [Out] IntPtr* lpNameHandle); + [GeneratedDllImport(Libraries.Ws2_32, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] + internal static unsafe partial int GetAddrInfoExW( + string pName, + string? pServiceName, + int dwNamespace, + IntPtr lpNspId, + AddressInfoEx* pHints, + AddressInfoEx** ppResult, + IntPtr timeout, + NativeOverlapped* lpOverlapped, + delegate* unmanaged lpCompletionRoutine, + IntPtr* lpNameHandle); [DllImport(Libraries.Ws2_32, ExactSpelling = true)] internal static extern unsafe int GetAddrInfoExCancel([In] IntPtr* lpHandle); diff --git a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.GetAddrInfoW.cs b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.GetAddrInfoW.cs index 01fdff217eeba..d3a28a4808e21 100644 --- a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.GetAddrInfoW.cs +++ b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.GetAddrInfoW.cs @@ -9,15 +9,15 @@ internal static partial class Interop { internal static partial class Winsock { - [DllImport(Interop.Libraries.Ws2_32, ExactSpelling = true, CharSet = CharSet.Unicode, BestFitMapping = false, ThrowOnUnmappableChar = true, SetLastError = true)] - internal static extern unsafe int GetAddrInfoW( - [In] string pNameName, - [In] string? pServiceName, - [In] AddressInfo* pHints, - [Out] AddressInfo** ppResult); + [GeneratedDllImport(Interop.Libraries.Ws2_32, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] + internal static unsafe partial int GetAddrInfoW( + string pNameName, + string? pServiceName, + AddressInfo* pHints, + AddressInfo** ppResult); - [DllImport(Interop.Libraries.Ws2_32, ExactSpelling = true, SetLastError = true)] - internal static extern unsafe void FreeAddrInfoW(AddressInfo* info); + [GeneratedDllImport(Interop.Libraries.Ws2_32, ExactSpelling = true, SetLastError = true)] + internal static unsafe partial void FreeAddrInfoW(AddressInfo* info); [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] internal unsafe struct AddressInfo diff --git a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.GetNameInfoW.cs b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.GetNameInfoW.cs index 13673f2adff7d..7825ed7ac5ae2 100644 --- a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.GetNameInfoW.cs +++ b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.GetNameInfoW.cs @@ -19,8 +19,8 @@ internal enum NameInfoFlags NI_DGRAM = 0x10, /* Service is a datagram service */ } - [DllImport(Interop.Libraries.Ws2_32, CharSet = CharSet.Unicode, BestFitMapping = false, ThrowOnUnmappableChar = true, SetLastError = true)] - internal static extern unsafe SocketError GetNameInfoW( + [GeneratedDllImport(Interop.Libraries.Ws2_32, CharSet = CharSet.Unicode, SetLastError = true)] + internal static unsafe partial SocketError GetNameInfoW( byte* pSockaddr, int SockaddrLength, char* pNodeBuffer, diff --git a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.gethostname.cs b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.gethostname.cs index 292b73230406c..54b90ef1df81f 100644 --- a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.gethostname.cs +++ b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.gethostname.cs @@ -8,7 +8,7 @@ internal static partial class Interop { internal static partial class Winsock { - [DllImport(Interop.Libraries.Ws2_32, SetLastError = true)] - internal static extern unsafe SocketError gethostname(byte* name, int namelen); + [GeneratedDllImport(Interop.Libraries.Ws2_32, SetLastError = true)] + internal static unsafe partial SocketError gethostname(byte* name, int namelen); } }