当前位置: 首页>>代码示例>>Golang>>正文


Golang Msg.MsgHdr方法代码示例

本文整理汇总了Golang中github.com/miekg/dns.Msg.MsgHdr方法的典型用法代码示例。如果您正苦于以下问题:Golang Msg.MsgHdr方法的具体用法?Golang Msg.MsgHdr怎么用?Golang Msg.MsgHdr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/miekg/dns.Msg的用法示例。


在下文中一共展示了Msg.MsgHdr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: sendTruncated

func sendTruncated(w dns.ResponseWriter, msgHdr dns.MsgHdr) {
	emptyResp := new(dns.Msg)
	emptyResp.MsgHdr = msgHdr
	emptyResp.Response = true
	if _, isTCP := w.RemoteAddr().(*net.TCPAddr); isTCP {
		dns.HandleFailed(w, emptyResp)
		return
	}
	emptyResp.Truncated = true
	w.WriteMsg(emptyResp)
}
开发者ID:jedisct1,项目名称:rpdns,代码行数:11,代码来源:rpdns.go

示例2: testResolution

func testResolution(t *testing.T, tester ResolveTester, rt ResolveTest) {
	t.Log(" => " + rt.Description)

	// Construct query
	query := new(dns.Msg)
	query.MsgHdr = rt.Header
	query.Question = rt.QuestionSection

	// Get response
	response, err := tester.GetResponse(query)
	was_failure := tester.WasFailure(response, err)
	if rt.ShouldFail {
		// Expecting a failure...
		// ...in fact, if we don't get one, that's BAD
		if !was_failure {
			t.Fatal("Test should have failed, didn't")
		}
		return
	} else {
		// Normal case, should not fail
		if was_failure {
			t.Log(rt)
			t.Fatal(err)
		}
	}

	// Construct expected response
	expected := new(dns.Msg)
	expected.MsgHdr = rt.ExpectedHeader
	expected.Question = query.Question
	expected.Answer = make([]dns.RR, len(rt.ExpectedAnswers))
	for i, answer := range rt.ExpectedAnswers {
		rr, err := dns.NewRR(answer)
		if err != nil {
			t.Fatal(err)
		}
		expected.Answer[i] = rr
	}
	expected.Ns = make([]dns.RR, 0)
	expected.Extra = make([]dns.RR, 0)

	compare_part := func(item1, item2 interface{}, name string) {
		if !reflect.DeepEqual(item1, item2) {
			t.Logf(" * %s is different", name)
			t.Logf("%#v vs %#v", item1, item2)
		}
	}

	// DNS package tends to be loose about some encoding details,
	// only calculating them right before putting the data on the
	// wire.
	sanitize := func(rr_list []dns.RR) {
		for i := range rr_list {
			rr_list[i].Header().Rdlength = 0
		}
	}
	for _, msg := range []*dns.Msg{response, expected} {
		sanitize(msg.Answer)
		sanitize(msg.Ns)
		sanitize(msg.Extra)
	}

	// Confirm equality
	if !reflect.DeepEqual(response, expected) {
		t.Log(response)
		t.Log(expected)
		t.Log("Response not equal to expected response")

		// More DRY to use reflect, but it would also be like
		// chewing broken glass.
		compare_part(response.MsgHdr, expected.MsgHdr, "MsgHdr")
		compare_part(response.Compress, expected.Compress, "Compress")
		compare_part(response.Question, expected.Question, "Question")
		compare_part(response.Answer, expected.Answer, "Answer")
		compare_part(response.Ns, expected.Ns, "Ns")
		compare_part(response.Extra, expected.Extra, "Extra")

		t.FailNow()
	}
}
开发者ID:alLi1n,项目名称:djdns,代码行数:80,代码来源:server_test.go


注:本文中的github.com/miekg/dns.Msg.MsgHdr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。