mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-28 15:40:56 +01:00
Make sure to test IPv6
This commit is contained in:
@@ -481,7 +481,7 @@ namespace Tgstation.Server.Host.Components
|
||||
|
||||
// This runs before the real socket is opened, ensures we don't perform reattaches unless we're fairly certain the bind won't fail
|
||||
// If it does fail, DD will be killed.
|
||||
SocketExtensions.BindTest(serverPortProvider.HttpApiPort);
|
||||
SocketExtensions.BindTest(serverPortProvider.HttpApiPort, true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace Tgstation.Server.Host.Components.Session
|
||||
{
|
||||
try
|
||||
{
|
||||
SocketExtensions.BindTest(port);
|
||||
SocketExtensions.BindTest(port, false);
|
||||
}
|
||||
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.AddressAlreadyInUse)
|
||||
{
|
||||
|
||||
@@ -12,12 +12,21 @@ namespace Tgstation.Server.Host.Extensions
|
||||
/// Attempt to exclusively bind to a given <paramref name="port"/>.
|
||||
/// </summary>
|
||||
/// <param name="port">The port number to bind to.</param>
|
||||
public static void BindTest(ushort port)
|
||||
/// <param name="includeIPv6">If IPV6 should be tested as well.</param>
|
||||
public static void BindTest(ushort port, bool includeIPv6)
|
||||
{
|
||||
using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, true);
|
||||
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, false);
|
||||
socket.Bind(new IPEndPoint(IPAddress.Any, port));
|
||||
if (includeIPv6)
|
||||
socket.DualMode = true;
|
||||
|
||||
socket.Bind(
|
||||
new IPEndPoint(
|
||||
includeIPv6
|
||||
? IPAddress.IPv6Any
|
||||
: IPAddress.Any,
|
||||
port));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user