diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs index 5cc0c19772753..888c243521f83 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs @@ -14,6 +14,11 @@ internal static partial class Sys internal static unsafe string GetHostName() { + if (OperatingSystem.IsWasi()) + { + return "localhost"; + } + const int HOST_NAME_MAX = 255; const int ArrLength = HOST_NAME_MAX + 1; 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 b8bc38524a59c..8d00d95ebf214 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 @@ -21,6 +21,7 @@ internal enum GetAddrInfoErrorFlags : int EAI_BADARG = 6, // One or more input arguments were invalid. EAI_NOMORE = 7, // No more entries are present in the list. EAI_MEMORY = 8, // Out of memory. + EAI_SYSTEM = 9, // Other system error; errno is set to indicate the error. } [StructLayout(LayoutKind.Sequential)] diff --git a/src/libraries/System.Net.NameResolution/Directory.Build.props b/src/libraries/System.Net.NameResolution/Directory.Build.props index bc799605d32ed..ce244cbea5619 100644 --- a/src/libraries/System.Net.NameResolution/Directory.Build.props +++ b/src/libraries/System.Net.NameResolution/Directory.Build.props @@ -3,7 +3,6 @@ Microsoft true - - browser;wasi + browser \ No newline at end of file diff --git a/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj b/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj index c5c8b4ffc9a58..582fe6cc88241 100644 --- a/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj +++ b/src/libraries/System.Net.NameResolution/src/System.Net.NameResolution.csproj @@ -9,14 +9,14 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) - SR.SystemNetNameResolution_PlatformNotSupported - ExcludeApiList.PNSE.Browser.txt + SR.SystemNetNameResolution_PlatformNotSupported + ExcludeApiList.PNSE.Browser.txt - + @@ -80,6 +80,8 @@ Link="Common\Interop\CoreLib\Unix\Interop.Errors.cs" /> + - + + + + + + + + + + + + + + + + + + + diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs b/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs index c8a526ccc4b3c..5bedc17d253f8 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs @@ -7,6 +7,7 @@ using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; +using System.Runtime.Versioning; namespace System.Net { @@ -37,6 +38,8 @@ public static string GetHostName() public static IPHostEntry GetHostEntry(IPAddress address) { + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + ArgumentNullException.ThrowIfNull(address); if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)) @@ -68,7 +71,7 @@ public static IPHostEntry GetHostEntry(string hostNameOrAddress, AddressFamily f // See if it's an IP Address. IPHostEntry ipHostEntry; - if (IPAddress.TryParse(hostNameOrAddress, out IPAddress? address)) + if (NameResolutionPal.SupportsGetNameInfo && IPAddress.TryParse(hostNameOrAddress, out IPAddress? address)) { if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)) { @@ -147,6 +150,8 @@ public static Task GetHostEntryAsync(string hostNameOrAddress, Addr public static Task GetHostEntryAsync(IPAddress address) { + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + ArgumentNullException.ThrowIfNull(address); if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any)) @@ -156,6 +161,8 @@ public static Task GetHostEntryAsync(IPAddress address) } return RunAsync(static (s, activity) => { + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + IPHostEntry ipHostEntry = GetHostEntryCore((IPAddress)s, AddressFamily.Unspecified, activity); if (NetEventSource.Log.IsEnabled()) NetEventSource.Info((IPAddress)s, $"{ipHostEntry} with {ipHostEntry.AddressList.Length} entries"); return ipHostEntry; @@ -170,6 +177,8 @@ public static IAsyncResult BeginGetHostEntry(string hostNameOrAddress, AsyncCall public static IPHostEntry EndGetHostEntry(IAsyncResult asyncResult) { + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + ArgumentNullException.ThrowIfNull(asyncResult); return TaskToAsyncResult.End(asyncResult); @@ -244,6 +253,8 @@ public static IAsyncResult BeginGetHostAddresses(string hostNameOrAddress, Async public static IPAddress[] EndGetHostAddresses(IAsyncResult asyncResult) { + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + ArgumentNullException.ThrowIfNull(asyncResult); return TaskToAsyncResult.End(asyncResult); @@ -269,6 +280,8 @@ public static IAsyncResult BeginGetHostByName(string hostName, AsyncCallback? re [Obsolete("EndGetHostByName has been deprecated. Use EndGetHostEntry instead.")] public static IPHostEntry EndGetHostByName(IAsyncResult asyncResult) { + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + ArgumentNullException.ThrowIfNull(asyncResult); return TaskToAsyncResult.End(asyncResult); @@ -277,6 +290,8 @@ public static IPHostEntry EndGetHostByName(IAsyncResult asyncResult) [Obsolete("GetHostByAddress has been deprecated. Use GetHostEntry instead.")] public static IPHostEntry GetHostByAddress(string address) { + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + ArgumentNullException.ThrowIfNull(address); IPHostEntry ipHostEntry = GetHostEntryCore(IPAddress.Parse(address), AddressFamily.Unspecified); @@ -288,6 +303,8 @@ public static IPHostEntry GetHostByAddress(string address) [Obsolete("GetHostByAddress has been deprecated. Use GetHostEntry instead.")] public static IPHostEntry GetHostByAddress(IPAddress address) { + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + ArgumentNullException.ThrowIfNull(address); IPHostEntry ipHostEntry = GetHostEntryCore(address, AddressFamily.Unspecified); @@ -303,7 +320,7 @@ public static IPHostEntry Resolve(string hostName) // See if it's an IP Address. IPHostEntry ipHostEntry; - if (IPAddress.TryParse(hostName, out IPAddress? address) && + if (NameResolutionPal.SupportsGetNameInfo && IPAddress.TryParse(hostName, out IPAddress? address) && (address.AddressFamily != AddressFamily.InterNetworkV6 || SocketProtocolSupportPal.OSSupportsIPv6)) { try @@ -332,6 +349,8 @@ public static IAsyncResult BeginResolve(string hostName, AsyncCallback? requestC [Obsolete("EndResolve has been deprecated. Use EndGetHostEntry instead.")] public static IPHostEntry EndResolve(IAsyncResult asyncResult) { + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + IPHostEntry ipHostEntry; try @@ -414,6 +433,8 @@ private static IPAddress[] GetHostAddressesCore(IPAddress address, AddressFamily // Does internal IPAddress reverse and then forward lookups (for Legacy and current public methods). private static object GetHostEntryOrAddressesCore(IPAddress address, bool justAddresses, AddressFamily addressFamily, NameResolutionActivity? activityOrDefault = default) { + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + // Try to get the data for the host from its address. // We need to call getnameinfo first, because getaddrinfo w/ the ipaddress string // will only return that address and not the full list. @@ -500,7 +521,7 @@ private static Task GetHostEntryOrAddressesCoreAsync(string hostName, bool justR object asyncState; // See if it's an IP Address. - if (IPAddress.TryParse(hostName, out IPAddress? ipAddress)) + if (NameResolutionPal.SupportsGetNameInfo && IPAddress.TryParse(hostName, out IPAddress? ipAddress)) { if (throwOnIIPAny && (ipAddress.Equals(IPAddress.Any) || ipAddress.Equals(IPAddress.IPv6Any))) { diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs index 54ec640a3b071..c2924830c07be 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Unix.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Runtime.Versioning; namespace System.Net { @@ -15,6 +16,9 @@ internal static partial class NameResolutionPal { public const bool SupportsGetAddrInfoAsync = false; + [UnsupportedOSPlatformGuard("wasi")] + public static bool SupportsGetNameInfo => !OperatingSystem.IsWasi(); + #pragma warning disable IDE0060 internal static Task? GetAddrInfoAsync(string hostName, bool justAddresses, AddressFamily family, CancellationToken cancellationToken) => throw new NotSupportedException(); @@ -39,6 +43,9 @@ private static SocketError GetSocketErrorForNativeError(int error) return SocketError.HostNotFound; case (int)Interop.Sys.GetAddrInfoErrorFlags.EAI_MEMORY: throw new OutOfMemoryException(); + case (int)Interop.Sys.GetAddrInfoErrorFlags.EAI_SYSTEM: + Debug.Fail($"Unexpected error: {error} errno: {Interop.Sys.GetErrNo()}"); + return SocketError.SocketError; default: Debug.Fail($"Unexpected error: {error}"); return SocketError.SocketError; @@ -146,6 +153,8 @@ public static unsafe SocketError TryGetAddrInfo(string name, bool justAddresses, public static unsafe string? TryGetNameInfo(IPAddress addr, out SocketError socketError, out int nativeErrorCode) { + if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185 + byte* buffer = stackalloc byte[Interop.Sys.NI_MAXHOST + 1 /*for null*/]; byte isIPv6; diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs index 72fc7685dffe9..a044e20461273 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Win32.SafeHandles; +using System.Runtime.Versioning; namespace System.Net { @@ -43,6 +44,8 @@ static void Initialize() } } + public const bool SupportsGetNameInfo = true; + public static unsafe SocketError TryGetAddrInfo(string name, bool justAddresses, AddressFamily addressFamily, out string? hostName, out string[] aliases, out IPAddress[] addresses, out int nativeErrorCode) { Interop.Winsock.EnsureInitialized(); diff --git a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs index 07a252fbd250c..defa4da90564b 100644 --- a/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs +++ b/src/libraries/System.Net.NameResolution/src/System/Net/NameResolutionTelemetry.cs @@ -59,7 +59,7 @@ protected override void OnEventCommand(EventCommandEventArgs command) private void ResolutionFailed() => WriteEvent(ResolutionFailedEventId); [NonEvent] - public static bool AnyDiagnosticsEnabled() => Log.IsEnabled() || NameResolutionMetrics.IsEnabled() || NameResolutionActivity.IsTracingEnabled(); + public static bool AnyDiagnosticsEnabled() => !OperatingSystem.IsWasi() && (Log.IsEnabled() || NameResolutionMetrics.IsEnabled() || NameResolutionActivity.IsTracingEnabled()); [NonEvent] public NameResolutionActivity BeforeResolution(object hostNameOrAddress, long startingTimestamp = 0) @@ -91,6 +91,8 @@ public NameResolutionActivity BeforeResolution(object hostNameOrAddress, long st [NonEvent] public void AfterResolution(object hostNameOrAddress, in NameResolutionActivity activity, object? answer, Exception? exception = null) { + if (OperatingSystem.IsWasi()) return; + if (!activity.Stop(answer, exception, out TimeSpan duration)) { // We stopped the System.Diagnostics.Activity at this point and neither metrics nor EventSource is enabled. diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs index 71820b8cc72f7..d1073db5d3986 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostAddressesTest.cs @@ -69,14 +69,14 @@ public async Task Dns_GetHostAddressesAsync_NullHost_Fail() await Assert.ThrowsAsync(() => Dns.GetHostAddressesAsync(null)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public void DnsBeginGetHostAddresses_BadName_Throws() { IAsyncResult asyncObject = Dns.BeginGetHostAddresses("BadName", null, null); Assert.ThrowsAny(() => Dns.EndGetHostAddresses(asyncObject)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public void DnsBeginGetHostAddresses_BadIpString_ReturnsAddress() { IAsyncResult asyncObject = Dns.BeginGetHostAddresses("0.0.1.1", null, null); @@ -86,7 +86,7 @@ public void DnsBeginGetHostAddresses_BadIpString_ReturnsAddress() Assert.Equal(IPAddress.Parse("0.0.1.1"), results[0]); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public void DnsBeginGetHostAddresses_MachineName_MatchesGetHostAddresses() { IAsyncResult asyncObject = Dns.BeginGetHostAddresses(TestSettings.LocalHost, null, null); diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByAddressTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByAddressTest.cs index a9072c6506faa..6a6b237b0d938 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByAddressTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByAddressTest.cs @@ -8,6 +8,7 @@ namespace System.Net.NameResolution.Tests { + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public class GetHostByAddressTest { [Fact] diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByNameTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByNameTest.cs index 56f52afb1b7da..479a5cd39ac35 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByNameTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostByNameTest.cs @@ -19,7 +19,7 @@ public void DnsObsoleteBeginGetHostByName_BadName_Throws() Assert.ThrowsAny(() => Dns.EndGetHostByName(asyncObject)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] public void DnsObsoleteBeginGetHostByName_IPv4String_ReturnsOnlyGivenIP() { IAsyncResult asyncObject = Dns.BeginGetHostByName(IPAddress.Loopback.ToString(), null, null); @@ -106,6 +106,7 @@ public void DnsObsoleteGetHostByName_IPv6String_ReturnsOnlyGivenIP() [ActiveIssue("https://github.com/dotnet/runtime/issues/1488", TestPlatforms.OSX)] [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArm64Process))] // [ActiveIssue("https://github.com/dotnet/runtime/issues/27622")] [ActiveIssue("https://github.com/dotnet/runtime/issues/51377", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/107339", TestPlatforms.Wasi)] public void DnsObsoleteGetHostByName_EmptyString_ReturnsHostName() { IPHostEntry entry = Dns.GetHostByName(""); diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs index a4a7174897a39..c4988cef81672 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/GetHostEntryTest.cs @@ -148,10 +148,16 @@ public async Task Dns_GetHostEntry_NullStringHost_Fail() { Assert.Throws(() => Dns.GetHostEntry((string)null)); await Assert.ThrowsAsync(() => Dns.GetHostEntryAsync((string)null)); + } + + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + public async Task Dns_GetHostEntry_NullStringHost_Fail_Obsolete() + { await Assert.ThrowsAsync(() => Task.Factory.FromAsync(Dns.BeginGetHostEntry, Dns.EndGetHostEntry, (string)null, null)); } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public async Task Dns_GetHostEntryAsync_NullIPAddressHost_Fail() { Assert.Throws(() => Dns.GetHostEntry((IPAddress)null)); @@ -168,6 +174,7 @@ public static IEnumerable GetInvalidAddresses() [Theory] [MemberData(nameof(GetInvalidAddresses))] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public async Task Dns_GetHostEntry_AnyIPAddress_Fail(IPAddress address) { Assert.Throws(() => Dns.GetHostEntry(address)); @@ -195,6 +202,7 @@ public async Task DnsGetHostEntry_MachineName_AllVariationsMatch() } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public async Task DnsGetHostEntry_Loopback_AllVariationsMatch() { IPHostEntry syncResult = Dns.GetHostEntry(IPAddress.Loopback); @@ -216,6 +224,7 @@ public async Task DnsGetHostEntry_Loopback_AllVariationsMatch() [InlineData("Really.Long.Name.Over.One.Hundred.And.Twenty.Six.Chars.Eeeeeeeventualllllllly.I.Will.Get.To.The.Eeeee" + "eeeeend.Almost.There.Are.We.Really.Long.Name.Over.One.Hundred.And.Twenty.Six.Chars.Eeeeeeeventualll" + "llllly.I.Will.Get.To.The.Eeeeeeeeeend.Almost.There.Are")] // very long name but not too long + [ActiveIssue("https://github.com/dotnet/runtime/issues/107339", TestPlatforms.Wasi)] public async Task DnsGetHostEntry_BadName_ThrowsSocketException(string hostNameOrAddress) { Assert.ThrowsAny(() => Dns.GetHostEntry(hostNameOrAddress)); @@ -231,6 +240,14 @@ public async Task DnsGetHostEntry_BadName_ThrowsArgumentOutOfRangeException(stri { Assert.ThrowsAny(() => Dns.GetHostEntry(hostNameOrAddress)); await Assert.ThrowsAnyAsync(() => Dns.GetHostEntryAsync(hostNameOrAddress)); + } + + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))] + [InlineData("Really.Long.Name.Over.One.Hundred.And.Twenty.Six.Chars.Eeeeeeeventualllllllly.I.Will.Get.To.The.Eeeee" + + "eeeeend.Almost.There.Are.We.Really.Long.Name.Over.One.Hundred.And.Twenty.Six.Chars.Eeeeeeeventualll" + + "llllly.I.Will.Get.To.The.Eeeeeeeeeend.Almost.There.Aret")] + public async Task DnsGetHostEntry_BadName_ThrowsArgumentOutOfRangeException_Obsolete(string hostNameOrAddress) + { await Assert.ThrowsAnyAsync(() => Task.Factory.FromAsync(Dns.BeginGetHostEntry, Dns.EndGetHostEntry, hostNameOrAddress, null)); } @@ -238,6 +255,7 @@ public async Task DnsGetHostEntry_BadName_ThrowsArgumentOutOfRangeException(stri [InlineData(0)] [InlineData(1)] [InlineData(2)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/107339", TestPlatforms.Wasi)] public async Task DnsGetHostEntry_LocalHost_ReturnsFqdnAndLoopbackIPs(int mode) { IPHostEntry entry = mode switch @@ -259,6 +277,9 @@ public async Task DnsGetHostEntry_LocalHost_ReturnsFqdnAndLoopbackIPs(int mode) [InlineData(2)] public async Task DnsGetHostEntry_LoopbackIP_MatchesGetHostEntryLoopbackString(int mode) { + if (OperatingSystem.IsWasi() && mode == 2) + throw new SkipTestException("mode 2 is not supported on WASI"); + IPAddress address = IPAddress.Loopback; IPHostEntry ipEntry = mode switch diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs index 920a5af60cf00..43f3db17b3e90 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/LoggingTest.cs @@ -15,6 +15,7 @@ namespace System.Net.NameResolution.Tests using Configuration = System.Net.Test.Common.Configuration; [Collection(nameof(DisableParallelization))] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI doesn't have event source yet")] public class LoggingTest { [Fact] diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs index 0cafd974a4a20..ebee4d90e8dd1 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/MetricsTest.cs @@ -12,6 +12,7 @@ namespace System.Net.NameResolution.Tests { + [SkipOnPlatform(TestPlatforms.Wasi, "WASI doesn't have event source yet")] public class MetricsTest { private const string DnsLookupDuration = "dns.lookup.duration"; diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/ResolveTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/ResolveTest.cs index 071e9927ee9ff..814ec5cc6c267 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/ResolveTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/ResolveTest.cs @@ -46,6 +46,7 @@ public void DnsObsoleteResolve_BadName_Throws() } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public void DnsObsoleteResolve_BadIP_ReturnsIPasNameAndIP() { IPHostEntry entry = Dns.Resolve("0.0.1.1"); diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj index 182e5d9eba19b..9741c993ccdba 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/System.Net.NameResolution.Functional.Tests.csproj @@ -1,9 +1,10 @@ - $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser;$(NetCoreAppCurrent)-wasi true true true + true diff --git a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/TelemetryTest.cs b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/TelemetryTest.cs index b88ad1188aedc..3da2983720572 100644 --- a/src/libraries/System.Net.NameResolution/tests/FunctionalTests/TelemetryTest.cs +++ b/src/libraries/System.Net.NameResolution/tests/FunctionalTests/TelemetryTest.cs @@ -12,6 +12,7 @@ namespace System.Net.NameResolution.Tests { + [SkipOnPlatform(TestPlatforms.Wasi, "WASI doesn't have event source yet")] public class TelemetryTest { [Fact] diff --git a/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs b/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs index 030f03c01eddf..e4049b1291990 100644 --- a/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs +++ b/src/libraries/System.Net.NameResolution/tests/PalTests/NameResolutionPalTests.cs @@ -61,6 +61,7 @@ private void LogUnixInfo() [Theory] [InlineData(false)] [InlineData(true)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/107339", TestPlatforms.Wasi)] public void TryGetAddrInfo_LocalHost(bool justAddresses) { SocketError error = NameResolutionPal.TryGetAddrInfo("localhost", justAddresses, AddressFamily.Unspecified, out string hostName, out string[] aliases, out IPAddress[] addresses, out int nativeErrorCode); @@ -77,6 +78,7 @@ public void TryGetAddrInfo_LocalHost(bool justAddresses) [Theory] [InlineData(false)] [InlineData(true)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/107339", TestPlatforms.Wasi)] public void TryGetAddrInfo_EmptyHost(bool justAddresses) { SocketError error = NameResolutionPal.TryGetAddrInfo("", justAddresses, AddressFamily.Unspecified, out string hostName, out string[] aliases, out IPAddress[] addresses, out int nativeErrorCode); @@ -151,6 +153,7 @@ public void TryGetAddrInfo_UnknownHost(bool justAddresses) } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public void TryGetNameInfo_LocalHost_IPv4() { SocketError error; @@ -161,6 +164,7 @@ public void TryGetNameInfo_LocalHost_IPv4() } [ConditionalFact(nameof(Ipv6LocalHostNameLookupNotBrokenByNrpRule))] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public void TryGetNameInfo_LocalHost_IPv6() { SocketError error; @@ -176,6 +180,7 @@ public void TryGetNameInfo_LocalHost_IPv6() } [Fact] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public void TryGetAddrInfo_LocalHost_TryGetNameInfo() { SocketError error = NameResolutionPal.TryGetAddrInfo("localhost", justAddresses: false, AddressFamily.Unspecified, out string hostName, out string[] aliases, out IPAddress[] addresses, out int nativeErrorCode); @@ -247,6 +252,7 @@ public void TryGetAddrInfo_HostName_TryGetNameInfo() [Theory] [InlineData(false)] [InlineData(true)] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public void TryGetNameInfo_LocalHost_IPv4_TryGetAddrInfo(bool justAddresses) { string name = NameResolutionPal.TryGetNameInfo(new IPAddress(new byte[] { 127, 0, 0, 1 }), out SocketError error, out _); @@ -262,6 +268,7 @@ public void TryGetNameInfo_LocalHost_IPv4_TryGetAddrInfo(bool justAddresses) [ConditionalTheory(nameof(Ipv6LocalHostNameLookupNotBrokenByNrpRule))] [InlineData(false)] [InlineData(true)] + [SkipOnPlatform(TestPlatforms.Wasi, "WASI has no getnameinfo")] public void TryGetNameInfo_LocalHost_IPv6_TryGetAddrInfo(bool justAddresses) { SocketError error; diff --git a/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj b/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj index 6e08a5f973e09..7daa5977519b0 100644 --- a/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj +++ b/src/libraries/System.Net.NameResolution/tests/PalTests/System.Net.NameResolution.Pal.Tests.csproj @@ -2,8 +2,9 @@ true ../../src/Resources/Strings.resx - $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser;$(NetCoreAppCurrent)-wasi true + true @@ -71,7 +72,9 @@ - + + - + + diff --git a/src/native/libs/Common/pal_config.h.in b/src/native/libs/Common/pal_config.h.in index 4439e8cebfeaa..c8e43fa37dd6a 100644 --- a/src/native/libs/Common/pal_config.h.in +++ b/src/native/libs/Common/pal_config.h.in @@ -56,6 +56,9 @@ #cmakedefine01 HAVE_ETHTOOL_H #cmakedefine01 HAVE_SYS_POLL_H #cmakedefine01 HAVE_EPOLL +#cmakedefine01 HAVE_GETHOSTNAME +#cmakedefine01 HAVE_GETNAMEINFO +#cmakedefine01 HAVE_SOCKADDR_UN_SUN_PATH #cmakedefine01 HAVE_ACCEPT4 #cmakedefine01 HAVE_KQUEUE #cmakedefine01 HAVE_SENDFILE_4 diff --git a/src/native/libs/System.Native/CMakeLists.txt b/src/native/libs/System.Native/CMakeLists.txt index 4cac1051f6739..7e00e0ed0a271 100644 --- a/src/native/libs/System.Native/CMakeLists.txt +++ b/src/native/libs/System.Native/CMakeLists.txt @@ -24,6 +24,7 @@ set(NATIVE_SOURCES pal_io.c pal_maphardwaretype.c pal_memory.c + pal_networking.c pal_networkstatistics.c pal_random.c pal_runtimeinformation.c @@ -42,7 +43,6 @@ if (NOT CLR_CMAKE_TARGET_WASI) list (APPEND NATIVE_SOURCES pal_dynamicload.c pal_mount.c - pal_networking.c pal_process.c pal_signal.c pal_threading.c @@ -52,7 +52,6 @@ else() list (APPEND NATIVE_SOURCES pal_dynamicload_wasi.c pal_mount_wasi.c - pal_networking_wasi.c pal_process_wasi.c pal_signal_wasi.c pal_threading_wasi.c diff --git a/src/native/libs/System.Native/pal_networking.c b/src/native/libs/System.Native/pal_networking.c index dc727fe546504..82e3960e6fc33 100644 --- a/src/native/libs/System.Native/pal_networking.c +++ b/src/native/libs/System.Native/pal_networking.c @@ -34,7 +34,9 @@ #include #include #include +#if HAVE_NET_IF_H #include +#endif #include #include #include @@ -50,7 +52,9 @@ #include #endif #include +#ifdef HAVE_PWD_H #include +#endif #if HAVE_SENDFILE_4 #include #elif HAVE_SENDFILE_6 @@ -139,14 +143,11 @@ struct in_pktinfo #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP #endif -enum -{ -#if defined(__APPLE__) && __APPLE__ - LINGER_OPTION_NAME = SO_LINGER_SEC -#else - LINGER_OPTION_NAME = SO_LINGER, +#if defined(__APPLE__) && __APPLE__ && defined(SO_LINGER_SEC) + #define LINGER_OPTION_NAME SO_LINGER_SEC +#elif defined(SO_LINGER) + #define LINGER_OPTION_NAME SO_LINGER #endif -}; enum { @@ -271,16 +272,17 @@ static void ConvertByteArrayToSockAddrIn6(struct sockaddr_in6* addr, const uint8 addr->sin6_family = AF_INET6; } -static void ConvertByteArrayToInAddr(struct in_addr* addr, const uint8_t* buffer, int32_t bufferLength) +static void ConvertInAddrToByteArray(uint8_t* buffer, int32_t bufferLength, const struct in_addr* addr) { assert(bufferLength == NUM_BYTES_IN_IPV4_ADDRESS); - memcpy_s(&addr->s_addr, NUM_BYTES_IN_IPV4_ADDRESS, buffer, (uint32_t)bufferLength); // Send back in network byte order. + memcpy_s(buffer, (uint32_t)bufferLength, &addr->s_addr, NUM_BYTES_IN_IPV4_ADDRESS); // Send back in network byte order. } -static void ConvertInAddrToByteArray(uint8_t* buffer, int32_t bufferLength, const struct in_addr* addr) +#if HAVE_GETNAMEINFO +static void ConvertByteArrayToInAddr(struct in_addr* addr, const uint8_t* buffer, int32_t bufferLength) { assert(bufferLength == NUM_BYTES_IN_IPV4_ADDRESS); - memcpy_s(buffer, (uint32_t)bufferLength, &addr->s_addr, NUM_BYTES_IN_IPV4_ADDRESS); // Send back in network byte order. + memcpy_s(&addr->s_addr, NUM_BYTES_IN_IPV4_ADDRESS, buffer, (uint32_t)bufferLength); // Send back in network byte order. } static void ConvertByteArrayToSockAddrIn(struct sockaddr_in* addr, const uint8_t* buffer, int32_t bufferLength) @@ -289,6 +291,7 @@ static void ConvertByteArrayToSockAddrIn(struct sockaddr_in* addr, const uint8_t addr->sin_family = AF_INET; } +#endif // HAVE_GETNAMEINFO static int32_t ConvertGetAddrInfoAndGetNameInfoErrorsToPal(int32_t error) { @@ -313,10 +316,12 @@ static int32_t ConvertGetAddrInfoAndGetNameInfoErrorsToPal(int32_t error) case EAI_NODATA: #endif return GetAddrInfoErrorFlags_EAI_NONAME; + case EAI_SYSTEM: + return GetAddrInfoErrorFlags_EAI_SYSTEM; + default: + assert_err(0, "Unknown AddrInfo error flag", error); + return -1; } - - assert_err(0, "Unknown AddrInfo error flag", error); - return -1; } static int32_t CopySockAddrToIPAddress(sockaddr* addr, sa_family_t family, IPAddress* ipAddress) @@ -546,6 +551,7 @@ typedef int32_t NativeFlagsType; typedef uint32_t NativeFlagsType; #endif +#if HAVE_GETNAMEINFO static inline NativeFlagsType ConvertGetNameInfoFlagsToNative(int32_t flags) { NativeFlagsType outFlags = 0; @@ -560,6 +566,7 @@ static inline NativeFlagsType ConvertGetNameInfoFlagsToNative(int32_t flags) return outFlags; } +#endif // HAVE_GETNAMEINFO int32_t SystemNative_GetNameInfo(const uint8_t* address, int32_t addressLength, @@ -570,6 +577,7 @@ int32_t SystemNative_GetNameInfo(const uint8_t* address, int32_t serviceLength, int32_t flags) { +#if HAVE_GETNAMEINFO assert(address != NULL); assert(addressLength > 0); assert((host != NULL) || (service != NULL)); @@ -606,6 +614,17 @@ int32_t SystemNative_GetNameInfo(const uint8_t* address, } return ConvertGetAddrInfoAndGetNameInfoErrorsToPal(result); +#else // HAVE_GETNAMEINFO + (void)address; + (void)addressLength, + (void)isIPv6, + (void)host, + (void)hostLength, + (void)service, + (void)serviceLength, + (void)flags; + return ConvertGetAddrInfoAndGetNameInfoErrorsToPal(EAI_FAIL); +#endif // HAVE_GETNAMEINFO } int32_t SystemNative_GetDomainName(uint8_t* name, int32_t nameLength) @@ -652,11 +671,17 @@ int32_t SystemNative_GetDomainName(uint8_t* name, int32_t nameLength) int32_t SystemNative_GetHostName(uint8_t* name, int32_t nameLength) { +#if HAVE_GETHOSTNAME assert(name != NULL); assert(nameLength > 0); size_t unsignedSize = (uint32_t)nameLength; return gethostname((char*)name, unsignedSize); +#else // HAVE_GETHOSTNAME + (void)name; + (void)nameLength; + return Error_ENOTSUP; +#endif // HAVE_GETHOSTNAME } static bool IsInBounds(const void* void_baseAddr, size_t len, const void* void_valueAddr, size_t valueSize) @@ -907,6 +932,7 @@ SystemNative_SetIPv6Address(uint8_t* socketAddress, int32_t socketAddressLen, ui return Error_SUCCESS; } +#if defined(CMSG_SPACE) static int8_t IsStreamSocket(int socket) { int type; @@ -933,15 +959,23 @@ static void ConvertMessageHeaderToMsghdr(struct msghdr* header, const MessageHea header->msg_controllen = (uint32_t)messageHeader->ControlBufferLen; header->msg_flags = 0; } +#endif // CMSG_SPACE int32_t SystemNative_GetControlMessageBufferSize(int32_t isIPv4, int32_t isIPv6) { // Note: it is possible that the address family of the socket is neither // AF_INET nor AF_INET6. In this case both inputs will be 0 and // the control message buffer size should be zero. +#if defined(CMSG_SPACE) return (isIPv4 != 0 ? CMSG_SPACE(sizeof(struct in_pktinfo)) : 0) + (isIPv6 != 0 ? CMSG_SPACE(sizeof(struct in6_pktinfo)) : 0); +#else // CMSG_SPACE + (void)isIPv4; + (void)isIPv6; + return 0; +#endif // CMSG_SPACE } +#if defined(CMSG_SPACE) static int32_t GetIPv4PacketInformation(struct cmsghdr* controlMessage, IPPacketInformation* packetInfo) { assert(controlMessage != NULL); @@ -1020,6 +1054,7 @@ static struct cmsghdr* GET_CMSG_NXTHDR(struct msghdr* mhdr, struct cmsghdr* cmsg #pragma clang diagnostic pop #endif } +#endif // CMSG_SPACE int32_t SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isIPv4, IPPacketInformation* packetInfo) @@ -1029,6 +1064,7 @@ SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isI return 0; } +#if defined(CMSG_SPACE) struct msghdr header; ConvertMessageHeaderToMsghdr(&header, messageHeader, -1); @@ -1057,6 +1093,12 @@ SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isI } return 0; +#else // CMSG_SPACE + (void)messageHeader; + (void)isIPv4; + (void)packetInfo; + return Error_ENOTSUP; +#endif // CMSG_SPACE } static int8_t GetMulticastOptionName(int32_t multicastOption, int8_t isIPv6, int* optionName) @@ -1257,6 +1299,7 @@ int32_t SystemNative_GetLingerOption(intptr_t socket, LingerOption* option) return Error_EFAULT; } +#if defined(LINGER_OPTION_NAME) int fd = ToFileDescriptor(socket); struct linger opt; @@ -1271,6 +1314,11 @@ int32_t SystemNative_GetLingerOption(intptr_t socket, LingerOption* option) option->OnOff = opt.l_onoff; option->Seconds = opt.l_linger; return Error_SUCCESS; +#else // LINGER_OPTION_NAME + (void)socket; + (void)option; + return Error_ENOTSUP; +#endif // LINGER_OPTION_NAME } int32_t SystemNative_SetLingerOption(intptr_t socket, LingerOption* option) @@ -1285,6 +1333,7 @@ int32_t SystemNative_SetLingerOption(intptr_t socket, LingerOption* option) return Error_EINVAL; } +#if defined(LINGER_OPTION_NAME) int fd = ToFileDescriptor(socket); struct linger opt; @@ -1304,6 +1353,9 @@ int32_t SystemNative_SetLingerOption(intptr_t socket, LingerOption* option) #endif return err == 0 ? Error_SUCCESS : SystemNative_ConvertErrorPlatformToPal(errno); +#else // LINGER_OPTION_NAME + return Error_ENOTSUP; +#endif // LINGER_OPTION_NAME } static int32_t SetTimeoutOption(int32_t socket, int32_t millisecondsTimeout, int optionName) @@ -1333,32 +1385,62 @@ int32_t SystemNative_SetSendTimeout(intptr_t socket, int32_t millisecondsTimeout static int8_t ConvertSocketFlagsPalToPlatform(int32_t palFlags, int* platformFlags) { - const int32_t SupportedFlagsMask = + const int32_t SupportedFlagsMask = 0 #ifdef MSG_ERRQUEUE - SocketFlags_MSG_ERRQUEUE | + | SocketFlags_MSG_ERRQUEUE +#endif +#ifdef MSG_OOB + | SocketFlags_MSG_OOB +#endif +#ifdef MSG_PEEK + | SocketFlags_MSG_PEEK +#endif +#ifdef MSG_DONTWAIT + | SocketFlags_MSG_DONTWAIT +#endif +#ifdef MSG_DONTROUTE + | SocketFlags_MSG_DONTROUTE +#endif +#ifdef MSG_TRUNC + | SocketFlags_MSG_TRUNC #endif - SocketFlags_MSG_OOB | SocketFlags_MSG_PEEK | SocketFlags_MSG_DONTROUTE | SocketFlags_MSG_TRUNC | SocketFlags_MSG_CTRUNC | SocketFlags_MSG_DONTWAIT; +#ifdef MSG_CTRUNC + | SocketFlags_MSG_CTRUNC +#endif + ; if ((palFlags & ~SupportedFlagsMask) != 0) { return false; } - *platformFlags = ((palFlags & SocketFlags_MSG_OOB) == 0 ? 0 : MSG_OOB) | - ((palFlags & SocketFlags_MSG_PEEK) == 0 ? 0 : MSG_PEEK) | - ((palFlags & SocketFlags_MSG_DONTROUTE) == 0 ? 0 : MSG_DONTROUTE) | - ((palFlags & SocketFlags_MSG_DONTWAIT) == 0 ? 0 : MSG_DONTWAIT) | - ((palFlags & SocketFlags_MSG_TRUNC) == 0 ? 0 : MSG_TRUNC) | - ((palFlags & SocketFlags_MSG_CTRUNC) == 0 ? 0 : MSG_CTRUNC); + *platformFlags = 0 #ifdef MSG_ERRQUEUE - if ((palFlags & SocketFlags_MSG_ERRQUEUE) != 0) - { - *platformFlags |= MSG_ERRQUEUE; - } + | ((palFlags & SocketFlags_MSG_ERRQUEUE) == 0 ? 0 : MSG_ERRQUEUE) +#endif +#ifdef MSG_OOB + | ((palFlags & SocketFlags_MSG_OOB) == 0 ? 0 : MSG_OOB) +#endif +#ifdef MSG_PEEK + | ((palFlags & SocketFlags_MSG_PEEK) == 0 ? 0 : MSG_PEEK) +#endif +#ifdef MSG_DONTROUTE + | ((palFlags & SocketFlags_MSG_DONTROUTE) == 0 ? 0 : MSG_DONTROUTE) +#endif +#ifdef MSG_DONTWAIT + | ((palFlags & SocketFlags_MSG_DONTWAIT) == 0 ? 0 : MSG_DONTWAIT) +#endif +#ifdef MSG_TRUNC + | ((palFlags & SocketFlags_MSG_TRUNC) == 0 ? 0 : MSG_TRUNC) #endif +#ifdef MSG_CTRUNC + | ((palFlags & SocketFlags_MSG_CTRUNC) == 0 ? 0 : MSG_CTRUNC) +#endif + ; return true; } +#if defined(CMSG_SPACE) static int32_t ConvertSocketFlagsPlatformToPal(int platformFlags) { const int SupportedFlagsMask = MSG_OOB | MSG_DONTROUTE | MSG_TRUNC | MSG_CTRUNC; @@ -1370,6 +1452,7 @@ static int32_t ConvertSocketFlagsPlatformToPal(int platformFlags) ((platformFlags & MSG_TRUNC) == 0 ? 0 : SocketFlags_MSG_TRUNC) | ((platformFlags & MSG_CTRUNC) == 0 ? 0 : SocketFlags_MSG_CTRUNC); } +#endif // CMSG_SPACE int32_t SystemNative_Receive(intptr_t socket, void* buffer, int32_t bufferLen, int32_t flags, int32_t* received) { @@ -1469,10 +1552,14 @@ int32_t SystemNative_ReceiveMessage(intptr_t socket, MessageHeader* messageHeade return Error_ENOTSUP; } + ssize_t res; +#if !defined(CMSG_SPACE) + // TODO https://github.com/dotnet/runtime/issues/98957 + return Error_ENOTSUP; +#else // !CMSG_SPACE struct msghdr header; ConvertMessageHeaderToMsghdr(&header, messageHeader, fd); - ssize_t res; while ((res = recvmsg(fd, &header, socketFlags)) < 0 && errno == EINTR); assert(header.msg_name == messageHeader->SocketAddress); // should still be the same location as set in ConvertMessageHeaderToMsghdr @@ -1494,6 +1581,7 @@ int32_t SystemNative_ReceiveMessage(intptr_t socket, MessageHeader* messageHeade *received = 0; return SystemNative_ConvertErrorPlatformToPal(errno); +#endif // !CMSG_SPACE } int32_t SystemNative_Send(intptr_t socket, void* buffer, int32_t bufferLen, int32_t flags, int32_t* sent) @@ -1547,10 +1635,14 @@ int32_t SystemNative_SendMessage(intptr_t socket, MessageHeader* messageHeader, return Error_ENOTSUP; } +#if !defined(CMSG_SPACE) + // TODO https://github.com/dotnet/runtime/issues/98957 + return Error_ENOTSUP; +#else // !CMSG_SPACE + ssize_t res; struct msghdr header; ConvertMessageHeaderToMsghdr(&header, messageHeader, fd); - ssize_t res; #if defined(__APPLE__) && __APPLE__ // possible OSX kernel bug: https://github.com/dotnet/runtime/issues/27221 // According to https://github.com/dotnet/runtime/issues/63291 the EPROTOTYPE may be @@ -1568,6 +1660,7 @@ int32_t SystemNative_SendMessage(intptr_t socket, MessageHeader* messageHeader, *sent = 0; return SystemNative_ConvertErrorPlatformToPal(errno); +#endif // !CMSG_SPACE } int32_t SystemNative_Accept(intptr_t socket, uint8_t* socketAddress, int32_t* socketAddressLen, intptr_t* acceptedSocket) @@ -1699,7 +1792,7 @@ int32_t SystemNative_Connectx(intptr_t socket, uint8_t* socketAddress, int32_t s } #endif // avoid possible warning about unused parameters - (void*)data; + (void)data; (void)dataLen; (void)tfo; sent = 0; @@ -1791,9 +1884,11 @@ static bool TryGetPlatformSocketOption(int32_t socketOptionLevel, int32_t socket switch (socketOptionName) { +#if defined(SO_DEBUG) case SocketOptionName_SO_DEBUG: *optName = SO_DEBUG; return true; +#endif case SocketOptionName_SO_ACCEPTCONN: *optName = SO_ACCEPTCONN; @@ -1807,23 +1902,31 @@ static bool TryGetPlatformSocketOption(int32_t socketOptionLevel, int32_t socket *optName = SO_KEEPALIVE; return true; +#if defined(SO_DONTROUTE) case SocketOptionName_SO_DONTROUTE: *optName = SO_DONTROUTE; return true; +#endif +#if defined(SO_BROADCAST) case SocketOptionName_SO_BROADCAST: *optName = SO_BROADCAST; return true; +#endif // case SocketOptionName_SO_USELOOPBACK: +#if defined(SO_LINGER) case SocketOptionName_SO_LINGER: *optName = SO_LINGER; return true; +#endif +#if defined(SO_OOBINLINE) case SocketOptionName_SO_OOBINLINE: *optName = SO_OOBINLINE; return true; +#endif // case SocketOptionName_SO_DONTLINGER: @@ -1837,14 +1940,18 @@ static bool TryGetPlatformSocketOption(int32_t socketOptionLevel, int32_t socket *optName = SO_RCVBUF; return true; +#if defined(SO_SNDLOWAT) case SocketOptionName_SO_SNDLOWAT: *optName = SO_SNDLOWAT; return true; +#endif +#if defined(SO_RCVLOWAT) case SocketOptionName_SO_RCVLOWAT: *optName = SO_RCVLOWAT; return true; +#endif case SocketOptionName_SO_SNDTIMEO: *optName = SO_SNDTIMEO; return true; @@ -2064,9 +2171,11 @@ static bool TryConvertSocketTypePlatformToPal(int platformSocketType, int32_t* p *palSocketType = SocketType_SOCK_DGRAM; return true; +#if defined(SOCK_RAW) case SOCK_RAW: *palSocketType = SocketType_SOCK_RAW; return true; +#endif // SOCK_RAW #ifdef SOCK_RDM case SOCK_RDM: @@ -2074,9 +2183,11 @@ static bool TryConvertSocketTypePlatformToPal(int platformSocketType, int32_t* p return true; #endif +#if defined(SOCK_SEQPACKET) case SOCK_SEQPACKET: *palSocketType = SocketType_SOCK_SEQPACKET; return true; +#endif // SOCK_SEQPACKET default: *palSocketType = (int32_t)platformSocketType; @@ -2336,9 +2447,11 @@ static bool TryConvertSocketTypePalToPlatform(int32_t palSocketType, int* platfo *platformSocketType = SOCK_DGRAM; return true; +#if defined(SOCK_RAW) case SocketType_SOCK_RAW: *platformSocketType = SOCK_RAW; return true; +#endif // SOCK_RAW #ifdef SOCK_RDM case SocketType_SOCK_RDM: @@ -2346,9 +2459,11 @@ static bool TryConvertSocketTypePalToPlatform(int32_t palSocketType, int* platfo return true; #endif +#if defined(SOCK_SEQPACKET) case SocketType_SOCK_SEQPACKET: *platformSocketType = SOCK_SEQPACKET; return true; +#endif // SOCK_SEQPACKET default: *platformSocketType = (int)palSocketType; @@ -2392,9 +2507,11 @@ static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_ *platformProtocolType = 0; return true; +#if defined(IPPROTO_ICMP) case ProtocolType_PT_ICMP: *platformProtocolType = IPPROTO_ICMP; return true; +#endif case ProtocolType_PT_TCP: *platformProtocolType = IPPROTO_TCP; @@ -2404,9 +2521,11 @@ static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_ *platformProtocolType = IPPROTO_UDP; return true; +#if defined(IPPROTO_IGMP) case ProtocolType_PT_IGMP: *platformProtocolType = IPPROTO_IGMP; return true; +#endif case ProtocolType_PT_RAW: *platformProtocolType = IPPROTO_RAW; @@ -2424,10 +2543,12 @@ static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_ *platformProtocolType = 0; return true; +#if defined(IPPROTO_ICMPV6) case ProtocolType_PT_ICMPV6: case ProtocolType_PT_ICMP: *platformProtocolType = IPPROTO_ICMPV6; return true; +#endif case ProtocolType_PT_TCP: *platformProtocolType = IPPROTO_TCP; @@ -2437,29 +2558,39 @@ static bool TryConvertProtocolTypePalToPlatform(int32_t palAddressFamily, int32_ *platformProtocolType = IPPROTO_UDP; return true; +#if defined(IPPROTO_IGMP) case ProtocolType_PT_IGMP: *platformProtocolType = IPPROTO_IGMP; return true; +#endif case ProtocolType_PT_RAW: *platformProtocolType = IPPROTO_RAW; return true; +#if defined(IPPROTO_DSTOPTS) case ProtocolType_PT_DSTOPTS: *platformProtocolType = IPPROTO_DSTOPTS; return true; +#endif +#if defined(IPPROTO_NONE) case ProtocolType_PT_NONE: *platformProtocolType = IPPROTO_NONE; return true; +#endif +#if defined(IPPROTO_ROUTING) case ProtocolType_PT_ROUTING: *platformProtocolType = IPPROTO_ROUTING; return true; +#endif +#if defined(IPPROTO_FRAGMENT) case ProtocolType_PT_FRAGMENT: *platformProtocolType = IPPROTO_FRAGMENT; return true; +#endif default: *platformProtocolType = (int)palProtocolType; @@ -2515,9 +2646,11 @@ static bool TryConvertProtocolTypePlatformToPal(int32_t palAddressFamily, int pl *palProtocolType = ProtocolType_PT_UNSPECIFIED; return true; +#if defined(IPPROTO_ICMP) case IPPROTO_ICMP: *palProtocolType = ProtocolType_PT_ICMP; return true; +#endif case IPPROTO_TCP: *palProtocolType = ProtocolType_PT_TCP; @@ -2527,9 +2660,11 @@ static bool TryConvertProtocolTypePlatformToPal(int32_t palAddressFamily, int pl *palProtocolType = ProtocolType_PT_UDP; return true; +#if defined(IPPROTO_IGMP) case IPPROTO_IGMP: *palProtocolType = ProtocolType_PT_IGMP; return true; +#endif case IPPROTO_RAW: *palProtocolType = ProtocolType_PT_RAW; @@ -2547,9 +2682,11 @@ static bool TryConvertProtocolTypePlatformToPal(int32_t palAddressFamily, int pl *palProtocolType = ProtocolType_PT_UNSPECIFIED; return true; +#if defined(IPPROTO_ICMPV6) case IPPROTO_ICMPV6: *palProtocolType = ProtocolType_PT_ICMPV6; return true; +#endif case IPPROTO_TCP: *palProtocolType = ProtocolType_PT_TCP; @@ -2559,29 +2696,39 @@ static bool TryConvertProtocolTypePlatformToPal(int32_t palAddressFamily, int pl *palProtocolType = ProtocolType_PT_UDP; return true; +#if defined(IPPROTO_IGMP) case IPPROTO_IGMP: *palProtocolType = ProtocolType_PT_IGMP; return true; +#endif case IPPROTO_RAW: *palProtocolType = ProtocolType_PT_RAW; return true; +#if defined(IPPROTO_DSTOPTS) case IPPROTO_DSTOPTS: *palProtocolType = ProtocolType_PT_DSTOPTS; return true; +#endif +#if defined(IPPROTO_NONE) case IPPROTO_NONE: *palProtocolType = ProtocolType_PT_NONE; return true; +#endif +#if defined(IPPROTO_ROUTING) case IPPROTO_ROUTING: *palProtocolType = ProtocolType_PT_ROUTING; return true; +#endif +#if defined(IPPROTO_FRAGMENT) case IPPROTO_FRAGMENT: *palProtocolType = ProtocolType_PT_FRAGMENT; return true; +#endif default: *palProtocolType = (int)platformProtocolType; @@ -2723,6 +2870,7 @@ int32_t SystemNative_GetSocketType(intptr_t socket, int32_t* addressFamily, int3 int32_t SystemNative_GetAtOutOfBandMark(intptr_t socket, int32_t* atMark) { +#if defined(SIOCATMARK) if (atMark == NULL) { return Error_EFAULT; @@ -2741,6 +2889,9 @@ int32_t SystemNative_GetAtOutOfBandMark(intptr_t socket, int32_t* atMark) *atMark = (int32_t)result; return Error_SUCCESS; +#else // SIOCATMARK + return Error_ENOTSUP; +#endif // SIOCATMARK } int32_t SystemNative_GetBytesAvailable(intptr_t socket, int32_t* available) @@ -2847,11 +2998,15 @@ int32_t SystemNative_Select(int* readFds, int readFdsCount, int* writeFds, int w return Error_SUCCESS; #else // avoid unused parameters warnings - (void*)readFds; - (void*)writeFds; - (void*)errorFds; - (void*)triggered; - readFdsCount + writeFdsCount + errorFdsCount + microseconds + maxFd; + (void)readFds; + (void)writeFds; + (void)errorFds; + (void)triggered; + (void)readFdsCount; + (void)writeFdsCount; + (void)errorFdsCount; + (void)microseconds; + (void)maxFd; return SystemNative_ConvertErrorPlatformToPal(ENOTSUP); #endif } @@ -3151,10 +3306,6 @@ static int32_t WaitForSocketEventsInner(int32_t port, SocketEvent* buffer, int32 #else static const size_t SocketEventBufferElementSize = 0; -static SocketEvents GetSocketEvents(int16_t filter, uint16_t flags) -{ - return SocketEvents_SA_NONE; -} static int32_t CloseSocketEventPortInner(int32_t port) { return Error_ENOSYS; @@ -3268,8 +3419,13 @@ void SystemNative_GetDomainSocketSizes(int32_t* pathOffset, int32_t* pathSize, i struct sockaddr_un domainSocket; +#if HAVE_SOCKADDR_UN_SUN_PATH *pathOffset = offsetof(struct sockaddr_un, sun_path); *pathSize = sizeof(domainSocket.sun_path); +#else // HAVE_SOCKADDR_UN_SUN_PATH + *pathOffset = 0; + *pathSize = 0; +#endif // HAVE_SOCKADDR_UN_SUN_PATH *addressSize = sizeof(domainSocket); } @@ -3449,8 +3605,13 @@ int32_t SystemNative_SendFile(intptr_t out_fd, intptr_t in_fd, int64_t offset, i uint32_t SystemNative_InterfaceNameToIndex(char* interfaceName) { +#if HAVE_NET_IF_H assert(interfaceName != NULL); if (interfaceName[0] == '%') interfaceName++; return if_nametoindex(interfaceName); +#else // HAVE_NET_IF_H + (void)interfaceName; + return Error_ENOTSUP; +#endif // HAVE_NET_IF_H } diff --git a/src/native/libs/System.Native/pal_networking.h b/src/native/libs/System.Native/pal_networking.h index a0904f295267d..8044ce00b0266 100644 --- a/src/native/libs/System.Native/pal_networking.h +++ b/src/native/libs/System.Native/pal_networking.h @@ -24,6 +24,7 @@ typedef enum GetAddrInfoErrorFlags_EAI_BADARG = 6, // One or more input arguments were invalid. GetAddrInfoErrorFlags_EAI_NOMORE = 7, // No more entries are present in the list. GetAddrInfoErrorFlags_EAI_MEMORY = 8, // Out of memory. + GetAddrInfoErrorFlags_EAI_SYSTEM = 9, // Other system error; errno is set to indicate the error. } GetAddrInfoErrorFlags; /** diff --git a/src/native/libs/System.Native/pal_networking_wasi.c b/src/native/libs/System.Native/pal_networking_wasi.c deleted file mode 100644 index baeb6494b31e7..0000000000000 --- a/src/native/libs/System.Native/pal_networking_wasi.c +++ /dev/null @@ -1,443 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#include "pal_config.h" -#include "pal_networking.h" -#include "pal_safecrt.h" -#include "pal_utilities.h" -#include -#include - -#include -#include -int32_t SystemNative_GetHostEntryForName(const uint8_t* address, int32_t addressFamily, HostEntry* entry) -{ - return -1; -} - -void SystemNative_FreeHostEntry(HostEntry* entry) -{ - if (entry != NULL) - { - free(entry->CanonicalName); - free(entry->IPAddressList); - - entry->CanonicalName = NULL; - entry->IPAddressList = NULL; - entry->IPAddressCount = 0; - } -} - -int32_t SystemNative_GetNameInfo(const uint8_t* address, - int32_t addressLength, - int8_t isIPv6, - uint8_t* host, - int32_t hostLength, - uint8_t* service, - int32_t serviceLength, - int32_t flags) -{ - assert(address != NULL); - assert(addressLength > 0); - assert((host != NULL) || (service != NULL)); - assert((hostLength > 0) || (serviceLength > 0)); - - return Error_EINVAL; -} - -int32_t SystemNative_GetDomainName(uint8_t* name, int32_t nameLength) -{ - assert(name != NULL); - assert(nameLength > 0); - return Error_EFAULT; -} - -int32_t SystemNative_GetHostName(uint8_t* name, int32_t nameLength) -{ - assert(name != NULL); - assert(nameLength > 0); - - size_t unsignedSize = (uint32_t)nameLength; - return gethostname((char*)name, unsignedSize); -} - -int32_t SystemNative_GetSocketAddressSizes(int32_t* ipv4SocketAddressSize, int32_t* ipv6SocketAddressSize, int32_t*udsSocketAddressSize, int* maxSocketAddressSize) -{ - return Error_EFAULT; -} - -int32_t SystemNative_GetAddressFamily(const uint8_t* socketAddress, int32_t socketAddressLen, int32_t* addressFamily) -{ - return Error_EFAULT; -} - -int32_t SystemNative_SetAddressFamily(uint8_t* socketAddress, int32_t socketAddressLen, int32_t addressFamily) -{ - return Error_EFAULT; -} - -int32_t SystemNative_GetPort(const uint8_t* socketAddress, int32_t socketAddressLen, uint16_t* port) -{ - return Error_EFAULT; -} - -int32_t SystemNative_SetPort(uint8_t* socketAddress, int32_t socketAddressLen, uint16_t port) -{ - return Error_EFAULT; -} - -int32_t SystemNative_GetIPv4Address(const uint8_t* socketAddress, int32_t socketAddressLen, uint32_t* address) -{ - return Error_EFAULT; -} - -int32_t SystemNative_SetIPv4Address(uint8_t* socketAddress, int32_t socketAddressLen, uint32_t address) -{ - return Error_EFAULT; -} - -int32_t SystemNative_GetIPv6Address( - const uint8_t* socketAddress, int32_t socketAddressLen, uint8_t* address, int32_t addressLen, uint32_t* scopeId) -{ - return Error_EFAULT; -} - -int32_t -SystemNative_SetIPv6Address(uint8_t* socketAddress, int32_t socketAddressLen, uint8_t* address, int32_t addressLen, uint32_t scopeId) -{ - return Error_EFAULT; -} - -int32_t SystemNative_GetControlMessageBufferSize(int32_t isIPv4, int32_t isIPv6) -{ - return Error_EFAULT; -} - - -int32_t -SystemNative_TryGetIPPacketInformation(MessageHeader* messageHeader, int32_t isIPv4, IPPacketInformation* packetInfo) -{ - if (messageHeader == NULL || packetInfo == NULL) - { - return 0; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetIPv4MulticastOption(intptr_t socket, int32_t multicastOption, IPv4MulticastOption* option) -{ - return Error_EINVAL; -} - -int32_t SystemNative_SetIPv4MulticastOption(intptr_t socket, int32_t multicastOption, IPv4MulticastOption* option) -{ - if (option == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetIPv6MulticastOption(intptr_t socket, int32_t multicastOption, IPv6MulticastOption* option) -{ - if (option == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_SetIPv6MulticastOption(intptr_t socket, int32_t multicastOption, IPv6MulticastOption* option) -{ - if (option == NULL) - { - return Error_EFAULT; - } - return Error_EINVAL; -} - - -int32_t SystemNative_GetLingerOption(intptr_t socket, LingerOption* option) -{ - if (option == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_SetLingerOption(intptr_t socket, LingerOption* option) -{ - if (option == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_SetReceiveTimeout(intptr_t socket, int32_t millisecondsTimeout) -{ - return Error_EINVAL; -} - -int32_t SystemNative_SetSendTimeout(intptr_t socket, int32_t millisecondsTimeout) -{ - return Error_EINVAL; -} -int32_t SystemNative_Receive(intptr_t socket, void* buffer, int32_t bufferLen, int32_t flags, int32_t* received) -{ - if (buffer == NULL || bufferLen < 0 || received == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_ReceiveMessage(intptr_t socket, MessageHeader* messageHeader, int32_t flags, int64_t* received) -{ - if (messageHeader == NULL || received == NULL || messageHeader->SocketAddressLen < 0 || - messageHeader->ControlBufferLen < 0 || messageHeader->IOVectorCount < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_Send(intptr_t socket, void* buffer, int32_t bufferLen, int32_t flags, int32_t* sent) -{ - return Error_EINVAL; -} - -int32_t SystemNative_SendMessage(intptr_t socket, MessageHeader* messageHeader, int32_t flags, int64_t* sent) -{ - return Error_EINVAL; -} - -int32_t SystemNative_Accept(intptr_t socket, uint8_t* socketAddress, int32_t* socketAddressLen, intptr_t* acceptedSocket) -{ - if (socketAddress == NULL || socketAddressLen == NULL || acceptedSocket == NULL || *socketAddressLen < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_Bind(intptr_t socket, int32_t protocolType, uint8_t* socketAddress, int32_t socketAddressLen) -{ - if (socketAddress == NULL || socketAddressLen < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_Connect(intptr_t socket, uint8_t* socketAddress, int32_t socketAddressLen) -{ - return Error_EINVAL; -} - -int32_t SystemNative_GetPeerName(intptr_t socket, uint8_t* socketAddress, int32_t* socketAddressLen) -{ - if (socketAddress == NULL || socketAddressLen == NULL || *socketAddressLen < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetSockName(intptr_t socket, uint8_t* socketAddress, int32_t* socketAddressLen) -{ - if (socketAddress == NULL || socketAddressLen == NULL || *socketAddressLen < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_Listen(intptr_t socket, int32_t backlog) -{ - return Error_EINVAL; -} - -int32_t SystemNative_Shutdown(intptr_t socket, int32_t socketShutdown) -{ - return Error_EINVAL; -} - -int32_t SystemNative_GetSocketErrorOption(intptr_t socket, int32_t* error) -{ - if (error == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetSockOpt( - intptr_t socket, int32_t socketOptionLevel, int32_t socketOptionName, uint8_t* optionValue, int32_t* optionLen) -{ - if (optionLen == NULL || *optionLen < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetRawSockOpt( - intptr_t socket, int32_t socketOptionLevel, int32_t socketOptionName, uint8_t* optionValue, int32_t* optionLen) -{ - if (optionLen == NULL || *optionLen < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t -SystemNative_SetSockOpt(intptr_t socket, int32_t socketOptionLevel, int32_t socketOptionName, uint8_t* optionValue, int32_t optionLen) -{ - return Error_EINVAL; -} - -int32_t SystemNative_SetRawSockOpt( - intptr_t socket, int32_t socketOptionLevel, int32_t socketOptionName, uint8_t* optionValue, int32_t optionLen) -{ - if (optionLen < 0 || optionValue == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_Socket(int32_t addressFamily, int32_t socketType, int32_t protocolType, intptr_t* createdSocket) -{ - if (createdSocket == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetSocketType(intptr_t socket, int32_t* addressFamily, int32_t* socketType, int32_t* protocolType, int32_t* isListening) -{ - if (addressFamily == NULL || socketType == NULL || protocolType == NULL || isListening == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetAtOutOfBandMark(intptr_t socket, int32_t* atMark) -{ - if (atMark == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_GetBytesAvailable(intptr_t socket, int32_t* available) -{ - if (available == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_CreateSocketEventPort(intptr_t* port) -{ - if (port == NULL) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_CloseSocketEventPort(intptr_t port) -{ - return Error_EINVAL; -} - -int32_t SystemNative_CreateSocketEventBuffer(int32_t count, SocketEvent** buffer) -{ - if (buffer == NULL || count < 0) - { - return Error_EFAULT; - } - - return Error_EINVAL; -} - -int32_t SystemNative_FreeSocketEventBuffer(SocketEvent* buffer) -{ - free(buffer); - return Error_SUCCESS; -} - -int32_t -SystemNative_TryChangeSocketEventRegistration(intptr_t port, intptr_t socket, int32_t currentEvents, int32_t newEvents, uintptr_t data) -{ - return Error_EINVAL; -} - -int32_t SystemNative_WaitForSocketEvents(intptr_t port, SocketEvent* buffer, int32_t* count) -{ - return Error_EINVAL; -} - -int32_t SystemNative_PlatformSupportsDualModeIPv4PacketInfo(void) -{ - return 0; -} - -void SystemNative_GetDomainSocketSizes(int32_t* pathOffset, int32_t* pathSize, int32_t* addressSize) -{ - *pathOffset = -1; - *pathSize = -1; - *addressSize = -1; -} - -int32_t SystemNative_GetMaximumAddressSize(void) -{ - return sizeof(struct sockaddr_storage); -} - -int32_t SystemNative_Disconnect(intptr_t socket) -{ - return Error_EINVAL; -} - -int32_t SystemNative_SendFile(intptr_t out_fd, intptr_t in_fd, int64_t offset, int64_t count, int64_t* sent) -{ - assert(sent != NULL); - - return Error_EINVAL; -} - -uint32_t SystemNative_InterfaceNameToIndex(char* interfaceName) -{ - assert(interfaceName != NULL); - return Error_EINVAL; -} - diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 477f9f1f14a03..945fbed855ce8 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -458,6 +458,18 @@ check_symbol_exists( sys/epoll.h HAVE_EPOLL) +check_symbol_exists( + gethostname + unistd.h + HAVE_GETHOSTNAME) + +check_symbol_exists( + getnameinfo + netdb.h + HAVE_GETNAMEINFO) + +check_struct_has_member("struct sockaddr_un" sun_path "sys/types.h;sys/un.h" HAVE_SOCKADDR_UN_SUN_PATH) + check_symbol_exists( accept4 sys/socket.h @@ -562,7 +574,10 @@ elseif(CLR_CMAKE_TARGET_ANDROID) unset(HAVE_ALIGNED_ALLOC) # only exists on newer Android set(HAVE_CLOCK_MONOTONIC 1) set(HAVE_CLOCK_REALTIME 1) -elseif(CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) +elseif(CLR_CMAKE_TARGET_WASI) + set(HAVE_FORK 0) + unset(HAVE_GETNAMEINFO) # WASIp2 libc has empty function with TODO and abort() +elseif(CLR_CMAKE_TARGET_BROWSER) set(HAVE_FORK 0) else() check_symbol_exists(