Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Servers/Kestrel/Core/src/AnyIPListenOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
using Microsoft.Extensions.Logging;

Expand All @@ -11,7 +12,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core;
internal sealed class AnyIPListenOptions : ListenOptions
{
internal AnyIPListenOptions(int port)
: base(new IPEndPoint(IPAddress.IPv6Any, port))
: base(new IPEndPoint(Socket.OSSupportsIPv6 ? IPAddress.IPv6Any : IPAddress.Any, port))
{
}

Expand Down
31 changes: 31 additions & 0 deletions src/Servers/Kestrel/Core/test/AddressBinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
using Microsoft.AspNetCore.InternalTesting;
using Microsoft.DotNet.RemoteExecutor;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
Expand Down Expand Up @@ -62,6 +63,36 @@ public void ParseAddressDefaultsToAnyIPOnInvalidIPAddress(string host)
Assert.False(https);
}

[ConditionalFact]
[RemoteExecutionSupported]
public void ParseAddressOnOSWithoutIPv6()
{
var tmpDir = Directory.CreateTempSubdirectory();

try
{
var options = new RemoteInvokeOptions();
options.StartInfo.WorkingDirectory = tmpDir.FullName;
options.StartInfo.EnvironmentVariables["DOTNET_SYSTEM_NET_DISABLEIPV6"] = "1";

using var remoteHandle = RemoteExecutor.Invoke(static () =>
{
Assert.False(Socket.OSSupportsIPv6);

var listenOptions = AddressBinder.ParseAddress($"http://*:80", out var https);
Assert.IsType<AnyIPListenOptions>(listenOptions);
Assert.IsType<IPEndPoint>(listenOptions.EndPoint);
Assert.Equal(IPAddress.Any, listenOptions.IPEndPoint.Address);
Assert.Equal(80, listenOptions.IPEndPoint.Port);
Assert.False(https);
}, options);
}
finally
{
tmpDir.Delete(recursive: true);
}
}

[Fact]
public void ParseAddressLocalhost()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
<Reference Include="Microsoft.Extensions.Logging" />
<Reference Include="Microsoft.Extensions.Diagnostics.Testing" />
<Reference Include="Microsoft.Extensions.TimeProvider.Testing" />
<Reference Include="Microsoft.DotNet.RemoteExecutor" />
</ItemGroup>
</Project>
Loading