<div><div><br></div><div><br><div class="gmail_quote"></div></div></div><div><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 26 Jul 2019 at 12:15 AM, Rémi Denis-Courmont <<a href="mailto:remi@remlab.net" target="_blank">remi@remlab.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Le torstaina 25. heinäkuuta 2019, 8.39.11 EEST Roland Bewick a écrit :<br>
> On 24/07/2019 11:18 PM, Rémi Denis-Courmont wrote:<br>
> > Le keskiviikkona 24. heinäkuuta 2019, 19.10.50 EEST Roland Bewick a écrit <br>
:<br>
> >> Hi Rémi,<br>
> >> <br>
> >> Thanks for the reply.<br>
> >> <br>
> >> On 24/07/2019 10:59 PM, Rémi Denis-Courmont wrote:<br>
> >>> Le keskiviikkona 24. heinäkuuta 2019, 18.43.49 EEST Roland Bewick a<br>
> >>> écrit<br>
> >>> <br>
> >>>> ---<br>
> >>>> <br>
> >>>>    modules/services_discovery/microdns.c | 62<br>
> >>>> <br>
> >>>> +++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3<br>
> >>>> deletions(-)<br>
> >>>> <br>
> >>>> diff --git a/modules/services_discovery/microdns.c<br>
> >>>> b/modules/services_discovery/microdns.c index 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>
> >>>> <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 address */<br>
> >>>> +    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 sockaddr_in<br>
> >>>> *)id->ifa_addr; +<br>
> >>>> +                char *ip_address = inet_ntoa( addr_in->sin_addr );<br>
> >>>> +<br>
> >>>> +                /* TODO: smarter priority function. */<br>
> >>>> +                int priority = 0;<br>
> >>>> +                if( strncmp( "eth0", id->ifa_name, strlen( "eth0" ) )<br>
> >>>> ==<br>
> >>>> 0<br>
> >>>> ) +                {<br>
> >>>> +                    priority = 1000;<br>
> >>>> +                }<br>
> >>>> +                else if( strncmp( "wifi0", id->ifa_name, strlen(<br>
> >>>> "wifi0"<br>
> >>>> )<br>
> >>>> ) == 0 ) +                {<br>
> >>>> +                    priority = 2000;<br>
> >>>> +                }<br>
> >>>> +<br>
> >>>> +                msg_Dbg( p_obj, "Assigned interface %s priority %d",<br>
> >>>> +                         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>
> >>> <br>
> >>> That could have worked in the nineties. Machines, especially laptops,<br>
> >>> change IP addresses and have multiple addresses routinely nowadays, and<br>
> >>> Linux desktops interfaces are not always called eth0 or wifi0.<br>
> >> <br>
> >> I will take Alexandre's suggestion.<br>
> >> <br>
> >>> Besides, you need to respond with the correct IP address for the<br>
> >>> interface<br>
> >>> on which the request came, usually with IP_PKTINFO/IP6_PKTINFO if you<br>
> >>> use<br>
> >>> UDP.<br>
> >> <br>
> >> Respond to what? I don't understand.<br>
> > <br>
> > Typically, discovery protocols wait for inbound client requests.<br>
> <br>
> Oh - so I don't even have to do the detection myself. Great!<br>
<br>
You should never do detection.<br>
<br>
For unsolicited announcements, you should either enumerate all eligible <br>
interfaces and spam all of them, or leave the IP stack routing table to pick <br>
the correct one at a given time.<br>
<br>
For responses to unicast, you should copy the destination IP of the request as <br>
the source IP of the response.<br>
<br>
And for responses to multicast, you should again let the IP stack 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. There are no <br>
reason to write OS-specific code here.<br>
</blockquote><div dir="auto"><br></div></div></div></div><div><div><div class="gmail_quote"><div dir="auto">In this case we are responding to multicast (works currently as you mentioned above I think) BUT also we are providing a unicast ip address in the A/AAAA record in the response packet.</div><div dir="auto"><br></div><div dir="auto">The relationship between the unicast address and the multicast response is that they share the same interface. Right?</div><div dir="auto"><br></div><div dir="auto">To get the unicast IP address from the interface we’re responding on, I can’t see any other way than using custom code on Windows.</div><div dir="auto"><br></div><div dir="auto">Sorry, could you please correct my understanding on this?</div><div dir="auto"><br></div><div dir="auto">Thanks,</div><div dir="auto"><br></div><div dir="auto">Roland</div></div></div></div><div><div><div class="gmail_quote"><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
-- <br>
Реми Дёни-Курмон<br>
<a href="http://www.remlab.net/" rel="noreferrer" target="_blank">http://www.remlab.net/</a><br>
<br>
<br>
<br>
_______________________________________________<br>
vlc-devel mailing list<br>
To unsubscribe or modify your subscription options:<br>
<a href="https://mailman.videolan.org/listinfo/vlc-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/vlc-devel</a></blockquote></div></div>
</div>