77using System . Net . Sockets ;
88using System . Threading ;
99using System . Threading . Tasks ;
10+ using System . Runtime . Versioning ;
1011
1112namespace System . Net
1213{
@@ -37,6 +38,8 @@ public static string GetHostName()
3738
3839 public static IPHostEntry GetHostEntry ( IPAddress address )
3940 {
41+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
42+
4043 ArgumentNullException . ThrowIfNull ( address ) ;
4144
4245 if ( address . Equals ( IPAddress . Any ) || address . Equals ( IPAddress . IPv6Any ) )
@@ -68,7 +71,7 @@ public static IPHostEntry GetHostEntry(string hostNameOrAddress, AddressFamily f
6871
6972 // See if it's an IP Address.
7073 IPHostEntry ipHostEntry ;
71- if ( IPAddress . TryParse ( hostNameOrAddress , out IPAddress ? address ) )
74+ if ( NameResolutionPal . SupportsGetNameInfo && IPAddress . TryParse ( hostNameOrAddress , out IPAddress ? address ) )
7275 {
7376 if ( address . Equals ( IPAddress . Any ) || address . Equals ( IPAddress . IPv6Any ) )
7477 {
@@ -147,6 +150,8 @@ public static Task<IPHostEntry> GetHostEntryAsync(string hostNameOrAddress, Addr
147150
148151 public static Task < IPHostEntry > GetHostEntryAsync ( IPAddress address )
149152 {
153+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
154+
150155 ArgumentNullException . ThrowIfNull ( address ) ;
151156
152157 if ( address . Equals ( IPAddress . Any ) || address . Equals ( IPAddress . IPv6Any ) )
@@ -156,6 +161,8 @@ public static Task<IPHostEntry> GetHostEntryAsync(IPAddress address)
156161 }
157162
158163 return RunAsync ( static ( s , activity ) => {
164+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
165+
159166 IPHostEntry ipHostEntry = GetHostEntryCore ( ( IPAddress ) s , AddressFamily . Unspecified , activity ) ;
160167 if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Info ( ( IPAddress ) s , $ "{ ipHostEntry } with { ipHostEntry . AddressList . Length } entries") ;
161168 return ipHostEntry ;
@@ -170,6 +177,8 @@ public static IAsyncResult BeginGetHostEntry(string hostNameOrAddress, AsyncCall
170177
171178 public static IPHostEntry EndGetHostEntry ( IAsyncResult asyncResult )
172179 {
180+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
181+
173182 ArgumentNullException . ThrowIfNull ( asyncResult ) ;
174183
175184 return TaskToAsyncResult . End < IPHostEntry > ( asyncResult ) ;
@@ -244,6 +253,8 @@ public static IAsyncResult BeginGetHostAddresses(string hostNameOrAddress, Async
244253
245254 public static IPAddress [ ] EndGetHostAddresses ( IAsyncResult asyncResult )
246255 {
256+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
257+
247258 ArgumentNullException . ThrowIfNull ( asyncResult ) ;
248259
249260 return TaskToAsyncResult . End < IPAddress [ ] > ( asyncResult ) ;
@@ -269,6 +280,8 @@ public static IAsyncResult BeginGetHostByName(string hostName, AsyncCallback? re
269280 [ Obsolete ( "EndGetHostByName has been deprecated. Use EndGetHostEntry instead." ) ]
270281 public static IPHostEntry EndGetHostByName ( IAsyncResult asyncResult )
271282 {
283+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
284+
272285 ArgumentNullException . ThrowIfNull ( asyncResult ) ;
273286
274287 return TaskToAsyncResult . End < IPHostEntry > ( asyncResult ) ;
@@ -277,6 +290,8 @@ public static IPHostEntry EndGetHostByName(IAsyncResult asyncResult)
277290 [ Obsolete ( "GetHostByAddress has been deprecated. Use GetHostEntry instead." ) ]
278291 public static IPHostEntry GetHostByAddress ( string address )
279292 {
293+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
294+
280295 ArgumentNullException . ThrowIfNull ( address ) ;
281296
282297 IPHostEntry ipHostEntry = GetHostEntryCore ( IPAddress . Parse ( address ) , AddressFamily . Unspecified ) ;
@@ -288,6 +303,8 @@ public static IPHostEntry GetHostByAddress(string address)
288303 [ Obsolete ( "GetHostByAddress has been deprecated. Use GetHostEntry instead." ) ]
289304 public static IPHostEntry GetHostByAddress ( IPAddress address )
290305 {
306+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
307+
291308 ArgumentNullException . ThrowIfNull ( address ) ;
292309
293310 IPHostEntry ipHostEntry = GetHostEntryCore ( address , AddressFamily . Unspecified ) ;
@@ -303,7 +320,7 @@ public static IPHostEntry Resolve(string hostName)
303320
304321 // See if it's an IP Address.
305322 IPHostEntry ipHostEntry ;
306- if ( IPAddress . TryParse ( hostName , out IPAddress ? address ) &&
323+ if ( NameResolutionPal . SupportsGetNameInfo && IPAddress . TryParse ( hostName , out IPAddress ? address ) &&
307324 ( address . AddressFamily != AddressFamily . InterNetworkV6 || SocketProtocolSupportPal . OSSupportsIPv6 ) )
308325 {
309326 try
@@ -332,6 +349,8 @@ public static IAsyncResult BeginResolve(string hostName, AsyncCallback? requestC
332349 [ Obsolete ( "EndResolve has been deprecated. Use EndGetHostEntry instead." ) ]
333350 public static IPHostEntry EndResolve ( IAsyncResult asyncResult )
334351 {
352+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
353+
335354 IPHostEntry ipHostEntry ;
336355
337356 try
@@ -414,6 +433,8 @@ private static IPAddress[] GetHostAddressesCore(IPAddress address, AddressFamily
414433 // Does internal IPAddress reverse and then forward lookups (for Legacy and current public methods).
415434 private static object GetHostEntryOrAddressesCore ( IPAddress address , bool justAddresses , AddressFamily addressFamily , NameResolutionActivity ? activityOrDefault = default )
416435 {
436+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
437+
417438 // Try to get the data for the host from its address.
418439 // We need to call getnameinfo first, because getaddrinfo w/ the ipaddress string
419440 // will only return that address and not the full list.
@@ -500,7 +521,7 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR
500521 object asyncState ;
501522
502523 // See if it's an IP Address.
503- if ( IPAddress . TryParse ( hostName , out IPAddress ? ipAddress ) )
524+ if ( NameResolutionPal . SupportsGetNameInfo && IPAddress . TryParse ( hostName , out IPAddress ? ipAddress ) )
504525 {
505526 if ( throwOnIIPAny && ( ipAddress . Equals ( IPAddress . Any ) || ipAddress . Equals ( IPAddress . IPv6Any ) ) )
506527 {
0 commit comments