Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service based query fails over and returns random mDNS responses #96

Open
JAlexoid opened this issue Mar 1, 2023 · 1 comment
Open

Comments

@JAlexoid
Copy link

JAlexoid commented Mar 1, 2023

The mdns.Lookup returns random results, when target service type is not found.

This is an undocumented and random response, which makes this library useless for service lookup.

github.com/hashicorp/mdns v1.0.5


import (
	"fmt"
	"io/ioutil"
	"net"
	"os"
	"time"

	"github.com/hashicorp/mdns"
)

func main() {

	// Make a channel for results and start listening
	entriesCh := make(chan *mdns.ServiceEntry, 4)
	go func() {
		for entry := range entriesCh {
			fmt.Printf("Got new entry: %v\n", entry)
		}
	}()
	// Start the lookup
	mdns.Lookup("_pcm._tcp", entriesCh)
	close(entriesCh)
}
Got new entry: &{PCM-Sink._pcm._tcp.local. mdns-C78.local. 192.168.1.66 <nil> 3333 path=/foobar|board=esp32 [path=/foobar board=esp32] 192.168.1.66 true true}
2023/03/01 11:52:10 [INFO] mdns: Closing client {true true 0xc000128038 0xc000128040 0xc000128048 0xc000128050 1 0xc00010e120}
alex@ubuntu:~/eclipse-workspace/mdns$ ./mdns 
Got new entry: &{PCM-Sink._pcm._tcp.local. mdns-C78.local. 192.168.1.66 <nil> 3333 path=/foobar|board=esp32 [path=/foobar board=esp32] 192.168.1.66 true true}
2023/03/01 11:52:13 [INFO] mdns: Closing client {true true 0xc000014048 0xc000014050 0xc000014058 0xc000014060 1 0xc00001c1e0}
alex@ubuntu:~/eclipse-workspace/mdns$ ./mdns 
2023/03/01 11:52:25 [INFO] mdns: Closing client {true true 0xc000014048 0xc000014050 0xc000014058 0xc000014060 1 0xc00001c1e0}
alex@ubuntu:~/eclipse-workspace/mdns$ ./mdns 
Got new entry: &{mac-address-id._googlezone._tcp.local. mac-address-id.local. 192.168.1.42 ***}
Got new entry: &{mac-address-id._agentdvr._tcp.local. mac-address-id.agentdvr.local. 192.168.1.221 ***}
Got new entry: &{Chromecast-Ultra._googlecast._tcp.local. mac-address-id.local. 192.168.1.42 ***}
Got new entry: &{spotify._spotify-connect._tcp.local. 521797894248-0.local. 192.168.1.15 ***}
Got new entry: &{mac-address-id._googlezone._tcp.local. mac-address-id.local. 192.168.1.27 ***}
Got new entry: &{mac-address-id._googlezone._tcp.local. mac-address-id.local. 192.168.1.25 ***}
Got new entry: &{OctoPrint\ instance\ on\ octoprint._octoprint._tcp.local. octoprint.local. 192.168.1.53 ***}
Got new entry: &{mac._googlezone._tcp.local. mac.local. 192.168.1.26 ***}
Got new entry: &{mac._googlezone._tcp.local. mac.local. 192.168.1.28 ***}
Got new entry: &{iPhone._rdlink._tcp.local. iPhone.local. 192.168.1.55 ***}
Got new entry: &{Family\ Room\ TV._viziocast._tcp.local. CastTV.local. 192.168.1.103 ***}
Got new entry: &{xxx::windows11._oculusal_sp._tcp.local. windows11.local. 192.168.1.221 ***}
2023/03/01 11:52:27 [INFO] mdns: Closing client {true true 0xc000014048 0xc000014050 0xc000014058 0xc000014060 1 0xc00001c1e0}
@zonque
Copy link

zonque commented Mar 31, 2023

I experienced the same, and the reason is quite obvious: the client makes a listener subscription to the multicast group, then sends out a query and reports all answers on that group without checking that the answers match the query. As other hosts may also send queries, and service providers also send unsolicited announcements (when their services start, for instance), the client library ends up reporting everything that happens to arrive at the time of listening.

I consider that a bug.

@JAlexoid JAlexoid changed the title Service based query fails over and returns ransom DNS responses Service based query fails over and returns random DNS responses Mar 31, 2023
@JAlexoid JAlexoid changed the title Service based query fails over and returns random DNS responses Service based query fails over and returns random mDNS responses Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants