[vlc-commits] upnp: add basic network interface discovery for iOS and tvOS

Felix Paul Kühne git at videolan.org
Mon Jul 13 10:31:48 CEST 2020


vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Mon Jul  6 13:57:55 2020 +0200| [c4bb98bd0f55b8b18a3adfaa3f0a94ad66fd8bbf] | committer: Felix Paul Kühne

upnp: add basic network interface discovery for iOS and tvOS

This is a manual forward-port of a8e6a381.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c4bb98bd0f55b8b18a3adfaa3f0a94ad66fd8bbf
---

 modules/services_discovery/upnp-wrapper.hpp | 41 +++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/modules/services_discovery/upnp-wrapper.hpp b/modules/services_discovery/upnp-wrapper.hpp
index ba132dc50b..f692552eae 100644
--- a/modules/services_discovery/upnp-wrapper.hpp
+++ b/modules/services_discovery/upnp-wrapper.hpp
@@ -337,7 +337,6 @@ done:
 
 #ifdef __APPLE__
 #include <TargetConditionals.h>
-#endif
 
 #if defined(TARGET_OS_OSX) && TARGET_OS_OSX
 #include <SystemConfiguration/SystemConfiguration.h>
@@ -364,7 +363,45 @@ inline char *getPreferedAdapter()
     return returnValue;
 }
 
-#else
+#else /* iOS and tvOS */
+
+inline bool necessaryFlagsSetOnInterface(struct ifaddrs *anInterface)
+{
+    unsigned int flags = anInterface->ifa_flags;
+    if( (flags & IFF_UP) && (flags & IFF_RUNNING) && !(flags & IFF_LOOPBACK) && !(flags & IFF_POINTOPOINT) ) {
+        return true;
+    }
+    return false;
+}
+
+inline char *getPreferedAdapter()
+{
+    struct ifaddrs *listOfInterfaces;
+    struct ifaddrs *anInterface;
+    int ret = getifaddrs(&listOfInterfaces);
+    char *adapterName = NULL;
+
+    if (ret != 0) {
+        return NULL;
+    }
+
+    anInterface = listOfInterfaces;
+    while (anInterface != NULL) {
+        bool ret = necessaryFlagsSetOnInterface(anInterface);
+        if (ret) {
+            adapterName = strdup(anInterface->ifa_name);
+            break;
+        }
+
+        anInterface = anInterface->ifa_next;
+    }
+    freeifaddrs(listOfInterfaces);
+
+    return adapterName;
+}
+#endif
+
+#else /* *nix and Android */
 
 inline char *getPreferedAdapter()
 {



More information about the vlc-commits mailing list