richardschneider / net-mdns

Simple multicast DNS
MIT License
232 stars 81 forks source link

No query received after enabling a networkinterface #110

Closed yoyos closed 2 years ago

yoyos commented 2 years ago

With the simple example below, I have produced a problem where no query is received when a network interface is enabled after the multicastservice has been started.

How would you update the MulticastService using NetworkInterfaceDiscovered so it receives queries again after enabling a new networkinterface ?

Thanks !

using Makaretu.Dns;

var service = "...";
var mdns = new MulticastService();
mdns.QueryReceived += (s, e) =>
{
    var msg = e.Message;
    if (msg.Questions.Any(q => q.Name == service))
    {
        var res = msg.CreateResponse();
        var addresses = MulticastService.GetIPAddresses()
            .Where(ip => ip.AddressFamily == AddressFamily.InterNetwork);
        foreach (var address in addresses)
        {
            res.Answers.Add(new ARecord
            {
                Name = service,
                Address = address
            });
        }
        mdns.SendAnswer(res);
    }
};
mdns.Start();
yoyos commented 2 years ago

I fixed it here https://github.com/queequac/net-mdns/pull/2/commits/07e0f0a59e3af5f2decc40919051dad3d00830f9