77using System . Net . Sockets ;
88using System . Threading ;
99using System . Threading . Tasks ;
10+ using System . Runtime . Versioning ;
1011
1112namespace System . Net
1213{
@@ -37,6 +38,9 @@ public static string GetHostName()
3738
3839 public static IPHostEntry GetHostEntry ( IPAddress address )
3940 {
41+ #if TARGET_WASI
42+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
43+ #endif // TARGET_WASI
4044 ArgumentNullException . ThrowIfNull ( address ) ;
4145
4246 if ( address . Equals ( IPAddress . Any ) || address . Equals ( IPAddress . IPv6Any ) )
@@ -68,6 +72,7 @@ public static IPHostEntry GetHostEntry(string hostNameOrAddress, AddressFamily f
6872
6973 // See if it's an IP Address.
7074 IPHostEntry ipHostEntry ;
75+ #if ! TARGET_WASI
7176 if ( IPAddress . TryParse ( hostNameOrAddress , out IPAddress ? address ) )
7277 {
7378 if ( address . Equals ( IPAddress . Any ) || address . Equals ( IPAddress . IPv6Any ) )
@@ -79,6 +84,7 @@ public static IPHostEntry GetHostEntry(string hostNameOrAddress, AddressFamily f
7984 ipHostEntry = GetHostEntryCore ( address , family ) ;
8085 }
8186 else
87+ #endif // TARGET_WASI
8288 {
8389 ipHostEntry = GetHostEntryCore ( hostNameOrAddress , family ) ;
8490 }
@@ -147,6 +153,9 @@ public static Task<IPHostEntry> GetHostEntryAsync(string hostNameOrAddress, Addr
147153
148154 public static Task < IPHostEntry > GetHostEntryAsync ( IPAddress address )
149155 {
156+ #if TARGET_WASI
157+ throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
158+ #else
150159 ArgumentNullException . ThrowIfNull ( address ) ;
151160
152161 if ( address . Equals ( IPAddress . Any ) || address . Equals ( IPAddress . IPv6Any ) )
@@ -160,6 +169,7 @@ public static Task<IPHostEntry> GetHostEntryAsync(IPAddress address)
160169 if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Info ( ( IPAddress ) s , $ "{ ipHostEntry } with { ipHostEntry . AddressList . Length } entries") ;
161170 return ipHostEntry ;
162171 } , address , CancellationToken . None ) ;
172+ #endif // TARGET_WASI
163173 }
164174
165175 public static IAsyncResult BeginGetHostEntry ( IPAddress address , AsyncCallback ? requestCallback , object ? stateObject ) =>
@@ -170,6 +180,9 @@ public static IAsyncResult BeginGetHostEntry(string hostNameOrAddress, AsyncCall
170180
171181 public static IPHostEntry EndGetHostEntry ( IAsyncResult asyncResult )
172182 {
183+ #if TARGET_WASI
184+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
185+ #endif // TARGET_WASI
173186 ArgumentNullException . ThrowIfNull ( asyncResult ) ;
174187
175188 return TaskToAsyncResult . End < IPHostEntry > ( asyncResult ) ;
@@ -192,6 +205,7 @@ public static IPAddress[] GetHostAddresses(string hostNameOrAddress, AddressFami
192205
193206 // See if it's an IP Address.
194207 IPAddress [ ] addresses ;
208+ #if TARGET_WASI
195209 if ( IPAddress . TryParse ( hostNameOrAddress , out IPAddress ? address ) )
196210 {
197211 if ( address . Equals ( IPAddress . Any ) || address . Equals ( IPAddress . IPv6Any ) )
@@ -203,6 +217,7 @@ public static IPAddress[] GetHostAddresses(string hostNameOrAddress, AddressFami
203217 addresses = ( family == AddressFamily . Unspecified || address . AddressFamily == family ) ? new IPAddress [ ] { address } : Array . Empty < IPAddress > ( ) ;
204218 }
205219 else
220+ #endif // TARGET_WASI
206221 {
207222 addresses = GetHostAddressesCore ( hostNameOrAddress , family ) ;
208223 }
@@ -244,6 +259,9 @@ public static IAsyncResult BeginGetHostAddresses(string hostNameOrAddress, Async
244259
245260 public static IPAddress [ ] EndGetHostAddresses ( IAsyncResult asyncResult )
246261 {
262+ #if TARGET_WASI
263+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
264+ #endif // TARGET_WASI
247265 ArgumentNullException . ThrowIfNull ( asyncResult ) ;
248266
249267 return TaskToAsyncResult . End < IPAddress [ ] > ( asyncResult ) ;
@@ -269,6 +287,9 @@ public static IAsyncResult BeginGetHostByName(string hostName, AsyncCallback? re
269287 [ Obsolete ( "EndGetHostByName has been deprecated. Use EndGetHostEntry instead." ) ]
270288 public static IPHostEntry EndGetHostByName ( IAsyncResult asyncResult )
271289 {
290+ #if TARGET_WASI
291+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
292+ #endif // TARGET_WASI
272293 ArgumentNullException . ThrowIfNull ( asyncResult ) ;
273294
274295 return TaskToAsyncResult . End < IPHostEntry > ( asyncResult ) ;
@@ -277,6 +298,9 @@ public static IPHostEntry EndGetHostByName(IAsyncResult asyncResult)
277298 [ Obsolete ( "GetHostByAddress has been deprecated. Use GetHostEntry instead." ) ]
278299 public static IPHostEntry GetHostByAddress ( string address )
279300 {
301+ #if TARGET_WASI
302+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
303+ #endif // TARGET_WASI
280304 ArgumentNullException . ThrowIfNull ( address ) ;
281305
282306 IPHostEntry ipHostEntry = GetHostEntryCore ( IPAddress . Parse ( address ) , AddressFamily . Unspecified ) ;
@@ -288,6 +312,9 @@ public static IPHostEntry GetHostByAddress(string address)
288312 [ Obsolete ( "GetHostByAddress has been deprecated. Use GetHostEntry instead." ) ]
289313 public static IPHostEntry GetHostByAddress ( IPAddress address )
290314 {
315+ #if TARGET_WASI
316+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
317+ #endif // TARGET_WASI
291318 ArgumentNullException . ThrowIfNull ( address ) ;
292319
293320 IPHostEntry ipHostEntry = GetHostEntryCore ( address , AddressFamily . Unspecified ) ;
@@ -303,6 +330,7 @@ public static IPHostEntry Resolve(string hostName)
303330
304331 // See if it's an IP Address.
305332 IPHostEntry ipHostEntry ;
333+ #if ! TARGET_WASI
306334 if ( IPAddress . TryParse ( hostName , out IPAddress ? address ) &&
307335 ( address . AddressFamily != AddressFamily . InterNetworkV6 || SocketProtocolSupportPal . OSSupportsIPv6 ) )
308336 {
@@ -317,6 +345,7 @@ public static IPHostEntry Resolve(string hostName)
317345 }
318346 }
319347 else
348+ #endif // TARGET_WASI
320349 {
321350 ipHostEntry = GetHostEntryCore ( hostName , AddressFamily . Unspecified ) ;
322351 }
@@ -332,6 +361,9 @@ public static IAsyncResult BeginResolve(string hostName, AsyncCallback? requestC
332361 [ Obsolete ( "EndResolve has been deprecated. Use EndGetHostEntry instead." ) ]
333362 public static IPHostEntry EndResolve ( IAsyncResult asyncResult )
334363 {
364+ #if TARGET_WASI
365+ if ( OperatingSystem . IsWasi ( ) ) throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
366+ #endif // TARGET_WASI
335367 IPHostEntry ipHostEntry ;
336368
337369 try
@@ -405,13 +437,16 @@ private static object GetHostEntryOrAddressesCore(string hostName, bool justAddr
405437 return result ;
406438 }
407439
440+ [ UnsupportedOSPlatform ( "wasi" ) ]
408441 private static IPHostEntry GetHostEntryCore ( IPAddress address , AddressFamily addressFamily , NameResolutionActivity ? activityOrDefault = default ) =>
409442 ( IPHostEntry ) GetHostEntryOrAddressesCore ( address , justAddresses : false , addressFamily , activityOrDefault ) ;
410443
444+ [ UnsupportedOSPlatform ( "wasi" ) ]
411445 private static IPAddress [ ] GetHostAddressesCore ( IPAddress address , AddressFamily addressFamily , NameResolutionActivity ? activityOrDefault = default ) =>
412446 ( IPAddress [ ] ) GetHostEntryOrAddressesCore ( address , justAddresses : true , addressFamily , activityOrDefault ) ;
413447
414448 // Does internal IPAddress reverse and then forward lookups (for Legacy and current public methods).
449+ [ UnsupportedOSPlatform ( "wasi" ) ]
415450 private static object GetHostEntryOrAddressesCore ( IPAddress address , bool justAddresses , AddressFamily addressFamily , NameResolutionActivity ? activityOrDefault = default )
416451 {
417452 // Try to get the data for the host from its address.
@@ -499,6 +534,7 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR
499534
500535 object asyncState ;
501536
537+ #if ! TARGET_WASI
502538 // See if it's an IP Address.
503539 if ( IPAddress . TryParse ( hostName , out IPAddress ? ipAddress ) )
504540 {
@@ -518,6 +554,7 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR
518554 asyncState = family == AddressFamily . Unspecified ? ( object ) ipAddress : new KeyValuePair < IPAddress , AddressFamily > ( ipAddress , family ) ;
519555 }
520556 else
557+ #endif // TARGET_WASI
521558 {
522559 if ( NameResolutionPal . SupportsGetAddrInfoAsync )
523560 {
@@ -558,8 +595,13 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR
558595 {
559596 string h => GetHostAddressesCore ( h , AddressFamily . Unspecified , activity ) ,
560597 KeyValuePair < string , AddressFamily > t => GetHostAddressesCore ( t . Key , t . Value , activity ) ,
598+ #if ! TARGET_WASI
561599 IPAddress a => GetHostAddressesCore ( a , AddressFamily . Unspecified , activity ) ,
562600 KeyValuePair < IPAddress , AddressFamily > t => GetHostAddressesCore ( t . Key , t . Value , activity ) ,
601+ #else
602+ IPAddress => throw new PlatformNotSupportedException ( ) ,
603+ KeyValuePair < IPAddress , AddressFamily > => throw new PlatformNotSupportedException ( ) ,
604+ #endif // TARGET_WASI
563605 _ => null
564606 } , asyncState , cancellationToken ) ;
565607 }
@@ -569,8 +611,13 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR
569611 {
570612 string h => GetHostEntryCore ( h , AddressFamily . Unspecified , activity ) ,
571613 KeyValuePair < string , AddressFamily > t => GetHostEntryCore ( t . Key , t . Value , activity ) ,
614+ #if ! TARGET_WASI
572615 IPAddress a => GetHostEntryCore ( a , AddressFamily . Unspecified , activity ) ,
573616 KeyValuePair < IPAddress , AddressFamily > t => GetHostEntryCore ( t . Key , t . Value , activity ) ,
617+ #else
618+ IPAddress => throw new PlatformNotSupportedException ( ) ,
619+ KeyValuePair < IPAddress , AddressFamily > => throw new PlatformNotSupportedException ( ) ,
620+ #endif // TARGET_WASI
574621 _ => null
575622 } , asyncState , cancellationToken ) ;
576623 }
0 commit comments