Closed markcryptohash closed 2 years ago
The register
example does not register a hostname. It uses the local hostname instead. That's why resolving the hostname test.local
doesn't work.
Oh ok... any example code I could use to register a hostname? I have an application I'd like to announce to the world its IP address, with name resolution via mDNS.
I figured it out! cfg := dnssd.Config{ Name: instanceFlag, Type: serviceFlag, Domain: domainFlag, Port: portFlag, Ifaces: ifaces, IPs: []net.IP{net.ParseIP("127.0.0.1")}, Host: "test", //added this line... }
I'm using the example code here and trying to register a Record: https://github.com/brutella/dnssd/tree/v1.2.4/cmd/register
I've adjusted: cfg := dnssd.Config{ Name: instanceFlag, Type: serviceFlag, Domain: domainFlag, Port: portFlag, Ifaces: ifaces, IPs: []net.IP{net.ParseIP("127.0.0.1")}, //hardcoded just for a test (although docs say this is deprecated) }
Trying to get a test.local to resolve to 127.0.0.1 (or whatever IP I like).
$ dns-sd -B. --> this does detect the Service Timestamp A/R Flags if Domain Service Type Instance Name 13:30:38.961 Add 3 6 local. _http._tcp. test
$ dns-sd -G v4 test.local --> this does not show any entries. Where as other mDNS devices on my network pop up such as Octopi.local and my printer.
$ ping test.local ping: cannot resolve test.local: Unknown host
When I try this with the dns-sd -P "test" _http._tcp local 8888 test.local 127.0.0.1. --> this works and I see the A record when I packet sniff and also name resolution works.
Just curious what I am doing wrong, or need example code to make it happen :) Thanks!