mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-17 09:56:18 -05:00
d8c03f10b5
Co-authored-by: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
// +build !confonly
|
|
|
|
package dns
|
|
|
|
import (
|
|
"context"
|
|
|
|
"v2ray.com/core/common/net"
|
|
"v2ray.com/core/features/dns/localdns"
|
|
)
|
|
|
|
// LocalNameServer is an wrapper over local DNS feature.
|
|
type LocalNameServer struct {
|
|
client *localdns.Client
|
|
}
|
|
|
|
// QueryIP implements Server.
|
|
func (s *LocalNameServer) QueryIP(ctx context.Context, domain string, clientIP net.IP, option IPOption) ([]net.IP, error) {
|
|
if option.IPv4Enable && option.IPv6Enable {
|
|
return s.client.LookupIP(domain)
|
|
}
|
|
|
|
if option.IPv4Enable {
|
|
return s.client.LookupIPv4(domain)
|
|
}
|
|
|
|
if option.IPv6Enable {
|
|
return s.client.LookupIPv6(domain)
|
|
}
|
|
|
|
return nil, newError("neither IPv4 nor IPv6 is enabled")
|
|
}
|
|
|
|
// Name implements Server.
|
|
func (s *LocalNameServer) Name() string {
|
|
return "localhost"
|
|
}
|
|
|
|
// NewLocalNameServer creates localdns server object for directly lookup in system DNS.
|
|
func NewLocalNameServer() *LocalNameServer {
|
|
newError("DNS: created localhost client").AtInfo().WriteToLog()
|
|
return &LocalNameServer{
|
|
client: localdns.New(),
|
|
}
|
|
}
|
|
|
|
// NewLocalDNSClient creates localdns client object for directly lookup in system DNS.
|
|
func NewLocalDNSClient() *Client {
|
|
return &Client{server: NewLocalNameServer()}
|
|
}
|