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


Golang Msg.Pack方法代碼示例

本文整理匯總了Golang中dns.Msg.Pack方法的典型用法代碼示例。如果您正苦於以下問題:Golang Msg.Pack方法的具體用法?Golang Msg.Pack怎麽用?Golang Msg.Pack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dns.Msg的用法示例。


在下文中一共展示了Msg.Pack方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: send

func send(m *dns.Msg) (o []byte) {
	var p *dns.Msg
	for _, c := range qr {
		p, _ = c.Client.Exchange(m, c.Addr)
	}
	o, _ = p.Pack()
	return
}
開發者ID:niltonkummer,項目名稱:dns,代碼行數:8,代碼來源:config_sign.go

示例2: add

// Add an entry from the cache. The old entry (if any) gets
// overwritten
func (c Cache) add(q *dns.Msg) {
	qname := q.Question[0].Name
	i := intval(q.Question[0].Qclass, q.Question[0].Qtype)
	if c[qname] == nil {
		im := make(map[int][]byte)
		c[qname] = im
	}
	buf, _ := q.Pack()
	im := c[qname]
	im[i] = buf
}
開發者ID:andradeandrey,項目名稱:godns,代碼行數:13,代碼來源:config_rproxy.go

示例3: add

// Add an entry to the cache. The old entry (if any) gets overwritten
func (c Cache) add(q *dns.Msg) {
	c.rw.Lock()
	defer c.rw.Unlock()
	qname := q.Question[0].Name
	i := intval(q.Question[0].Qclass, q.Question[0].Qtype)
	if c.data[qname] == nil {
		im := make(map[int]*item)
		c.data[qname] = im
	}
	buf, _ := q.Pack()
	im := c.data[qname]
	im[i] = &item{time.Seconds(), buf}
}
開發者ID:niltonkummer,項目名稱:dns,代碼行數:14,代碼來源:config_rproxy.go

示例4: respondTo

func respondTo(conn *net.UDPConn, addr *net.UDPAddr, msg *dns.Msg, raw []uint8) {
	for _, question := range msg.Question {
		if strings.HasSuffix(question.Name, ".bit.") {
			respondWithDotBit(msg, question)
		} else {
			respondWithFallback(raw, msg, question, options.dnsProxy)
		}
	}

	out, ok := msg.Pack()
	if ok == true {
		conn.WriteToUDP(out, addr)
	} else {
		LOG.Fatalln("msg.Pack() failed")
	}
}
開發者ID:manveru,項目名稱:godns,代碼行數:16,代碼來源:godns.go

示例5: delay

func delay(m *dns.Msg) (buf []byte) {
	var (
		ok1 bool
		o   *dns.Msg
	)
	if previous, ok1 = checkDelay(); !ok1 {
		println("Dropping: too often")
		time.Sleep(NSECDELAY)
		return
	}
	println("Ok: let it through")
	for _, c := range qr {
		o, _ = c.Client.Exchange(m, c.Addr)
	}
	buf, _ = o.Pack()
	return
}
開發者ID:niltonkummer,項目名稱:dns,代碼行數:17,代碼來源:config_delay.go

示例6: handleReflect

func handleReflect(w dns.ResponseWriter, r *dns.Msg) {
	m := new(dns.Msg)
	m.SetReply(r)
	m.Extra = make([]dns.RR, 1)
	m.Answer = make([]dns.RR, 1)
	var (
		v4  bool
		rr  dns.RR
		str string
		a   net.IP
	)

	if ip, ok := w.RemoteAddr().(*net.UDPAddr); ok {
		str = "Port: " + strconv.Itoa(ip.Port) + " (udp)"
		a = ip.IP
		v4 = a.To4() != nil
	}
	if ip, ok := w.RemoteAddr().(*net.TCPAddr); ok {
		str = "Port: " + strconv.Itoa(ip.Port) + " (tcp)"
		a = ip.IP
		v4 = a.To4() != nil
	}

	if v4 {
		rr = new(dns.RR_A)
		rr.(*dns.RR_A).Hdr = dns.RR_Header{Name: dom, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 0}
		rr.(*dns.RR_A).A = a
	} else {
		rr = new(dns.RR_AAAA)
		rr.(*dns.RR_AAAA).Hdr = dns.RR_Header{Name: dom, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: 0}
		rr.(*dns.RR_AAAA).AAAA = a
	}

	t := new(dns.RR_TXT)
	t.Hdr = dns.RR_Header{Name: dom, Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: 0}
	t.Txt = str
	m.Extra[0] = t
	m.Answer[0] = rr

	b, ok := m.Pack()
	if !ok {
		return
	}
	w.Write(b)
}
開發者ID:andradeandrey,項目名稱:godns,代碼行數:45,代碼來源:reflect.go

示例7: reply

