Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ListenToSocketInternal so it works after Jellyfin 10.9.2 #51

Merged
merged 3 commits into from
May 26, 2024

Conversation

ms-afk
Copy link
Contributor

@ms-afk ms-afk commented May 26, 2024

Related to this issue.

The last Jellyfin update changed NetworkManager's GetAllBindInterfaces method.
This caused ListenToSocketInternal to fail if no local addresses were set, because the new implementation returns an IPData object without setting its Index property.
This causes the First() method in ListenToSocketInternal to throw an InvalidOperationException.

To fix this I check if GetAllBindInterfaces returns one and just one IPData object and if this object corresponds to what GetAllBindInterfaces returns in case no local address has been set in Jellyfin.

Indeed GetAllBindInterfaces will only set those addresses (IPAddress.Any and IPAddress.IPv6Any) when no local address has been set.

changed NetworkManager's GetAllBindInterfaces method.
Copy link
Member

@crobibero crobibero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting is off

Index: src/Rssdp/SsdpCommunicationsServer.cs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Rssdp/SsdpCommunicationsServer.cs b/src/Rssdp/SsdpCommunicationsServer.cs
--- a/src/Rssdp/SsdpCommunicationsServer.cs	(revision 2fa639a5a808b16b55399840b961dacf220a9706)
+++ b/src/Rssdp/SsdpCommunicationsServer.cs	(date 1716745437738)
@@ -416,19 +416,17 @@
                         var remoteEndpoint = (IPEndPoint)result.RemoteEndPoint;
                         var allBindInterfaces = _networkManager.GetAllBindInterfaces();
                         IPData localEndpointAdapter;
-                        if (
-                            allBindInterfaces.Count == 1
-                            && (
-                                allBindInterfaces.First().Address.Equals(IPAddress.Any)
-                                || allBindInterfaces.First().Address.Equals(IPAddress.IPv6Any)
-                            )
-                        )
+                        if (allBindInterfaces.Count == 1
+                            && (allBindInterfaces[0].Address.Equals(IPAddress.Any)
+                                || allBindInterfaces[0].Address.Equals(IPAddress.IPv6Any)))
                         {
-                            localEndpointAdapter = allBindInterfaces.First();
-                        } else
+                            localEndpointAdapter = allBindInterfaces[0];
+                        }
+                        else
                         {
                             localEndpointAdapter = allBindInterfaces.First(a => a.Index == result.PacketInformation.Interface);
                         }
+
                         ProcessMessage(
                             Encoding.UTF8.GetString(receiveBuffer, 0, result.ReceivedBytes),
                             remoteEndpoint,
@@ -522,7 +520,7 @@
                 LocalIPAddress = localIPAddress
             });
         }
-        
+
         private Socket CreateSsdpUdpSocket(IPData bindInterface, int localPort)
         {
             var interfaceAddress = bindInterface.Address;
@@ -548,7 +546,7 @@
                 throw;
             }
         }
-        
+
         private Socket CreateUdpMulticastSocket(IPAddress multicastAddress, IPData bindInterface, int multicastTimeToLive, int localPort)
         {
             var bindIPAddress = bindInterface.Address;

@ms-afk
Copy link
Contributor Author

ms-afk commented May 26, 2024

Fixed formatting

@crobibero crobibero merged commit c23e55c into jellyfin:master May 26, 2024
3 checks passed
Comment on lines +419 to +428
if (allBindInterfaces.Count == 1
&& (allBindInterfaces[0].Address.Equals(IPAddress.Any)
|| allBindInterfaces[0].Address.Equals(IPAddress.IPv6Any)))
{
localEndpointAdapter = allBindInterfaces[0];
}
else
{
localEndpointAdapter = allBindInterfaces.First(a => a.Index == result.PacketInformation.Interface);
}

Check notice

Code scanning / CodeQL

Missed ternary opportunity Note

Both branches of this 'if' statement write to the same variable - consider using '?' to express intent better.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants