From 095233e3dc22d0adb5bb80801775ea64c3879f5c Mon Sep 17 00:00:00 2001 From: richtr Date: Mon, 8 Sep 2014 15:11:55 +0200 Subject: [PATCH] Add IP binding suppression if at least one listener is registered --- server.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/server.go b/server.go index d426659..6f439b9 100644 --- a/server.go +++ b/server.go @@ -52,14 +52,8 @@ type Server struct { // NewServer is used to create a new mDNS server from a config func NewServer(config *Config) (*Server, error) { // Create the listeners - ipv4List, err := net.ListenMulticastUDP("udp4", config.Iface, ipv4Addr) - if err != nil { - log.Printf("[ERR] mdns: Failed to start IPv4 listener: %v", err) - } - ipv6List, err := net.ListenMulticastUDP("udp6", config.Iface, ipv6Addr) - if err != nil { - log.Printf("[ERR] mdns: Failed to start IPv6 listener: %v", err) - } + ipv4List, _ := net.ListenMulticastUDP("udp4", config.Iface, ipv4Addr) + ipv6List, _ := net.ListenMulticastUDP("udp6", config.Iface, ipv6Addr) // Check if we have any listener if ipv4List == nil && ipv6List == nil { @@ -72,8 +66,15 @@ func NewServer(config *Config) (*Server, error) { ipv6List: ipv6List, shutdownCh: make(chan struct{}), } - go s.recv(s.ipv4List) - go s.recv(s.ipv6List) + + if ipv4List != nil { + go s.recv(s.ipv4List) + } + + if ipv6List != nil { + go s.recv(s.ipv6List) + } + return s, nil }