Skip to content

Commit

Permalink
[c#] support IPv6 ports as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Dec 18, 2024
1 parent 4001475 commit cab48c6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dotnet/src/webdriver/Internal/PortUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cab48c6

Please sign in to comment.