7
7
using System . Net . Sockets ;
8
8
using System . Threading ;
9
9
using System . Threading . Tasks ;
10
+ using System . Runtime . Versioning ;
10
11
11
12
namespace System . Net
12
13
{
@@ -37,6 +38,9 @@ public static string GetHostName()
37
38
38
39
public static IPHostEntry GetHostEntry ( IPAddress address )
39
40
{
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
40
44
ArgumentNullException . ThrowIfNull ( address ) ;
41
45
42
46
if ( address . Equals ( IPAddress . Any ) || address . Equals ( IPAddress . IPv6Any ) )
@@ -68,6 +72,7 @@ public static IPHostEntry GetHostEntry(string hostNameOrAddress, AddressFamily f
68
72
69
73
// See if it's an IP Address.
70
74
IPHostEntry ipHostEntry ;
75
+ #if ! TARGET_WASI
71
76
if ( IPAddress . TryParse ( hostNameOrAddress , out IPAddress ? address ) )
72
77
{
73
78
if ( address . Equals ( IPAddress . Any ) || address . Equals ( IPAddress . IPv6Any ) )
@@ -79,6 +84,7 @@ public static IPHostEntry GetHostEntry(string hostNameOrAddress, AddressFamily f
79
84
ipHostEntry = GetHostEntryCore ( address , family ) ;
80
85
}
81
86
else
87
+ #endif // TARGET_WASI
82
88
{
83
89
ipHostEntry = GetHostEntryCore ( hostNameOrAddress , family ) ;
84
90
}
@@ -147,6 +153,9 @@ public static Task<IPHostEntry> GetHostEntryAsync(string hostNameOrAddress, Addr
147
153
148
154
public static Task < IPHostEntry > GetHostEntryAsync ( IPAddress address )
149
155
{
156
+ #if TARGET_WASI
157
+ throw new PlatformNotSupportedException ( ) ; // TODO remove with https://github.com/dotnet/runtime/pull/107185
158
+ #else
150
159
ArgumentNullException . ThrowIfNull ( address ) ;
151
160
152
161
if ( address . Equals ( IPAddress . Any ) || address . Equals ( IPAddress . IPv6Any ) )
@@ -160,6 +169,7 @@ public static Task<IPHostEntry> GetHostEntryAsync(IPAddress address)
160
169
if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Info ( ( IPAddress ) s , $ "{ ipHostEntry } with { ipHostEntry . AddressList . Length } entries") ;
161
170
return ipHostEntry ;
162
171
} , address , CancellationToken . None ) ;
172
+ #endif // TARGET_WASI
163
173
}
164
174
165
175
public static IAsyncResult BeginGetHostEntry ( IPAddress address , AsyncCallback ? requestCallback , object ? stateObject ) =>
@@ -170,6 +180,9 @@ public static IAsyncResult BeginGetHostEntry(string hostNameOrAddress, AsyncCall
170
180
171
181
public static IPHostEntry EndGetHostEntry ( IAsyncResult asyncResult )
172
182
{
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
173
186
ArgumentNullException . ThrowIfNull ( asyncResult ) ;
174
187
175
188
return TaskToAsyncResult . End < IPHostEntry > ( asyncResult ) ;
@@ -192,6 +205,7 @@ public static IPAddress[] GetHostAddresses(string hostNameOrAddress, AddressFami
192
205
193
206
// See if it's an IP Address.
194
207
IPAddress [ ] addresses ;
208
+ #if TARGET_WASI
195
209
if ( IPAddress . TryParse ( hostNameOrAddress , out IPAddress ? address ) )
196
210
{
197
211
if ( address . Equals ( IPAddress . Any ) || address . Equals ( IPAddress . IPv6Any ) )
@@ -203,6 +217,7 @@ public static IPAddress[] GetHostAddresses(string hostNameOrAddress, AddressFami
203
217
addresses = ( family == AddressFamily . Unspecified || address . AddressFamily == family ) ? new IPAddress [ ] { address } : Array . Empty < IPAddress > ( ) ;
204
218
}
205
219
else
220
+ #endif // TARGET_WASI
206
221
{
207
222
addresses = GetHostAddressesCore ( hostNameOrAddress , family ) ;
208
223
}
@@ -244,6 +259,9 @@ public static IAsyncResult BeginGetHostAddresses(string hostNameOrAddress, Async
244
259
245
260
public static IPAddress [ ] EndGetHostAddresses ( IAsyncResult asyncResult )
246
261
{
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
247
265
ArgumentNullException . ThrowIfNull ( asyncResult ) ;
248
266
249
267
return TaskToAsyncResult . End < IPAddress [ ] > ( asyncResult ) ;
@@ -269,6 +287,9 @@ public static IAsyncResult BeginGetHostByName(string hostName, AsyncCallback? re
269
287
[ Obsolete ( "EndGetHostByName has been deprecated. Use EndGetHostEntry instead." ) ]
270
288
public static IPHostEntry EndGetHostByName ( IAsyncResult asyncResult )
271
289
{
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
272
293
ArgumentNullException . ThrowIfNull ( asyncResult ) ;
273
294
274
295
return TaskToAsyncResult . End < IPHostEntry > ( asyncResult ) ;
@@ -277,6 +298,9 @@ public static IPHostEntry EndGetHostByName(IAsyncResult asyncResult)
277
298
[ Obsolete ( "GetHostByAddress has been deprecated. Use GetHostEntry instead." ) ]
278
299
public static IPHostEntry GetHostByAddress ( string address )
279
300
{
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
280
304
ArgumentNullException . ThrowIfNull ( address ) ;
281
305
282
306
IPHostEntry ipHostEntry = GetHostEntryCore ( IPAddress . Parse ( address ) , AddressFamily . Unspecified ) ;
@@ -288,6 +312,9 @@ public static IPHostEntry GetHostByAddress(string address)
288
312
[ Obsolete ( "GetHostByAddress has been deprecated. Use GetHostEntry instead." ) ]
289
313
public static IPHostEntry GetHostByAddress ( IPAddress address )
290
314
{
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
291
318
ArgumentNullException . ThrowIfNull ( address ) ;
292
319
293
320
IPHostEntry ipHostEntry = GetHostEntryCore ( address , AddressFamily . Unspecified ) ;
@@ -303,6 +330,7 @@ public static IPHostEntry Resolve(string hostName)
303
330
304
331
// See if it's an IP Address.
305
332
IPHostEntry ipHostEntry ;
333
+ #if ! TARGET_WASI
306
334
if ( IPAddress . TryParse ( hostName , out IPAddress ? address ) &&
307
335
( address . AddressFamily != AddressFamily . InterNetworkV6 || SocketProtocolSupportPal . OSSupportsIPv6 ) )
308
336
{
@@ -317,6 +345,7 @@ public static IPHostEntry Resolve(string hostName)
317
345
}
318
346
}
319
347
else
348
+ #endif // TARGET_WASI
320
349
{
321
350
ipHostEntry = GetHostEntryCore ( hostName , AddressFamily . Unspecified ) ;
322
351
}
@@ -332,6 +361,9 @@ public static IAsyncResult BeginResolve(string hostName, AsyncCallback? requestC
332
361
[ Obsolete ( "EndResolve has been deprecated. Use EndGetHostEntry instead." ) ]
333
362
public static IPHostEntry EndResolve ( IAsyncResult asyncResult )
334
363
{
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
335
367
IPHostEntry ipHostEntry ;
336
368
337
369
try
@@ -405,13 +437,16 @@ private static object GetHostEntryOrAddressesCore(string hostName, bool justAddr
405
437
return result ;
406
438
}
407
439
440
+ [ UnsupportedOSPlatform ( "wasi" ) ]
408
441
private static IPHostEntry GetHostEntryCore ( IPAddress address , AddressFamily addressFamily , NameResolutionActivity ? activityOrDefault = default ) =>
409
442
( IPHostEntry ) GetHostEntryOrAddressesCore ( address , justAddresses : false , addressFamily , activityOrDefault ) ;
410
443
444
+ [ UnsupportedOSPlatform ( "wasi" ) ]
411
445
private static IPAddress [ ] GetHostAddressesCore ( IPAddress address , AddressFamily addressFamily , NameResolutionActivity ? activityOrDefault = default ) =>
412
446
( IPAddress [ ] ) GetHostEntryOrAddressesCore ( address , justAddresses : true , addressFamily , activityOrDefault ) ;
413
447
414
448
// Does internal IPAddress reverse and then forward lookups (for Legacy and current public methods).
449
+ [ UnsupportedOSPlatform ( "wasi" ) ]
415
450
private static object GetHostEntryOrAddressesCore ( IPAddress address , bool justAddresses , AddressFamily addressFamily , NameResolutionActivity ? activityOrDefault = default )
416
451
{
417
452
// Try to get the data for the host from its address.
@@ -499,6 +534,7 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR
499
534
500
535
object asyncState ;
501
536
537
+ #if ! TARGET_WASI
502
538
// See if it's an IP Address.
503
539
if ( IPAddress . TryParse ( hostName , out IPAddress ? ipAddress ) )
504
540
{
@@ -518,6 +554,7 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR
518
554
asyncState = family == AddressFamily . Unspecified ? ( object ) ipAddress : new KeyValuePair < IPAddress , AddressFamily > ( ipAddress , family ) ;
519
555
}
520
556
else
557
+ #endif // TARGET_WASI
521
558
{
522
559
if ( NameResolutionPal . SupportsGetAddrInfoAsync )
523
560
{
@@ -558,8 +595,13 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR
558
595
{
559
596
string h => GetHostAddressesCore ( h , AddressFamily . Unspecified , activity ) ,
560
597
KeyValuePair < string , AddressFamily > t => GetHostAddressesCore ( t . Key , t . Value , activity ) ,
598
+ #if ! TARGET_WASI
561
599
IPAddress a => GetHostAddressesCore ( a , AddressFamily . Unspecified , activity ) ,
562
600
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
563
605
_ => null
564
606
} , asyncState , cancellationToken ) ;
565
607
}
@@ -569,8 +611,13 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR
569
611
{
570
612
string h => GetHostEntryCore ( h , AddressFamily . Unspecified , activity ) ,
571
613
KeyValuePair < string , AddressFamily > t => GetHostEntryCore ( t . Key , t . Value , activity ) ,
614
+ #if ! TARGET_WASI
572
615
IPAddress a => GetHostEntryCore ( a , AddressFamily . Unspecified , activity ) ,
573
616
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
574
621
_ => null
575
622
} , asyncState , cancellationToken ) ;
576
623
}
0 commit comments