From cab48c6006ba39041dea23753f7c1c6bf466961d Mon Sep 17 00:00:00 2001 From: delta456 Date: Thu, 19 Dec 2024 00:12:10 +0530 Subject: [PATCH] [c#] support IPv6 ports as well --- dotnet/src/webdriver/Internal/PortUtilities.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/Internal/PortUtilities.cs b/dotnet/src/webdriver/Internal/PortUtilities.cs index 26c45a8b2688f..5908987428948 100644 --- a/dotnet/src/webdriver/Internal/PortUtilities.cs +++ b/dotnet/src/webdriver/Internal/PortUtilities.cs @@ -37,9 +37,11 @@ public static int FindFreePort() // an IPEndPoint using IPAddress.Any and port 0. The socket will // select a free port. int listeningPort = 0; - Socket portSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + // Use a dual-stack socket (IPv6 family will support both IPv4 and IPv6) + Socket portSocket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); try { + portSocket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false); IPEndPoint socketEndPoint = new IPEndPoint(IPAddress.Any, 0); portSocket.Bind(socketEndPoint); socketEndPoint = (IPEndPoint)portSocket.LocalEndPoint;