<html><head></head><body>Hi,<br><br>How does libmicrodns work if there are multiple apps, multiple users and/or multiple instances of the same app running?<br><br><div class="gmail_quote">Le 4 août 2019 07:55:49 GMT+02:00, Roland Bewick <roland.bewick@gmail.com> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail"><br>On 2/08/2019 4:19 PM, Marvin Scholz wrote:<br>><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"><br> On 2 Aug 2019, at 8:03, Thomas Guillem wrote:<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;">On Wed, Jul 31, 2019, at 08:35, Roland Bewick wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;">On 27/07/2019 2:04 PM, Roland Bewick wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;">On 26/07/2019 1:07 AM, Rémi Denis-Courmont wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;">Le torstaina 25. heinäkuuta 2019, 20.51.09 EEST Roland Bewick a <br>écrit :<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"> On Fri, 26 Jul 2019 at 12:15 AM, Rémi Denis-Courmont <br> <remi@remlab.net><br><br> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;">Le torstaina 25. heinäkuuta 2019, 8.39.11 EEST Roland Bewick a <br>écrit :<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;">On 24/07/2019 11:18 PM, Rémi Denis-Courmont wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;">Le keskiviikkona 24. heinäkuuta 2019, 19.10.50 EEST Roland <br>Bewick a<br></blockquote></blockquote> écrit<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"> Hi Rémi,<br><br> Thanks for the reply.<br><br> On 24/07/2019 10:59 PM, Rémi Denis-Courmont wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"> Le keskiviikkona 24. heinäkuuta 2019, 18.43.49 EEST Roland<br> Bewick a<br> écrit<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><hr>     modules/services_discovery/microdns.c | 62<br><br> +++++++++++++++++++++++++++++++++-- 1 file changed, 59<br></blockquote></blockquote></blockquote></blockquote></blockquote> insertions(+), 3<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"> deletions(-)<br><br> diff --git a/modules/services_discovery/microdns.c<br> b/modules/services_discovery/microdns.c index<br> c460126b58..fa34ffa8d8<br> 100644<br> --- a/modules/services_discovery/microdns.c<br> +++ b/modules/services_discovery/microdns.c<br> @@ -28,6 +28,12 @@<br><br>     #include <stdatomic.h><br>     #include <assert.h><br><br> +#if defined( _WIN32 )<br> +<br> +#else<br> +    #include <ifaddrs.h><br> +#endif<br> +<br><br>     #include <vlc_common.h><br>     #include <vlc_plugin.h><br>     #include <vlc_modules.h><br><br> @@ -868,9 +874,59 @@ CloseRD( vlc_object_t *p_this )<br><br>         CleanDiscoveryCommon( p_sys );<br>         }<br><br> -static char * detect_ip_address()<br> +static char * detect_ip_address( vlc_object_t *p_obj )<br><br>     {<br><br> -    return strdup("127.0.0.1"); /* TODO: actually detect ip<br></blockquote></blockquote></blockquote></blockquote></blockquote> address */<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;">+    char result[16] = "127.0.0.1";<br>+    bool found = false;<br>+#if defined( _WIN32 )<br>+<br>+#else<br>+    struct ifaddrs *id;<br>+    if( getifaddrs( &id ) == 0 )<br>+    {<br>+        int selected_priority = 0;<br>+<br>+        for( ; id != NULL; id = id->ifa_next )<br>+        {<br>+            if( id->ifa_addr->sa_family == AF_INET )<br>+            {<br>+                struct sockaddr_in *addr_in = (struct<br>sockaddr_in<br>*)id->ifa_addr; +<br>+                char *ip_address = inet_ntoa(<br>addr_in->sin_addr );<br>+<br>+                /* TODO: smarter priority function. */<br>+                int priority = 0;<br>+                if( strncmp( "eth0", id->ifa_name, strlen(<br>"eth0"<br></blockquote></blockquote></blockquote></blockquote></blockquote> ) )<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;">==<br>0<br>) +                {<br>+                    priority = 1000;<br>+                }<br>+                else if( strncmp( "wifi0", id->ifa_name, <br>strlen(<br>"wifi0"<br>)<br>) == 0 ) +                {<br>+                    priority = 2000;<br>+                }<br>+<br>+                msg_Dbg( p_obj, "Assigned interface %s <br>priority<br></blockquote></blockquote></blockquote></blockquote></blockquote> %d",<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;">+ id->ifa_name, priority);<br>+<br>+                if( priority > selected_priority )<br>+                {<br>+                    strcpy( result, ip_address );<br>+                    selected_priority = priority;<br>+                    found = true;<br>+                }<br>+            }<br>+        }<br>+    }<br>+    else<br>+    {<br>+        msg_Err( p_obj, "Couldn't get interface addresses");<br>+    }<br></blockquote>That could have worked in the nineties. Machines, especially<br>laptops,<br>change IP addresses and have multiple addresses routinely<br>nowadays,<br></blockquote></blockquote></blockquote></blockquote> and<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;">Linux desktops interfaces are not always called eth0 or wifi0.<br></blockquote> I will take Alexandre's suggestion.<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ccc; padding-left: 1ex;">Besides, you need to respond with the correct IP address for <br>the<br>interface<br>on which the request came, usually with <br>IP_PKTINFO/IP6_PKTINFO if<br>you<br>use<br>UDP.<br></blockquote>Respond to what? I don't understand.<br></blockquote>Typically, discovery protocols wait for inbound client requests.<br></blockquote>Oh - so I don't even have to do the detection myself. Great!<br></blockquote> You should never do detection.<br><br> For unsolicited announcements, you should either enumerate all<br> eligible<br> interfaces and spam all of them, or leave the IP stack routing<br> table to<br> pick<br> the correct one at a given time.<br><br> For responses to unicast, you should copy the destination IP of the<br> request as<br> the source IP of the response.<br><br> And for responses to multicast, you should again let the IP stack<br> routing<br> table pick the correct source address for the inbound interface.<br><br> In any case, that can only work with packet info ancillary data.<br> There are<br> no<br> reason to write OS-specific code here.<br></blockquote>In this case we are responding to multicast (works currently as you<br>mentioned above I think) BUT also we are providing a unicast ip<br>address in<br>the A/AAAA record in the response packet.<br>The relationship between the unicast address and the multicast<br>response is<br>that they share the same interface. Right?<br></blockquote>Multicast addresses do not have an interface; you can have the same<br>multicast<br>addresses on different interfaces referring to the same or to<br>different actual<br>group(s). AFAIK, you have to get the correct interface index from the<br>incoming<br>packet ancillary data.<br></blockquote> Ok, thanks for the information.<br><br> libmicrodns scans all interface addresses on initialisation and for<br> each valid one opens a socket.<br><br> Each socket and interface [address (linux) / index (Windows)] are<br> paired so when we get an incoming packet we know what interface it is.<br> Therefore, I don't think we have to deal with packet ancillary data?<br><br> The problem though is getting the unicast address for that interface<br> so we can put it in the response body (A/AAAA record).<br><br> If I'm correct, this needs to be calculated on Windows which will<br> require OS-specific code. Then I will update libmicrodns to pass the<br> IP address string to the callback so VLC can use it to populate the<br> A/AAAA record.<br><br> Does this sound like a valid approach?<br><br> Thanks,<br><br> Roland<br></blockquote><br> Hi,<br><br> I've made the necessary changes to libmicrodns. My pull request is<br> here:<br> <a href="https://github.com/videolabs/libmicrodns/pull/20/commits/fb58b2fffdce80be6381431845fc8e743920e054">https://github.com/videolabs/libmicrodns/pull/20/commits/fb58b2fffdce80be6381431845fc8e743920e054</a> <br><br></blockquote>Hello, I will do the review on libmicrodns.<br></blockquote></blockquote>Thanks Thomas<br>>><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;"> I have one question though. Will it be possible to do the same with <br> avahi (used by default on linux Desktop) and bonjour (used by macOS) ?<br><br></blockquote> On macOS/iOS you would do something like:<br><br>     NSNetService *service = [[NSNetService alloc] <br> initWithDomain:@"local."<br> type:@"_http._tcp."<br> name:@"VLC media player something"<br> port:8080];<br>     [service publish];<br><br> (We probably want to use CFNetServices instead as that is pure C, but <br> it works really similar)<br><br> It seems to work similar for avahi, see<br> <a href="https://www.avahi.org/doxygen/html/publish_8h.html#acb05a7d3d23a3b825ca77cb1c7d00ce4">https://www.avahi.org/doxygen/html/publish_8h.html#acb05a7d3d23a3b825ca77cb1c7d00ce4</a> <br><br> When passing NULL for host, the daemon will use the local host name, <br> just like what<br> happens in the above snippet for macOS/iOS.<br><br> So we do not have to worry about which exact addresses to announce at <br> all there.<br></blockquote><br><br>libmicrodns is our cross-platform solution for mDNS discovery / <br>advertisement. Why do we need to write specific code for Avahi / Bonjour <br>implementations?<br><br>I've tested service discovery on Linux and Windows and it works. I have <br>no access to macOS.<br><br><br>><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;"><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;"> Please have a look and let me know if it's a viable solution.<br><br> Thanks,<br><br> Roland<hr> vlc-devel mailing list<br> To unsubscribe or modify your subscription options:<br> <a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></blockquote><hr>vlc-devel mailing list<br>To unsubscribe or modify your subscription options:<br><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a></pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>