Skip to content

Instantly share code, notes, and snippets.

@prologic
Created April 1, 2022 14:46
Show Gist options
  • Save prologic/2c3135df794129e13633230f294b8e09 to your computer and use it in GitHub Desktop.
Save prologic/2c3135df794129e13633230f294b8e09 to your computer and use it in GitHub Desktop.
Test program to test Go'a netdns=cgo resolver on macOS
package main
import (
"fmt"
"log"
"net"
)
func main() {
cnames, addrs, err := net.LookupSRV("_salty", "_tcp", "home.arpa")
if err != nil {
log.Fatal(err)
}
fmt.Printf("cnames: %s\n", cnames)
fmt.Printf("addrs: #%v\n", addrs)
}
@prologic
Copy link
Author

prologic commented Apr 1, 2022

Build with:

$ CGO_ENABLED=1 go build .

Run with:

$ GODEBUG=netdns=cgo+1 ./test-netdns
go package net: using cgo DNS resolver
2022/04/02 00:47:02 lookup __salty.__tcp.home.arpa on 10.0.0.10:53: no such host

Note this is using my Mac's DNS server in /etc/resolv.confand not the Resolver in/etc/resolver/home.arpa`:

$ cat /etc/resolver/home.arpa
nameserver 127.0.0.1
port 5300

Expected output (using dig):

$ dig @127.0.0.1 -p 5300 srv _salty._tcp.home.arpa +short
0 0 443 salty.home.arpa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment