]> git.sesse.net Git - vlc/commitdiff
sap.c: win32 fix for IPv6 local-link zone identifier
authorDamien Fouilleul <damienf@videolan.org>
Wed, 28 Feb 2007 12:07:45 +0000 (12:07 +0000)
committerDamien Fouilleul <damienf@videolan.org>
Wed, 28 Feb 2007 12:07:45 +0000 (12:07 +0000)
modules/services_discovery/sap.c

index 3efddedfe5ac8198936aa530cf075f92413fd3b2..67d99a2095cd001bc3eb6efa5797e8e13c684e9c 100644 (file)
 #ifdef HAVE_ZLIB_H
 #   include <zlib.h>
 #endif
-#include <net/if.h>
+
+#ifndef WIN32
+#   include <net/if.h>
+#endif
 
 /************************************************************************
  * Macros and definitions
@@ -492,6 +495,7 @@ static void Run( services_discovery_t *p_sd )
     {
         char psz_address[NI_MAXNUMERICHOST] = "ff02::2:7ffe%";
 
+#ifndef WIN32
         struct if_nameindex *l = if_nameindex ();
         if (l != NULL)
         {
@@ -503,6 +507,30 @@ static void Run( services_discovery_t *p_sd )
             }
             if_freenameindex (l);
         }
+#else
+        /* this is the Winsock2 equivalant of SIOCGIFCONF on BSD stacks,
+           which if_nameindex uses internally anyway */
+
+        // first create a dummy socket to pin down the protocol family
+        SOCKET s = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
+        if( s != INVALID_SOCKET )
+        {
+            INTERFACE_INFO ifaces[10]; // Assume there will be no more than 10 IP interfaces
+            size_t len = sizeof(ifaces); 
+             
+            if( SOCKET_ERROR != WSAIoctl(s, SIO_GET_INTERFACE_LIST, NULL, 0, &ifaces, len, &len, NULL, NULL) )
+            {
+                unsigned ifcount = len/sizeof(INTERFACE_INFO);
+                char *ptr = strchr (psz_address, '%') + 1;
+                for(unsigned i = 1; i<=ifcount; ++i )
+                {
+                    // append link-local zone identifier
+                    sprintf(ptr, "%d", i);
+                }
+            }
+            closesocket(s);
+        }
+#endif
         *strchr (psz_address, '%') = '\0';
 
         static const char ipv6_scopes[] = "1456789ABCDE";