Add IP binding suppression if at least one listener is registered

This commit is contained in:
richtr 2014-09-08 15:11:55 +02:00
parent 70462deb06
commit 095233e3dc

View File

@ -52,14 +52,8 @@ type Server struct {
// NewServer is used to create a new mDNS server from a config // NewServer is used to create a new mDNS server from a config
func NewServer(config *Config) (*Server, error) { func NewServer(config *Config) (*Server, error) {
// Create the listeners // Create the listeners
ipv4List, err := net.ListenMulticastUDP("udp4", config.Iface, ipv4Addr) ipv4List, _ := net.ListenMulticastUDP("udp4", config.Iface, ipv4Addr)
if err != nil { ipv6List, _ := net.ListenMulticastUDP("udp6", config.Iface, ipv6Addr)
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)
}
// Check if we have any listener // Check if we have any listener
if ipv4List == nil && ipv6List == nil { if ipv4List == nil && ipv6List == nil {
@ -72,8 +66,15 @@ func NewServer(config *Config) (*Server, error) {
ipv6List: ipv6List, ipv6List: ipv6List,
shutdownCh: make(chan struct{}), shutdownCh: make(chan struct{}),
} }
if ipv4List != nil {
go s.recv(s.ipv4List) go s.recv(s.ipv4List)
}
if ipv6List != nil {
go s.recv(s.ipv6List) go s.recv(s.ipv6List)
}
return s, nil return s, nil
} }