From 4869559e8201e8a1e8c7dc5a3ecf7c081f059fcd Mon Sep 17 00:00:00 2001 From: Fey Date: Tue, 25 Aug 2026 18:15:26 +0200 Subject: [PATCH] The SSDP M-SEARCH feature can now run on Synology DSM. --- .gitignore | 1 + .../SimpleServiceDiscoveryProtocol/SsdpClient.cs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2d26019..9553a02 100644 --- a/.gitignore +++ b/.gitignore @@ -139,3 +139,4 @@ imgui.ini /skyscraper8.Tests.NUnit/obj/Debug/net8.0 /skyscraper8.Tests.NUnit/obj .idea/.idea.skyscraper8/.idea +/skyscraper8/bin/Release/net8.0/linux-x64 diff --git a/skyscraper8/SimpleServiceDiscoveryProtocol/SsdpClient.cs b/skyscraper8/SimpleServiceDiscoveryProtocol/SsdpClient.cs index 13a4cc7..bf03811 100644 --- a/skyscraper8/SimpleServiceDiscoveryProtocol/SsdpClient.cs +++ b/skyscraper8/SimpleServiceDiscoveryProtocol/SsdpClient.cs @@ -27,14 +27,17 @@ namespace skyscraper8.SimpleServiceDiscoveryProtocol { NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); IPAddress[] ipAddresses = Array.ConvertAll(networkInterfaces, x => GetIPAddress(x)); - IPEndPoint[] localEndPoints = Array.ConvertAll(ipAddresses, x => new IPEndPoint(x, 1901)); + IPEndPoint[] localEndPoints = Array.ConvertAll(ipAddresses, x => new IPEndPoint(x, 0)); //don't use port 1901 here. It's used by old SSDP example code but is wrong. IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900); Socket[] udpSockets = Array.ConvertAll(localEndPoints, x => { byte[] addressBytes = x.Address.GetAddressBytes(); - if (addressBytes[0] == 169) - return null; + if (addressBytes[0] == 169 || addressBytes.Length != 4) + { + logger.WarnFormat("The address {0} will not be used because it's network type is not supported.", new IPAddress(addressBytes)); + return null; + } Socket temp = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); temp.Bind(x); temp.SendTo(Encoding.UTF8.GetBytes(SEARCH_STRING), SocketFlags.None, remoteEndPoint); @@ -81,6 +84,11 @@ namespace skyscraper8.SimpleServiceDiscoveryProtocol { IPInterfaceProperties ipProperties = networkInterface.GetIPProperties(); UnicastIPAddressInformationCollection addresses = ipProperties.UnicastAddresses; + if (addresses.Count == 0) + { + logger.WarnFormat("Network interface {0} does not have an unicast address.", networkInterface.Name); + return IPAddress.Loopback; + } UnicastIPAddressInformation[] addressArray = addresses.ToArray(); Array.Sort(addressArray, (a, b) => RateIpAddress(b).CompareTo(RateIpAddress(a))); UnicastIPAddressInformation address = addressArray[0];