func reply(c *dns.Conn, in *dns.Msg) []byte {
	m := new(dns.Msg)
	m.SetReply(in)

	m.Question = make([]dns.Question, 1)
	m.Answer = make([]dns.RR, 1)
	m.Extra = make([]dns.RR, 1)

	// Copy the question.
	m.Question[0] = in.Question[0]

	// Some foo to check if we are called through ip6 or ip4.
	// We add the correct reply RR.
	var ad net.IP
	if c.UDP != nil {
		ad = c.Addr.(*net.UDPAddr).IP
	} else {
		ad = c.Addr.(*net.TCPAddr).IP
	}

	if ad.To4() != nil {
		r := new(dns.RR_A)
		r.Hdr = dns.RR_Header{Name: "whoami.miek.nl.", Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 0}
		r.A = ad
		m.Answer[0] = r
	} else {
		r := new(dns.RR_AAAA)
		r.Hdr = dns.RR_Header{Name: "whoami.miek.nl.", Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: 0}
		r.AAAA = ad
		m.Answer[0] = r
	}

	t := new(dns.RR_TXT)
	t.Hdr = dns.RR_Header{Name: "whoami.miek.nl.", Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: 0}
	if c.TCP != nil {
		t.Txt = "Port: " + strconv.Itoa(c.Port) + " (tcp)"
	} else {
		t.Txt = "Port: " + strconv.Itoa(c.Port) + " (udp)"
	}
	m.Extra[0] = t

	b, _ := m.Pack()
	return b
}
開發者ID:elazarl,項目名稱:godns,代碼行數:44,代碼來源:reflect.go

示例8: checkcache

func checkcache(m *dns.Msg) (o []byte) {
	// Check if we have the packet in Cache
	// if so, return it. Otherwise ask the
	// server, return that answer and put it
	// in the cache.
	o = cache.lookup(m)
	if o != nil {
		// octet 1 and 2 contain the Id, set the one for the current pkt
		dns.RawSetId(o, 0, m.MsgHdr.Id)
		return
	}

	println("Cache miss")
	var p *dns.Msg
	for _, c := range qr {
		p, _ = c.Client.Exchange(m, c.Addr)
	}
	cache.add(p)
	o, _ = p.Pack()
	return
}
開發者ID:niltonkummer,項目名稱:dns,代碼行數:21,代碼來源:config_rproxy.go

示例9: send

func send(m *dns.Msg) (buf []byte) {
	if *verbose {
		fmt.Printf("--> %s\n", m.Question[0].String())
	}

	var o *dns.Msg
	var err error
	for _, c := range qr {
		o, err = c.Client.Exchange(m, c.Addr)
		if *verbose {
			if err == nil {
				fmt.Printf("<-- %s\n", m.Question[0].String())
			} else {
				fmt.Printf("%s\n", err.Error())
			}
		}
	}
	if err == nil {
		buf, _ = o.Pack()
	}
	return
}
開發者ID:niltonkummer,項目名稱:dns,代碼行數:22,代碼來源:config.go

示例10: send

func send(w dns.ResponseWriter, m *dns.Msg) {
	buf, _ := m.Pack()
	w.Write(buf)
}
開發者ID:andradeandrey,項目名稱:godns,代碼行數:4,代碼來源:ns.go

示例11: handleReflect

func handleReflect(w dns.ResponseWriter, r *dns.Msg) {
	var (
		v4  bool
		rr  dns.RR
		str string
		a   net.IP
	)
	m := new(dns.Msg)
	m.SetReply(r)
	if ip, ok := w.RemoteAddr().(*net.UDPAddr); ok {
		str = "Port: " + strconv.Itoa(ip.Port) + " (udp)"
		a = ip.IP
		v4 = a.To4() != nil
	}
	if ip, ok := w.RemoteAddr().(*net.TCPAddr); ok {
		str = "Port: " + strconv.Itoa(ip.Port) + " (tcp)"
		a = ip.IP
		v4 = a.To4() != nil
	}

	if v4 {
		rr = new(dns.RR_A)
		rr.(*dns.RR_A).Hdr = dns.RR_Header{Name: dom, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 0}
		rr.(*dns.RR_A).A = a.To4()
	} else {
		rr = new(dns.RR_AAAA)
		rr.(*dns.RR_AAAA).Hdr = dns.RR_Header{Name: dom, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: 0}
		rr.(*dns.RR_AAAA).AAAA = a
	}

	t := new(dns.RR_TXT)
	t.Hdr = dns.RR_Header{Name: dom, Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: 0}
	t.Txt = str

	switch r.Question[0].Qtype {
	case dns.TypeTXT:
		m.Answer = append(m.Answer, t)
		m.Extra = append(m.Extra, rr)
	default:
		fallthrough
	case dns.TypeAAAA, dns.TypeA:
		m.Answer = append(m.Answer, rr)
		m.Extra = append(m.Extra, t)

	}
	/*
	   nsec3 := new(dns.RR_NSEC3)
	   nsec3.Hdr = dns.RR_Header{Name: dom, Rrtype: dns.TypeNSEC3, Class: dns.ClassINET, Ttl: 0}
	   nsec3.Hash = dns.SHA1
	   nsec3.Flags = 0
	   nsec3.Iterations = 1
	   nsec3.Salt = "AABB"
	   nsec3.SaltLength = uint8(len(nsec3.Salt)/2)
	   nsec3.NextDomain = "miek.nl."
	   nsec3.TypeBitMap = []uint16{dns.TypeA, dns.TypeNS, dns.TypeSOA, dns.TypeTXT, dns.TypeRRSIG, 4000, 4001, 5949}
	   nsec3.HashNames("miek.nl.")
	   m.Extra = append(m.Extra, nsec3)
	*/

	b, ok := m.Pack()
	if *printf {
		fmt.Printf("%v\n", m.String())
	}
	if !ok {
		log.Print("Packing failed")
		m.SetRcode(r, dns.RcodeServerFailure)
		m.Extra = nil
		m.Answer = nil
		b, _ = m.Pack()
	}
	w.Write(b)
}
開發者ID:davecheney,項目名稱:godns,代碼行數:72,代碼來源:reflect.go


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