aboutsummaryrefslogtreecommitdiff
path: root/Emby.Common.Implementations/Networking/NetworkManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Common.Implementations/Networking/NetworkManager.cs')
-rw-r--r--Emby.Common.Implementations/Networking/NetworkManager.cs14
1 files changed, 12 insertions, 2 deletions
diff --git a/Emby.Common.Implementations/Networking/NetworkManager.cs b/Emby.Common.Implementations/Networking/NetworkManager.cs
index 4485e8b14..2b84b2aa1 100644
--- a/Emby.Common.Implementations/Networking/NetworkManager.cs
+++ b/Emby.Common.Implementations/Networking/NetworkManager.cs
@@ -234,7 +234,7 @@ namespace Emby.Common.Implementations.Networking
// Try to exclude virtual adapters
// http://stackoverflow.com/questions/8089685/c-sharp-finding-my-machines-local-ip-address-and-not-the-vms
var addr = ipProperties.GatewayAddresses.FirstOrDefault();
- if (addr == null|| string.Equals(addr.Address.ToString(), "0.0.0.0", StringComparison.OrdinalIgnoreCase))
+ if (addr == null || string.Equals(addr.Address.ToString(), "0.0.0.0", StringComparison.OrdinalIgnoreCase))
{
return new List<IPAddress>();
}
@@ -275,7 +275,7 @@ namespace Emby.Common.Implementations.Networking
/// Gets a random port number that is currently available
/// </summary>
/// <returns>System.Int32.</returns>
- public int GetRandomUnusedPort()
+ public int GetRandomUnusedTcpPort()
{
var listener = new TcpListener(IPAddress.Any, 0);
listener.Start();
@@ -284,6 +284,16 @@ namespace Emby.Common.Implementations.Networking
return port;
}
+ public int GetRandomUnusedUdpPort()
+ {
+ IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, 0);
+ using (var udpClient = new UdpClient(localEndPoint))
+ {
+ var port = ((IPEndPoint)(udpClient.Client.LocalEndPoint)).Port;
+ return port;
+ }
+ }
+
/// <summary>
/// Returns MAC Address from first Network Card in Computer
/// </summary>