[vlc-commits] [Git][videolan/vlc][master] upnp: implement IPv4 host IP lookup for AppleOS

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Wed Mar 30 18:43:57 UTC 2022



Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC


Commits:
643fee9b by Felix Paul Kühne at 2022-03-30T18:28:33+00:00
upnp: implement IPv4 host IP lookup for AppleOS

This adds an additional info line to match the IPv6 implementation.

- - - - -


1 changed file:

- modules/services_discovery/upnp-wrapper.hpp


Changes:

=====================================
modules/services_discovery/upnp-wrapper.hpp
=====================================
@@ -408,12 +408,60 @@ inline char *getPreferedAdapter()
 #endif
 #else
 
-inline char *getIpv4ForMulticast()
+#ifdef __APPLE__
+
+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;
+}
+
+static char *getIpv4ForMulticast()
+{
+    struct ifaddrs *listOfInterfaces;
+    struct ifaddrs *anInterface;
+    int ret = getifaddrs(&listOfInterfaces);
+    char *bestIP = NULL;
+
+    if (ret != 0) {
+        return NULL;
+    }
+
+    anInterface = listOfInterfaces;
+    while (anInterface != NULL) {
+        if (anInterface->ifa_addr->sa_family == AF_INET) {
+            bool ret = necessaryFlagsSetOnInterface(anInterface);
+            if (ret) {
+                /* ignore sockets connecting to the touchbar on MacBooks */
+                if (strncmp(anInterface->ifa_name, "bridge", 6) != 0) {
+                    if (bestIP) {
+                        FREENULL(bestIP);
+                    }
+                    bestIP = strdup(inet_ntoa(((struct sockaddr_in *)anInterface->ifa_addr)->sin_addr));
+                }
+            }
+        }
+
+        anInterface = anInterface->ifa_next;
+    }
+    freeifaddrs(listOfInterfaces);
+
+    return bestIP;
+}
+
+#else
+
+static char *getIpv4ForMulticast()
 {
     return NULL;
 }
 
 #endif
 
+#endif
+
 #endif /* _WIN32 */
 #endif /* UPNP_WRAPPER_H */



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/643fee9b6a2acff55ed9c13635bca6ccc5c1c6a8

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/643fee9b6a2acff55ed9c13635bca6ccc5c1c6a8
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list