-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace multiple "resolver.*" fn cals with single "dns.Exchange()" fn.
This highly simplify resolving DNS code. Also, DNS will work only for IPv4 Signed-off-by: Yevhen Vydolob <[email protected]> Co-authored-by: Christophe Fergeau <[email protected]>
- Loading branch information
Showing
5 changed files
with
241 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//go:build !windows | ||
|
||
package dns | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/miekg/dns" | ||
) | ||
|
||
func GetDNSHostAndPort() (string, string, error) { | ||
conf, err := dns.ClientConfigFromFile("/etc/resolv.conf") | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
return "", "", err | ||
} | ||
// TODO: use all configured nameservers, instead just first one | ||
nameserver := conf.Servers[0] | ||
|
||
return nameserver, conf.Port, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//go:build windows | ||
|
||
package dns | ||
|
||
import ( | ||
"net/netip" | ||
"strconv" | ||
|
||
qdmDns "github.com/qdm12/dns/v2/pkg/nameserver" | ||
) | ||
|
||
func GetDNSHostAndPort() (string, string, error) { | ||
nameservers := qdmDns.GetDNSServers() | ||
|
||
var nameserver netip.AddrPort | ||
for _, n := range nameservers { | ||
// return first non ipv6 nameserver | ||
if n.Addr().Is4() { | ||
nameserver = n | ||
break | ||
} | ||
} | ||
|
||
return nameserver.Addr().String(), strconv.Itoa(int(nameserver.Port())), nil | ||
|
||
} |
Oops, something went wrong.