The SSDP M-SEARCH feature can now run on Synology DSM.
All checks were successful
🚀 Pack skyscraper8 / make-zip (push) Successful in 44s

This commit is contained in:
Fey 2026-08-25 18:15:26 +02:00
parent dd58a37bed
commit 4869559e82
2 changed files with 12 additions and 3 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -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];