+ 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";
+ for (const char *c_scope = ipv6_scopes; *c_scope; c_scope++)
+ {
+ psz_address[3] = *c_scope;
+ InitSocket( p_sd, psz_address, SAP_PORT );
+ }
+ }
+
+ psz_addr = var_CreateGetString( p_sd, "sap-addr" );
+ if( psz_addr && *psz_addr )
+ InitSocket( p_sd, psz_addr, SAP_PORT );
+ free( psz_addr );
+
+ if( p_sd->p_sys->i_fd == 0 )
+ {
+ msg_Err( p_sd, "unable to listen on any address" );
+ return;
+ }
+
+ vlc_object_lock( p_sd );
+
+ /* read SAP packets */
+ while( vlc_object_alive( p_sd ) )
+ {
+ unsigned n = p_sd->p_sys->i_fd;
+ struct pollfd ufd[n+1];
+
+ for (unsigned i = 0; i < n; i++)
+ {
+ ufd[i].fd = p_sd->p_sys->pi_fd[i];
+ ufd[i].events = POLLIN;
+ ufd[i].revents = 0;
+ }
+
+ /* Make sure we track vlc_object_signal() */
+ ufd[n].fd = vlc_object_waitpipe( p_sd );
+ ufd[n].events = POLLIN | POLLHUP;
+ ufd[n].revents = 0;