本文整理汇总了Golang中github.com/patchwork-toolkit/patchwork/Godeps/_workspace/src/github.com/miekg/dns.Msg.Unpack方法的典型用法代码示例。如果您正苦于以下问题:Golang Msg.Unpack方法的具体用法?Golang Msg.Unpack怎么用?Golang Msg.Unpack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/patchwork-toolkit/patchwork/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] bonjour: Failed to unpack packet: %v", err)
return err
}
return s.handleQuery(&msg, from)
}
示例2: recv
// Data receiving routine reads from connection, unpacks packets into dns.Msg
// structures and sends them to a given msgCh channel
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.ReadFrom(buf)
if err != nil {
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
}
}
}