1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-15 16:38:16 -04:00
v2fly/app/dns/nameserver_local.go

44 lines
1.1 KiB
Go
Raw Normal View History

// +build !confonly
package dns
import (
"context"
2021-02-16 15:31:50 -05:00
"github.com/v2fly/v2ray-core/v4/common/net"
"github.com/v2fly/v2ray-core/v4/features/dns"
2021-02-16 15:31:50 -05:00
"github.com/v2fly/v2ray-core/v4/features/dns/localdns"
)
// LocalNameServer is an wrapper over local DNS feature.
type LocalNameServer struct {
client *localdns.Client
}
// QueryIP implements Server.
func (s *LocalNameServer) QueryIP(_ context.Context, domain string, _ net.IP, option dns.IPOption, _ bool) ([]net.IP, error) {
if option.IPv4Enable || option.IPv6Enable {
return s.client.LookupIP(domain, option)
}
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()}
}