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

Felix Paul Kühne fkuehne at videolan.org
Thu Jul 2 12:56:49 CEST 2020


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

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

diff --git a/modules/services_discovery/upnp.cpp b/modules/services_discovery/upnp.cpp
index 13c1eb7971..3e7e39a225 100644
--- a/modules/services_discovery/upnp.cpp
+++ b/modules/services_discovery/upnp.cpp
@@ -1621,9 +1621,52 @@ inline char *getPreferedAdapter()
 }
 #else
 
-static char *getPreferedAdapter()
+inline bool necessaryFlagsSetOnInterface(struct ifaddrs *anInterface, const char *nameToCompare)
 {
-    return NULL;
+    if (strncmp (anInterface->ifa_name, nameToCompare, strlen(nameToCompare)) == 0) {
+        unsigned int flags = anInterface->ifa_flags;
+        if( (flags & IFF_UP) && (flags & IFF_RUNNING) && !(flags & IFF_LOOPBACK) ) {
+            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, "en0");
+            if (ret) {
+                adapterName = strdup(anInterface->ifa_name);
+                break;
+            }
+
+            ret = necessaryFlagsSetOnInterface(anInterface, "en1");
+            if (ret) {
+                adapterName = strdup(anInterface->ifa_name);
+                break;
+            }
+
+            ret = necessaryFlagsSetOnInterface(anInterface, "bridge100");
+            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