Skip to content

Commit 1f4c467

Browse files
committed
Respond to multicast address for multicast queries
Without this fix the standard linux avahi-daemon won't accept the responses from this library. Signed-off-by: Miguel Angel Ajo <majopela@redhat.com>
1 parent f504e0b commit 1f4c467

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

server.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,24 @@ func (s *Server) handleQuestion(q dns.Question) (multicastRecs, unicastRecs []dn
269269

270270
// sendResponse is used to send a response packet
271271
func (s *Server) sendResponse(resp *dns.Msg, from net.Addr, unicast bool) error {
272-
// TODO(reddaly): Respect the unicast argument, and allow sending responses
273-
// over multicast.
274272
buf, err := resp.Pack()
275273
if err != nil {
276274
return err
277275
}
278276

279277
// Determine the socket to send from
280278
addr := from.(*net.UDPAddr)
279+
281280
if addr.IP.To4() != nil {
281+
if !unicast {
282+
addr.IP = net.ParseIP(ipv4mdns)
283+
}
282284
_, err = s.ipv4List.WriteToUDP(buf, addr)
283285
return err
284286
} else {
287+
if !unicast {
288+
addr.IP = net.ParseIP(ipv6mdns)
289+
}
285290
_, err = s.ipv6List.WriteToUDP(buf, addr)
286291
return err
287292
}

0 commit comments

Comments
 (0)