本文整理汇总了Golang中github.com/miekg/dns.A.AAAA方法的典型用法代码示例。如果您正苦于以下问题:Golang A.AAAA方法的具体用法?Golang A.AAAA怎么用?Golang A.AAAA使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/miekg/dns.A
的用法示例。
在下文中一共展示了A.AAAA方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AddressRecords
func (s *server) AddressRecords(q dns.Question, name string) (records []dns.RR, err error) {
results, err := s.hosts.FindHosts(name)
if err != nil {
return nil, err
}
for _, ip := range results {
switch {
case ip.To4() != nil && (q.Qtype == dns.TypeA || q.Qtype == dns.TypeANY):
r := new(dns.A)
r.Hdr = dns.RR_Header{Name: q.Name, Rrtype: dns.TypeA,
Class: dns.ClassINET, Ttl: s.config.HostsTtl}
r.A = ip.To4()
records = append(records, r)
case ip.To4() == nil && (q.Qtype == dns.TypeAAAA || q.Qtype == dns.TypeANY):
r := new(dns.AAAA)
r.Hdr = dns.RR_Header{Name: q.Name, Rrtype: dns.TypeAAAA,
Class: dns.ClassINET, Ttl: s.config.HostsTtl}
r.AAAA = ip.To16()
records = append(records, r)
}
}
return records, nil
}
示例2: handleDnsRequest
func handleDnsRequest(w dns.ResponseWriter, req *dns.Msg) {
r := new(dns.Msg)
r.SetReply(req)
r.Authoritative = true
if len(req.Question) > 1 || req.Rcode != dns.OpcodeQuery {
r.SetRcode(req, dns.RcodeNotImplemented)
}
if len(req.Question) == 0 {
r.SetRcode(req, dns.RcodeFormatError)
}
if r.Rcode != dns.RcodeSuccess {
w.WriteMsg(r)
dnsReportChan <- 1
return
}
q := req.Question[0]
log.Debug("dns server: question=%v type=%v remote_host=%v", q.Name, q.Qtype, w.RemoteAddr())
switch q.Qtype {
case dns.TypeA:
h, _ := randomHost()
if h == "" || !isIPv4(h) {
if *f_randomhosts {
h = randomIPv4Addr()
} else {
// return NXDOMAIN
r.SetRcode(req, dns.RcodeNameError)
break
}
}
resp := new(dns.A)
resp.Hdr = dns.RR_Header{
Name: q.Name,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: ttl,
}
resp.A = net.ParseIP(h)
r.Answer = append(r.Answer, resp)
case dns.TypeAAAA:
h, _ := randomHost()
if h == "" || !isIPv6(h) {
if *f_randomhosts {
h = randomIPv6Addr()
} else {
// return NXDOMAIN
r.SetRcode(req, dns.RcodeNameError)
break
}
}
resp := new(dns.AAAA)
resp.Hdr = dns.RR_Header{
Name: q.Name,
Rrtype: dns.TypeAAAA,
Class: dns.ClassINET,
Ttl: ttl,
}
resp.AAAA = net.ParseIP(h)
r.Answer = append(r.Answer, resp)
case dns.TypeCNAME:
resp := new(dns.CNAME)
resp.Hdr = dns.RR_Header{
Name: q.Name,
Rrtype: dns.TypeCNAME,
Class: dns.ClassINET,
Ttl: ttl,
}
resp.Target = fmt.Sprintf("cname.%s", q.Name)
r.Answer = append(r.Answer, resp)
case dns.TypeMX:
resp := new(dns.MX)
resp.Hdr = dns.RR_Header{
Name: q.Name,
Rrtype: dns.TypeMX,
Class: dns.ClassINET,
Ttl: ttl,
}
resp.Mx = fmt.Sprintf("mx.%s", q.Name)
r.Answer = append(r.Answer, resp)
case dns.TypeSOA:
resp := new(dns.SOA)
resp.Hdr = dns.RR_Header{
Name: q.Name,
Rrtype: dns.TypeSOA,
Class: dns.ClassINET,
Ttl: ttl,
}
resp.Ns = fmt.Sprintf("ns.%s", q.Name)
resp.Mbox = fmt.Sprintf("admin-%s", q.Name)
r.Answer = append(r.Answer, resp)
}
w.WriteMsg(r)
dnsReportChan <- 1
}