02709af2ba7bf6f541646aadf7f5ff95ad11482f
[mono.git] / mcs / class / test-helpers / NetworkHelpers.cs
1 using System;
2 using System.Net;
3 using System.Net.Sockets;
4
5 namespace MonoTests.Helpers {
6
7         public static class NetworkHelpers
8         {
9                 public static int FindFreePort ()
10                 {
11                         TcpListener l = new TcpListener(IPAddress.Loopback, 0);
12                         l.Start();
13                         int port = ((IPEndPoint)l.LocalEndpoint).Port;
14                         l.Stop();
15                         return port;
16                 }
17         }
18 }