The SSDP M-SEARCH feature can now run on Synology DSM.
All checks were successful
🚀 Pack skyscraper8 / make-zip (push) Successful in 44s
All checks were successful
🚀 Pack skyscraper8 / make-zip (push) Successful in 44s
This commit is contained in:
parent
dd58a37bed
commit
4869559e82
1
.gitignore
vendored
1
.gitignore
vendored
@ -139,3 +139,4 @@ imgui.ini
|
|||||||
/skyscraper8.Tests.NUnit/obj/Debug/net8.0
|
/skyscraper8.Tests.NUnit/obj/Debug/net8.0
|
||||||
/skyscraper8.Tests.NUnit/obj
|
/skyscraper8.Tests.NUnit/obj
|
||||||
.idea/.idea.skyscraper8/.idea
|
.idea/.idea.skyscraper8/.idea
|
||||||
|
/skyscraper8/bin/Release/net8.0/linux-x64
|
||||||
|
|||||||
@ -27,14 +27,17 @@ namespace skyscraper8.SimpleServiceDiscoveryProtocol
|
|||||||
{
|
{
|
||||||
NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
|
NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
|
||||||
IPAddress[] ipAddresses = Array.ConvertAll(networkInterfaces, x => GetIPAddress(x));
|
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);
|
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900);
|
||||||
Socket[] udpSockets = Array.ConvertAll(localEndPoints,
|
Socket[] udpSockets = Array.ConvertAll(localEndPoints,
|
||||||
x =>
|
x =>
|
||||||
{
|
{
|
||||||
byte[] addressBytes = x.Address.GetAddressBytes();
|
byte[] addressBytes = x.Address.GetAddressBytes();
|
||||||
if (addressBytes[0] == 169)
|
if (addressBytes[0] == 169 || addressBytes.Length != 4)
|
||||||
return null;
|
{
|
||||||
|
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);
|
Socket temp = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
||||||
temp.Bind(x);
|
temp.Bind(x);
|
||||||
temp.SendTo(Encoding.UTF8.GetBytes(SEARCH_STRING), SocketFlags.None, remoteEndPoint);
|
temp.SendTo(Encoding.UTF8.GetBytes(SEARCH_STRING), SocketFlags.None, remoteEndPoint);
|
||||||
@ -81,6 +84,11 @@ namespace skyscraper8.SimpleServiceDiscoveryProtocol
|
|||||||
{
|
{
|
||||||
IPInterfaceProperties ipProperties = networkInterface.GetIPProperties();
|
IPInterfaceProperties ipProperties = networkInterface.GetIPProperties();
|
||||||
UnicastIPAddressInformationCollection addresses = ipProperties.UnicastAddresses;
|
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();
|
UnicastIPAddressInformation[] addressArray = addresses.ToArray();
|
||||||
Array.Sort(addressArray, (a, b) => RateIpAddress(b).CompareTo(RateIpAddress(a)));
|
Array.Sort(addressArray, (a, b) => RateIpAddress(b).CompareTo(RateIpAddress(a)));
|
||||||
UnicastIPAddressInformation address = addressArray[0];
|
UnicastIPAddressInformation address = addressArray[0];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user