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

Felix Paul Kühne fkuehne at videolan.org
Fri Jul 3 12:59:50 CEST 2020


From: Felix Paul Kühne <felix at feepk.net>

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

diff --git a/modules/services_discovery/upnp.cpp b/modules/services_discovery/upnp.cpp
index 13c1eb7971..c9cd08f053 100644
--- a/modules/services_discovery/upnp.cpp
+++ b/modules/services_discovery/upnp.cpp
@@ -1621,9 +1621,38 @@ 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 = NULL;
+    struct ifaddrs *anInterface = NULL;
+    int ret = getifaddrs(&listOfInterfaces);
+    char *adapterName = NULL;
+
+    if (ret == 0) {
+        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
-- 
2.21.1 (Apple Git-122.3)



More information about the vlc-devel mailing list