1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-25 00:45:24 +00:00

check domain name

This commit is contained in:
Darien Raymond 2019-02-06 21:02:03 +01:00
parent fae47083c2
commit 2aa0c08709
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 11 additions and 3 deletions

View File

@ -196,6 +196,14 @@ func toNetIP(ips []net.Address) []net.IP {
}
func (s *Server) lookupIPInternal(domain string, option IPOption) ([]net.IP, error) {
if len(domain) == 0 {
return nil, newError("empty domain name")
}
if domain[len(domain)-1] == '.' {
domain = domain[:len(domain)-1]
}
ips := s.lookupStatic(domain, option, 0)
if ips != nil && ips[0].Family().IsIP() {
return toNetIP(ips), nil

View File

@ -216,18 +216,18 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,
RCode: dnsmessage.RCodeSuccess,
Response: true,
})
builder.StartAnswers()
common.Must(builder.StartAnswers())
rHeader := dnsmessage.ResourceHeader{Name: dnsmessage.MustNewName(domain), Class: dnsmessage.ClassINET, TTL: 600}
for _, ip := range ips {
if len(ip) == net.IPv4len {
var r dnsmessage.AResource
copy(r.A[:], ip)
builder.AResource(rHeader, r)
common.Must(builder.AResource(rHeader, r))
} else {
var r dnsmessage.AAAAResource
copy(r.AAAA[:], ip)
builder.AAAAResource(rHeader, r)
common.Must(builder.AAAAResource(rHeader, r))
}
}
msgBytes, err := builder.Finish()