From b9daafa91b053bac65c365e459b6ac3c96388f2d Mon Sep 17 00:00:00 2001
From: Alaric Senat <dev.asenat@posteo.net>
Date: Wed, 6 Apr 2022 11:08:48 +0200
Subject: [PATCH] upnp: win32: accept net-intf that support both IPv4/6

Previously when libupnp was built with IPv6 enabled only the adapters
supporting IPv6 were accepted. libupnp does support IPv4 even when built
with IPv6, this commit accept both kinds of adapters instead of
excluding the ones that does not support IPv6 at all.
---
 modules/services_discovery/upnp-wrapper.hpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/modules/services_discovery/upnp-wrapper.hpp b/modules/services_discovery/upnp-wrapper.hpp
index 8eb062a052ed..a2a9fb0f4d28 100644
--- a/modules/services_discovery/upnp-wrapper.hpp
+++ b/modules/services_discovery/upnp-wrapper.hpp
@@ -135,9 +135,10 @@ inline bool isAdapterSuitable(IP_ADAPTER_ADDRESSES* p_adapter)
     if (p_adapter->Length == sizeof(IP_ADAPTER_ADDRESSES_XP))
     {
         IP_ADAPTER_ADDRESSES_XP* p_adapter_xp = reinterpret_cast<IP_ADAPTER_ADDRESSES_XP*>( p_adapter );
-        // On Windows Server 2003 and Windows XP, this member is zero if IPv4 is not available on the interface.
+        // On Windows Server 2003 and Windows XP, those members are zero if the IPv* implementation
+        // is not available on the interface.
 #if defined( UPNP_ENABLE_IPV6 )
-        return p_adapter_xp->Ipv6IfIndex != 0;
+        return p_adapter_xp->Ipv6IfIndex != 0 || p_adapter_xp->IfIndex != 0;
 #else
         return p_adapter_xp->IfIndex != 0;
 #endif
@@ -146,7 +147,7 @@ inline bool isAdapterSuitable(IP_ADAPTER_ADDRESSES* p_adapter)
     if (p_adapter_lh->FirstGatewayAddress == NULL)
         return false;
 #if defined( UPNP_ENABLE_IPV6 )
-    return p_adapter_lh->Ipv6Enabled;
+    return p_adapter_lh->Ipv6Enabled || p_adapter_lh->Ipv4Enabled;
 #else
     return p_adapter_lh->Ipv4Enabled;
 #endif
-- 
GitLab