你可以如何在Golang的net包中使用dnsMsg?

huangapple go评论85阅读模式
英文:

How can I make use of dnsMsg in golang's net package

问题

我正在编写一个简单的 Golang 应用程序,需要对一些 DNS 数据包进行解码。我注意到在 net 库中,有一个完美的实现,即 net/dnsmsg.go,其中包含了正确的结构体、打包/解包函数等。

然而,该类型被标记为私有(小写的 dnsMsg)。所以看起来我无法在我的应用程序中使用它。

我对 Golang 还不太熟悉,所以不知道我的唯一选择是重新实现 net/dnsmsg.go,还是有更好的解决办法。

英文:

I'm writing a simple golang application that needs to do some decoding of some DNS packets. I noticed that in the net library, there appears to be the perfect implementation in the form of net/dnsmsg.go which contains the right structs, pack / unpack functions etc.

However, the type is marked private (lower case dnsMsg). So it appears that I have no way of using this from within my app.

I'm quite new to golang, so don't know if my only option would be to reimplement net/dnsmsg.go myself, or if there's a better way around this.

答案1

得分: 1

我的问题通过使用第三方 DNS 库 miekg/dns(https://github.com/miekg/dns)得到了解决。

英文:

My problem was solved by using a third party dns library, specifically miekg/dns (https://github.com/miekg/dns).

答案2

得分: 0

另一个选择是使用Google的gopacket包,该包提供了Go语言的数据包解码功能。特别是,layers子包提供了解码协议数据包的逻辑,其中包括解码DNS数据包所需的内容。

英文:

Another option would be to use Google's gopacket package which provides packets decoding for Go. In particular, the layers sub-package provides logic for decoding protocol packets, among which what is necessary to decode DNS packets.

huangapple
  • 本文由 发表于 2013年12月31日 02:26:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/20845256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定