Fix more robust, but also nack more about non qualified names
This commit is contained in:
parent
4d8ec5dfe6
commit
e9ea2d7750
|
@ -114,7 +114,7 @@ Flags:
|
|||
qtype = dns.TypeA
|
||||
}
|
||||
|
||||
nameserver = string([]byte(nameserver)[1:]) // chop off @
|
||||
nameserver = dns.Fqdn(string([]byte(nameserver)[1:])) // chop off @
|
||||
nameserver += ":" + strconv.Itoa(*port)
|
||||
|
||||
// We use the async query handling, just to show how it is to be used.
|
||||
|
@ -180,7 +180,7 @@ Flags:
|
|||
}
|
||||
|
||||
for i, v := range qname {
|
||||
m.Question[0] = dns.Question{v, qtype, qclass}
|
||||
m.Question[0] = dns.Question{dns.Fqdn(v), qtype, qclass}
|
||||
m.Id = dns.Id()
|
||||
if *query {
|
||||
fmt.Printf("%s", m.String())
|
||||
|
@ -203,7 +203,8 @@ Flags:
|
|||
}
|
||||
}()
|
||||
Redo:
|
||||
if r == nil {
|
||||
if e != nil {
|
||||
fmt.Printf(";; %s\n", e.Error())
|
||||
return
|
||||
}
|
||||
if r.Rcode != dns.RcodeSuccess {
|
||||
|
|
4
msg.go
4
msg.go
|
@ -1077,7 +1077,9 @@ func PackRR(rr RR, msg []byte, off int, compression map[string]int, compress boo
|
|||
if !ok {
|
||||
return len(msg), false
|
||||
}
|
||||
rawSetRdlength(msg, off, off1)
|
||||
if !rawSetRdlength(msg, off, off1) {
|
||||
return len(msg), false
|
||||
}
|
||||
return off1, true
|
||||
}
|
||||
|
||||
|
|
15
rawmsg.go
15
rawmsg.go
|
@ -7,6 +7,8 @@ package dns
|
|||
// These raw* functions do not use reflection, they directly set the values
|
||||
// in the buffer. There are faster than their reflection counterparts.
|
||||
|
||||
// TODO: make them all return booleans
|
||||
|
||||
// RawSetId sets the message id in buf.
|
||||
func rawSetId(msg []byte, i uint16) {
|
||||
msg[0], msg[1] = packUint16(i)
|
||||
|
@ -35,10 +37,14 @@ func rawSetExtraLen(msg []byte, i uint16) {
|
|||
// rawSetRdlength sets the rdlength in the header of
|
||||
// the RR. The offset 'off' must be positioned at the
|
||||
// start of the header of the RR, 'end' must be the
|
||||
// end of the RR. There is no check if we overrun the buffer.
|
||||
func rawSetRdlength(msg []byte, off, end int) {
|
||||
// end of the RR.
|
||||
func rawSetRdlength(msg []byte, off, end int) bool {
|
||||
l := len(msg)
|
||||
Loop:
|
||||
for {
|
||||
if off+1 > l {
|
||||
return false
|
||||
}
|
||||
c := int(msg[off])
|
||||
off++
|
||||
switch c & 0xC0 {
|
||||
|
@ -57,8 +63,11 @@ Loop:
|
|||
// The domainname has been seen, we at the start of the fixed part in the header.
|
||||
// Type is 2 bytes, class is 2 bytes, ttl 4 and then 2 bytes for the length.
|
||||
off += 2 + 2 + 4
|
||||
if off+2 > l {
|
||||
return false
|
||||
}
|
||||
//off+1 is the end of the header, 'end' is the end of the rr
|
||||
//so 'end' - 'off+2' is the lenght of the rdata
|
||||
msg[off], msg[off+1] = packUint16(uint16(end - (off + 2)))
|
||||
return
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue