2011-08-08 22:09:05 +10:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package dns
|
|
|
|
|
2011-09-26 17:11:14 +10:00
|
|
|
// Function defined in this subpackage work on []byte and but still
|
|
|
|
// provide some higher level functions.
|
2011-08-08 22:09:05 +10:00
|
|
|
|
2011-09-01 16:35:08 +10:00
|
|
|
// RawSetId sets the message ID in buf.
|
2012-01-10 02:24:19 +11:00
|
|
|
func RawSetId(msg []byte, off int, id uint16) bool {
|
|
|
|
msg[off], msg[off+1] = packUint16(id)
|
2011-11-28 16:03:21 +11:00
|
|
|
return true
|
2011-08-09 00:29:13 +10:00
|
|
|
}
|
2012-01-12 02:02:05 +11:00
|
|
|
|
|
|
|
// RawSetRdLength set the rdlength
|
|
|
|
func RawSetRdLength(msg []byte, off, end int) bool {
|
|
|
|
// We are at the start of the header, walk the
|
|
|
|
// domainname (might be compressed), and set the
|
|
|
|
// length
|
|
|
|
Loop:
|
|
|
|
for {
|
|
|
|
if off > len(msg) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
c := int(msg[off])
|
|
|
|
off++
|
|
|
|
switch c & 0xC00 {
|
|
|
|
case 0x00:
|
|
|
|
if c == 0x00 {
|
|
|
|
// End of the domainname
|
|
|
|
break Loop
|
|
|
|
}
|
|
|
|
|
|
|
|
case 0xC0:
|
|
|
|
// pointer, next byte included, ends domainnames
|
|
|
|
off++
|
|
|
|
break 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+1 > len(msg) {
|
|
|
|
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 true
|
|
|
|
}
|