service_discovery: upnp: select the default route interface on linux
Description
Note: the issue is #24992. I'm opening against 3.0.x because I don't yet manage to compile vlc master with qt6 (which is required for master?).
When doing upnp discovery, vlc has to init libupnp. On windows and apple device, the current 3.0.x branch take the first suitable interface found and use it (see the note below). On linux, the current code wasn't doing anything and instead relies on the default selection by libupnp, which simply selects the first interface it finds.
The issue is that this interface is not generally the right one: it does not even check if this interface is connected for instance. So if your wifi card, or docker0 interface appears before a connected ethernet card (which is often the case with my laptop), libupnp is selecting the former instead of the latter.
I propose to fix that by always selecting the interface corresponding to the default ip route. Note that this does not yet support a upnp service running inside a docker on localhost for instance, but it is a net improvement compared to the current situation: with this patch, my vlc reliably detects my minidlna service on my nas and my freebox when I'm at home.
I expect that this is the behaviour regular user will want most of the time.
The notion of suitable interface is different according to platform apparently:
- for windows: it's the first interface with an IP adress, if I read correctly.
- for OSX: an interface flagged with "PrimaryInterface" apparently
- For iOs and Tvos: the first interface having flags IFF_UP, IFF_RUNNING, but not IFF_LOOPBACK and IFF_POINTOPOINT.
I'd argue that for windows and iOS/tvos, we should also select the default route interface, but I have no such device to test, so I left this out :-(