本文整理匯總了Golang中github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/miekg/dns.Msg.Unpack方法的典型用法代碼示例。如果您正苦於以下問題:Golang Msg.Unpack方法的具體用法?Golang Msg.Unpack怎麽用?Golang Msg.Unpack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/djbarber/ipfs-hack/Godeps/_workspace/src/github.com/miekg/dns.Msg
的用法示例。
在下文中一共展示了Msg.Unpack方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: parsePacket
// parsePacket is used to parse an incoming packet
func (s *Server) parsePacket(packet []byte, from net.Addr) error {
var msg dns.Msg
if err := msg.Unpack(packet); err != nil {
log.Printf("[ERR] mdns: Failed to unpack packet: %v", err)
return err
}
return s.handleQuery(&msg, from)
}
示例2: recv
// recv is used to receive until we get a shutdown
func (c *client) recv(l *net.UDPConn, msgCh chan *dns.Msg) {
if l == nil {
return
}
buf := make([]byte, 65536)
for !c.closed {
n, err := l.Read(buf)
if err != nil {
log.Printf("[ERR] mdns: Failed to read packet: %v", err)
continue
}
msg := new(dns.Msg)
if err := msg.Unpack(buf[:n]); err != nil {
log.Printf("[ERR] mdns: Failed to unpack packet: %v", err)
continue
}
select {
case msgCh <- msg:
case <-c.closedCh:
return
}
}
}