@@ -58,6 +58,12 @@ var ipv4Addr = &net.UDPAddr{
58
58
Port : 5353 ,
59
59
}
60
60
61
+ // IP address used to check if IPv6 is supported by the local network
62
+ var ipv6Addr = & net.UDPAddr {
63
+ IP : net .ParseIP ("ff02::fb" ),
64
+ Port : 5353 ,
65
+ }
66
+
61
67
// MDNSDiscovery is the implementation of the network pluggable-discovery
62
68
type MDNSDiscovery struct {
63
69
cancelFunc func ()
@@ -127,27 +133,38 @@ func (d *MDNSDiscovery) StartSync(eventCB discovery.EventCallback, errorCB disco
127
133
// neither we have to any to do it, we can only wait for it
128
134
// to return.
129
135
queriesChan := make (chan * mdns.ServiceEntry )
130
- params := & mdns.QueryParam {
131
- Service : mdnsServiceName ,
132
- Domain : "local" ,
133
- Timeout : discoveryInterval ,
134
- Entries : queriesChan ,
135
- WantUnicastResponse : false ,
136
- DisableIPv6 : true ,
137
- }
138
136
139
137
ctx , cancel := context .WithCancel (context .Background ())
140
138
go func () {
141
139
defer close (queriesChan )
140
+
141
+ disableIPv6 := false
142
+ // Check if the current network supports IPv6
143
+ mconn6 , err := net .ListenMulticastUDP ("udp6" , nil , ipv6Addr )
144
+ if err != nil {
145
+ disableIPv6 = true
146
+ } else {
147
+ mconn6 .Close ()
148
+ }
149
+
142
150
// We must check if we're connected to a local network, if we don't
143
151
// the subsequent mDNS query would fail and return an error.
144
- if mconn4 , err := net .ListenMulticastUDP ("udp4" , nil , ipv4Addr ); err != nil {
152
+ mconn4 , err := net .ListenMulticastUDP ("udp4" , nil , ipv4Addr )
153
+ if err != nil {
145
154
return
146
- } else {
147
- // If we managed to open a connection close it, mdns.Query opens
148
- // another one on the same IP address we use and it would fail
149
- // if we leave this open.
150
- mconn4 .Close ()
155
+ }
156
+ // If we managed to open a connection close it, mdns.Query opens
157
+ // another one on the same IP address we use and it would fail
158
+ // if we leave this open.
159
+ mconn4 .Close ()
160
+
161
+ params := & mdns.QueryParam {
162
+ Service : mdnsServiceName ,
163
+ Domain : "local" ,
164
+ Timeout : discoveryInterval ,
165
+ Entries : queriesChan ,
166
+ WantUnicastResponse : false ,
167
+ DisableIPv6 : disableIPv6 ,
151
168
}
152
169
for {
153
170
if err := mdns .Query (params ); err != nil {
0 commit comments