Get darwin local DNS server from libresolv

This commit is contained in:
世界
2025-02-20 16:40:53 +08:00
parent c1189e2a7b
commit 5c4211e849
7 changed files with 90 additions and 27 deletions

View File

@@ -0,0 +1,23 @@
package local
import (
"os"
"strings"
_ "unsafe"
"github.com/miekg/dns"
)
//go:linkname defaultNS net.defaultNS
var defaultNS []string
func dnsDefaultSearch() []string {
hn, err := os.Hostname()
if err != nil {
return nil
}
if i := strings.IndexRune(hn, '.'); i >= 0 && i < len(hn)-1 {
return []string{dns.Fqdn(hn[i+1:])}
}
return nil
}