本文整理汇总了Golang中github.com/miekg/dns.Msg.Opcode方法的典型用法代码示例。如果您正苦于以下问题:Golang Msg.Opcode方法的具体用法?Golang Msg.Opcode怎么用?Golang Msg.Opcode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/miekg/dns.Msg
的用法示例。
在下文中一共展示了Msg.Opcode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestServeDNSOverrideIPv6
func TestServeDNSOverrideIPv6(t *testing.T) {
t.Parallel()
const hostname = "foo.com."
var a App
a.Overrides.Store(Overrides{hostname: net.ParseIP("1.2.3.4")})
req := new(dns.Msg)
req.Opcode = dns.OpcodeQuery
req.Question = []dns.Question{{Name: hostname, Qtype: qtypeIPv6}}
var w fDNSResponseWriter
a.ServeDNS(&w, req)
ensure.DeepEqual(t, len(w.msg.Answer), 0)
}
示例2: ResolveIt
func ResolveIt(domain string, rType uint16, badop ...bool) (*dns.Msg, error) {
// root domain if not already
root(&domain)
m := new(dns.Msg)
m.SetQuestion(domain, rType)
if len(badop) > 0 {
m.Opcode = dns.OpcodeStatus
}
// ask the dns server
r, err := dns.Exchange(m, config.DnsListen)
if err != nil {
return nil, fmt.Errorf("Failed to exchange - %v", err)
}
return r, nil
}
示例3: TestServeDNSForwardUDP
func TestServeDNSForwardUDP(t *testing.T) {
t.Parallel()
const ns = "a"
res := new(dns.Msg)
a := App{
Nameservers: []string{ns},
dnsUDPclient: fDNSClient{
exchange: func(m *dns.Msg, a string) (*dns.Msg, time.Duration, error) {
ensure.DeepEqual(t, a, ns)
return res, time.Minute, nil
},
},
}
req := new(dns.Msg)
req.Opcode = dns.OpcodeStatus
var w fDNSResponseWriter
a.ServeDNS(&w, req)
ensure.DeepEqual(t, w.msg, res)
}
示例4: TestServeDNSForwardNonOverrideQuery
func TestServeDNSForwardNonOverrideQuery(t *testing.T) {
t.Parallel()
const ns = "a"
res := new(dns.Msg)
a := App{
Nameservers: []string{ns},
dnsUDPclient: fDNSClient{
exchange: func(m *dns.Msg, a string) (*dns.Msg, time.Duration, error) {
ensure.DeepEqual(t, a, ns)
return res, time.Minute, nil
},
},
}
a.Overrides.Store(Overrides{})
req := new(dns.Msg)
req.Opcode = dns.OpcodeQuery
req.Question = []dns.Question{{Name: "foo.com."}}
var w fDNSResponseWriter
a.ServeDNS(&w, req)
ensure.DeepEqual(t, w.msg, res)
}
示例5: TestServeDNSForwardTryAllAndFail
func TestServeDNSForwardTryAllAndFail(t *testing.T) {
t.Parallel()
ns := []string{"a", "b"}
var current int32
a := App{
Log: log.New(ioutil.Discard, "", log.LstdFlags),
Nameservers: ns,
dnsUDPclient: fDNSClient{
exchange: func(m *dns.Msg, a string) (*dns.Msg, time.Duration, error) {
ensure.DeepEqual(t, a, ns[int(atomic.AddInt32(¤t, 1)-1)])
return nil, time.Minute, errors.New("foo")
},
},
}
req := new(dns.Msg)
req.Opcode = dns.OpcodeStatus
var w fDNSResponseWriter
a.ServeDNS(&w, req)
ensure.DeepEqual(t, w.msg.Rcode, dns.RcodeServerFailure)
ensure.DeepEqual(t, atomic.LoadInt32(¤t), int32(2))
}
示例6: TestServeDNSOverrideIPv4
func TestServeDNSOverrideIPv4(t *testing.T) {
t.Parallel()
const hostname = "foo.com."
ip := net.ParseIP("1.2.3.4")
var a App
a.Overrides.Store(Overrides{hostname: ip})
req := new(dns.Msg)
req.Opcode = dns.OpcodeQuery
req.Question = []dns.Question{{Name: hostname, Qtype: qtypeIPv4}}
var w fDNSResponseWriter
a.ServeDNS(&w, req)
ensure.DeepEqual(t, w.msg.Answer, []dns.RR{
&dns.A{
A: ip,
Hdr: dns.RR_Header{
Name: hostname,
Rrtype: 1,
Class: 1,
Ttl: 100,
Rdlength: 4,
},
},
})
}
示例7: main
//.........这里部分代码省略.........
if nameserver[0] == '[' && nameserver[len(nameserver)-1] == ']' {
nameserver = nameserver[1 : len(nameserver)-1]
}
if i := net.ParseIP(nameserver); i != nil {
nameserver = net.JoinHostPort(nameserver, strconv.Itoa(*port))
} else {
nameserver = dns.Fqdn(nameserver) + ":" + strconv.Itoa(*port)
}
c := new(dns.Client)
t := new(dns.Transfer)
c.Net = "udp"
if *four {
c.Net = "udp4"
}
if *six {
c.Net = "udp6"
}
if *tcp {
c.Net = "tcp"
if *four {
c.Net = "tcp4"
}
if *six {
c.Net = "tcp6"
}
}
m := new(dns.Msg)
m.MsgHdr.Authoritative = *aa
m.MsgHdr.AuthenticatedData = *ad
m.MsgHdr.CheckingDisabled = *cd
m.MsgHdr.RecursionDesired = *rd
m.Question = make([]dns.Question, 1)
m.Opcode = dns.OpcodeQuery
if op, ok := dns.StringToOpcode[strings.ToUpper(*opcode)]; ok {
m.Opcode = op
}
m.Rcode = dns.RcodeSuccess
if rc, ok := dns.StringToRcode[strings.ToUpper(*rcode)]; ok {
m.Rcode = rc
}
if *dnssec || *nsid || *client != "" {
o := new(dns.OPT)
o.Hdr.Name = "."
o.Hdr.Rrtype = dns.TypeOPT
if *dnssec {
o.SetDo()
o.SetUDPSize(dns.DefaultMsgSize)
}
if *nsid {
e := new(dns.EDNS0_NSID)
e.Code = dns.EDNS0NSID
o.Option = append(o.Option, e)
// NSD will not return nsid when the udp message size is too small
o.SetUDPSize(dns.DefaultMsgSize)
}
if *client != "" {
e := new(dns.EDNS0_SUBNET)
e.Code = dns.EDNS0SUBNET
if *clientdraftcode {
e.DraftOption = true
}
e.SourceScope = 0
e.Address = net.ParseIP(*client)
if e.Address == nil {