本文整理汇总了Golang中github.com/socketplane/socketplane/Godeps/_workspace/src/github.com/miekg/dns.Msg.Pack方法的典型用法代码示例。如果您正苦于以下问题:Golang Msg.Pack方法的具体用法?Golang Msg.Pack怎么用?Golang Msg.Pack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/socketplane/socketplane/Godeps/_workspace/src/github.com/miekg/dns.Msg
的用法示例。
在下文中一共展示了Msg.Pack方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sendQuery
// Pack the dns.Msg and write to available connections (multicast)
func (c *client) sendQuery(msg *dns.Msg) error {
buf, err := msg.Pack()
if err != nil {
return err
}
if c.ipv4conn != nil {
c.ipv4conn.WriteTo(buf, ipv4Addr)
}
if c.ipv4conn != nil {
c.ipv4conn.WriteTo(buf, ipv6Addr)
}
return nil
}
示例2: multicastResponse
// multicastResponse us used to send a multicast response packet
func (c *server) multicastResponse(msg *dns.Msg) error {
buf, err := msg.Pack()
if err != nil {
log.Println("Failed to pack message!")
return err
}
if c.ipv4conn != nil {
c.ipv4conn.WriteTo(buf, ipv4Addr)
}
if c.ipv6conn != nil {
c.ipv6conn.WriteTo(buf, ipv6Addr)
}
return nil
}
示例3: sendResponse
// sendResponse is used to send a unicast response packet
func (s *server) sendResponse(resp *dns.Msg, from net.Addr) error {
buf, err := resp.Pack()
if err != nil {
return err
}
addr := from.(*net.UDPAddr)
if addr.IP.To4() != nil {
_, err = s.ipv4conn.WriteToUDP(buf, addr)
return err
} else {
_, err = s.ipv6conn.WriteToUDP(buf, addr)
return err
}
}