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

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


vlc/vlc-3.0 | branch: master | Felix Paul Kühne <felix at feepk.net> | Wed Jul  1 13:45:29 2020 +0200| [a8e6a381bd81bbe6838499bc8f1b68fef663f8cb] | committer: Felix Paul Kühne

upnp: add basic network interface discovery for iOS and tvOS

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

 modules/services_discovery/upnp.cpp | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/modules/services_discovery/upnp.cpp b/modules/services_discovery/upnp.cpp
index d51a533b47..9a905d2496 100644
--- a/modules/services_discovery/upnp.cpp
+++ b/modules/services_discovery/upnp.cpp
@@ -1602,9 +1602,39 @@ inline char *getPreferedAdapter()
 }
 #else
 
-static char *getPreferedAdapter()
+inline bool necessaryFlagsSetOnInterface(struct ifaddrs *anInterface)
 {
-    return NULL;
+    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



More information about the vlc-commits mailing list