Merge pull request #11 from nikosk686/bugfix-ipv4-or-6-unavailability

Fixes new client or server creation failure when one of ipv4 or ipv6 is unavailable
This commit is contained in:
Asim Aslam 2019-05-23 08:37:24 +01:00 committed by GitHub
commit 32c17f6b3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 7 deletions

View File

@ -191,6 +191,13 @@ func newClient() (*client, error) {
return nil, fmt.Errorf("failed to bind to any unicast udp port")
}
if uconn4 == nil {
uconn4 = &net.UDPConn{}
}
if uconn6 == nil {
uconn6 = &net.UDPConn{}
}
mconn4, err := net.ListenUDP("udp4", mdnsWildcardAddrIPv4)
if err != nil {
log.Printf("[ERR] mdns: Failed to bind to udp4 port: %v", err)
@ -204,6 +211,13 @@ func newClient() (*client, error) {
return nil, fmt.Errorf("failed to bind to any multicast udp port")
}
if mconn4 == nil {
mconn4 = &net.UDPConn{}
}
if mconn6 == nil {
mconn6 = &net.UDPConn{}
}
p1 := ipv4.NewPacketConn(mconn4)
p2 := ipv6.NewPacketConn(mconn6)

View File

@ -73,6 +73,13 @@ func NewServer(config *Config) (*Server, error) {
return nil, fmt.Errorf("[ERR] mdns: Failed to bind to any udp port!")
}
if ipv4List == nil {
ipv4List = &net.UDPConn{}
}
if ipv6List == nil {
ipv6List = &net.UDPConn{}
}
// Join multicast groups to receive announcements
p1 := ipv4.NewPacketConn(ipv4List)
p2 := ipv6.NewPacketConn(ipv6List)
@ -112,13 +119,8 @@ func NewServer(config *Config) (*Server, error) {
shutdownCh: make(chan struct{}),
}
if ipv4List != nil {
go s.recv(s.ipv4List)
}
if ipv6List != nil {
go s.recv(s.ipv6List)
}
s.wg.Add(1)
go s.probe()