File tree Expand file tree Collapse file tree 1 file changed +5
-16
lines changed
dotnet/src/webdriver/Internal Expand file tree Collapse file tree 1 file changed +5
-16
lines changed Original file line number Diff line number Diff line change @@ -33,21 +33,10 @@ public static class PortUtilities
3333 /// <returns>A random, free port to be listened on.</returns>
3434 public static int FindFreePort ( )
3535 {
36- // Locate a free port on the local machine by binding a socket to
37- // an IPEndPoint using IPAddress.Any and port 0. The socket will
38- // select a free port.
39- try
40- {
41- using var socket = new Socket ( AddressFamily . InterNetworkV6 , SocketType . Stream , ProtocolType . Tcp ) ;
42- socket . Bind ( new IPEndPoint ( IPAddress . IPv6Loopback , 0 ) ) ;
43- return ( socket . LocalEndPoint as IPEndPoint ) ! . Port ;
44- }
45- catch ( SocketException )
46- {
47- // If IPv6 is not supported, fallback to IPv4
48- using var socket = new Socket ( AddressFamily . InterNetwork , SocketType . Stream , ProtocolType . Tcp ) ;
49- socket . Bind ( new IPEndPoint ( IPAddress . Loopback , 0 ) ) ;
50- return ( socket . LocalEndPoint as IPEndPoint ) ! . Port ;
51- }
36+ using var socket = new Socket ( AddressFamily . InterNetworkV6 , SocketType . Stream , ProtocolType . Tcp ) ;
37+ socket . DualMode = true ;
38+ socket . Bind ( new IPEndPoint ( IPAddress . IPv6Loopback , 0 ) ) ;
39+ return ( socket . LocalEndPoint as IPEndPoint ) ! . Port ;
40+
5241 }
5342}
You can’t perform that action at this time.
0 commit comments