Add IsMsg()
A quick validating function that checks if a buffer is a valid DNS message. The code is *far* from complete.
This commit is contained in:
parent
812ab5e755
commit
060e66250e
16
defaults.go
16
defaults.go
|
@ -5,14 +5,14 @@
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const hexDigit = "0123456789abcdef"
|
const hexDigit = "0123456789abcdef"
|
||||||
|
|
||||||
// Everything is assumed in the ClassINET class. If
|
// Everything is assumed in ClassINET.
|
||||||
// you need other classes you are on your own.
|
|
||||||
|
|
||||||
// SetReply creates a reply packet from a request message.
|
// SetReply creates a reply packet from a request message.
|
||||||
func (dns *Msg) SetReply(request *Msg) *Msg {
|
func (dns *Msg) SetReply(request *Msg) *Msg {
|
||||||
|
@ -165,6 +165,18 @@ func IsSubDomain(parent, child string) bool {
|
||||||
return CompareDomainName(parent, child) == CountLabel(parent)
|
return CompareDomainName(parent, child) == CountLabel(parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsMsg sanity checks buf and returns an error if it isn't a valid DNS packet.
|
||||||
|
// The checking is performed on the binary payload.
|
||||||
|
func IsMsg(buf []byte) error {
|
||||||
|
// Header
|
||||||
|
if len(buf) < 12 {
|
||||||
|
return errors.New("dns: bad message header")
|
||||||
|
}
|
||||||
|
// Header: Opcode
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// IsFqdn checks if a domain name is fully qualified.
|
// IsFqdn checks if a domain name is fully qualified.
|
||||||
func IsFqdn(s string) bool {
|
func IsFqdn(s string) bool {
|
||||||
l := len(s)
|
l := len(s)
|
||||||
|
|
1
msg.go
1
msg.go
|
@ -1535,6 +1535,7 @@ func (dns *Msg) Unpack(msg []byte) (err error) {
|
||||||
// If we see a TC bit being set we return here, without
|
// If we see a TC bit being set we return here, without
|
||||||
// an error, because technically it isn't an error. So return
|
// an error, because technically it isn't an error. So return
|
||||||
// without parsing the potentially corrupt packet and hitting an error.
|
// without parsing the potentially corrupt packet and hitting an error.
|
||||||
|
// TODO(miek): this isn't the best strategy!
|
||||||
if dns.Truncated {
|
if dns.Truncated {
|
||||||
dns.Answer = nil
|
dns.Answer = nil
|
||||||
dns.Ns = nil
|
dns.Ns = nil
|
||||||
|
|
Loading…
Reference in New Issue