本文整理汇总了Golang中dns.Msg.Recursion_desired方法的典型用法代码示例。如果您正苦于以下问题:Golang Msg.Recursion_desired方法的具体用法?Golang Msg.Recursion_desired怎么用?Golang Msg.Recursion_desired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dns.Msg
的用法示例。
在下文中一共展示了Msg.Recursion_desired方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: respondWithFallback
func respondWithFallback(raw []uint8, clientMsg *dns.Msg, clientQuestion dns.Question, proxy *net.UDPAddr) {
LOG.Println("fallback:", clientQuestion, proxy)
conn, err := net.Dial("udp", proxy.String())
if err != nil {
LOG.Fatalln(err)
}
conn.Write(raw)
buffer := make([]byte, 1<<15)
size, err := conn.Read(buffer)
if err != nil {
LOG.Fatalln(err, proxy)
}
msg := &dns.Msg{}
msg.Unpack(buffer[0:size])
LOG.Println(msg)
for _, answer := range msg.Answer {
clientMsg.Answer = append(clientMsg.Answer, answer)
}
clientMsg.Rcode = msg.Rcode
clientMsg.Response = msg.Response
clientMsg.Authoritative = msg.Authoritative
clientMsg.Recursion_desired = msg.Recursion_desired
clientMsg.Recursion_available = msg.Recursion_available
}
示例2: answerAAAA
func answerAAAA(msg *dns.Msg, question dns.Question, name []string, value NMCValue) {
var parsedIp net.IP
// len == 1 means root domain: check "ip" and "map".""
if len(name) == 1 {
vips := value.Ip6
if len(vips) == 0 {
// can't answer, make an error here.
return
} else {
parsedIp = net.ParseIP(vips[0])
}
}
ip := parsedIp.To16()
if ip == nil {
return
}
LOG.Println("AAAA", name, "=>", ip)
rraaaa := &dns.RR_AAAA{}
copy(ip, rraaaa.AAAA[:])
rrh := &dns.RR_Header{
Name: question.Name,
Rrtype: dns.TypeAAAA,
Class: dns.ClassINET,
Ttl: 60,
Rdlength: 100,
}
rraaaa.Hdr = *rrh
msg.Rcode = dns.RcodeSuccess
msg.Answer = append(msg.Answer, rraaaa)
msg.Response = true
msg.Authoritative = true
msg.Recursion_desired = true
msg.Recursion_available = true
}
示例3: answerA
func answerA(msg *dns.Msg, question dns.Question, name []string, value NMCValue) {
var parsedIp net.IP
// len == 1 means root domain: check "ip" and "map".""
if len(name) == 1 {
vips := value.Ip
// this is legacy support
if len(vips) == 0 {
vmap := value.Map
if vmap == nil {
return
}
vmip, ok := value.Map[""]
if !ok && vmip == "" {
// can't answer, make an error here.
return
}
switch vmip.(type) {
case nil:
return
case map[string]interface{}:
nsAvailable := vmip.(map[string]interface{})["ns"]
switch nsAvailable.(type) {
case []interface{}:
ns := nsAvailable.([]interface{})[0]
switch ns.(type) {
case string:
h := dns.MsgHdr{
Id: uint16(rand.Int()) ^ uint16(time.Nanoseconds()),
Recursion_desired: true,
}
q := &dns.Question{
Name: question.Name,
Qtype: dns.TypeA,
Qclass: dns.ClassINET,
}
m := &dns.Msg{}
m.MsgHdr = h
m.Question = append(m.Question, *q)
LOG.Println(m)
out, ok := m.Pack()
if !ok {
LOG.Fatalln("Failed to Pack:", msg)
}
nsaddr := ns.(string) + ":53"
conn, err := net.Dial("udp", nsaddr)
if err != nil {
LOG.Fatalf("net.DialUDP(\"udp\", nil, %v) => %v", nsaddr, err)
}
LOG.Println("out:", out)
n, err := conn.Write(out)
if err != nil {
LOG.Fatalln(err)
}
LOG.Println("wrote:", n)
conn.SetReadTimeout(10e9)
defer conn.Close()
b := make([]byte, 1<<15)
s, err := conn.Read(b)
if err != nil {
LOG.Fatalln(err, nsaddr)
}
err = conn.Close()
if err != nil {
LOG.Fatalln(err)
}
a := &dns.Msg{}
a.Unpack(b[0:s])
LOG.Println("a:", a)
msg.Answer = append(msg.Answer, a.Answer[0])
return
default:
LOG.Printf("can't find the type of: %#v", ns)
}
default:
LOG.Printf("can't find the type of: %#v", nsAvailable)
}
case string:
parsedIp = net.ParseIP(vmip.(string))
default:
LOG.Printf("can't find the type of: %#v", vmip)
}
} else {
//.........这里部分代码省略.........