[vlc-devel] [PATCH] upnp: add basic network interface discovery for iOS and tvOS
Rémi Denis-Courmont
remi at remlab.net
Thu Jul 2 16:44:03 CEST 2020
Le torstaina 2. heinäkuuta 2020, 13.56.49 EEST Felix Paul Kühne a écrit :
> 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
Come on. Did you even spend 5 seconds considering what could possibly go wrong
here? Like Apple decides to change the names in an OS update, or somebody's
using a VPN?
--
Реми Дёни-Курмон
http://www.remlab.net/
More information about the vlc-devel
mailing list