當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Msg.Opcode方法代碼示例

本文整理匯總了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)
}
開發者ID:undeadops,項目名稱:boxdns,代碼行數:12,代碼來源:main_test.go

示例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
}
開發者ID:nanopack,項目名稱:shaman,代碼行數:18,代碼來源:dns_test.go

示例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)
}
開發者ID:undeadops,項目名稱:boxdns,代碼行數:19,代碼來源:main_test.go

示例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)
}
開發者ID:undeadops,項目名稱:boxdns,代碼行數:21,代碼來源:main_test.go

示例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(&current, 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(&current), int32(2))
}
開發者ID:undeadops,項目名稱:boxdns,代碼行數:21,代碼來源:main_test.go

示例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,
			},
		},
	})
}
開發者ID:undeadops,項目名稱:boxdns,代碼行數:24,代碼來源:main_test.go

示例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 {
開發者ID:valm0unt,項目名稱:exdns,代碼行數:67,代碼來源:q.go


注:本文中的github.com/miekg/dns.Msg.Opcode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。