Last few fixes and remove debugging prints
This commit is contained in:
parent
cedf11f27b
commit
28f5e6c1ed
|
@ -38,7 +38,7 @@ func main() {
|
|||
}
|
||||
println(r.String())
|
||||
buf, _ := r.Pack()
|
||||
dns.Compress(buf)
|
||||
buf = dns.Compress(buf)
|
||||
r1 := new(dns.Msg)
|
||||
ok := r1.Unpack(buf)
|
||||
if ok {
|
||||
|
|
20
rawmsg.go
20
rawmsg.go
|
@ -4,10 +4,6 @@
|
|||
|
||||
package dns
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const maxPointer = 2 << 13 // We have 14 bits for the offset
|
||||
|
||||
// Function defined in this subpackage work on []byte and but still
|
||||
|
@ -31,8 +27,8 @@ type rawmove struct {
|
|||
}
|
||||
|
||||
// Compress performs name comression in the dns message contained in buf.
|
||||
// It returns the number of bytes saved.
|
||||
func Compress(msg []byte) int {
|
||||
// It returns the shortened buffer.
|
||||
func Compress(msg []byte) []byte {
|
||||
|
||||
// First we create a table of domain names to which we
|
||||
// can link. This is stored in 'table'
|
||||
|
@ -80,7 +76,7 @@ Loop:
|
|||
|
||||
// Discount for previous moves, decrease the poffset counter
|
||||
// with moves that occur before it
|
||||
for i := len(moves)-1; i >= 0; i-- {
|
||||
for i := len(moves) - 1; i >= 0; i-- {
|
||||
if poffset > moves[i].from {
|
||||
poffset -= (moves[i].length - 2)
|
||||
}
|
||||
|
@ -132,14 +128,14 @@ Loop:
|
|||
saved := 0
|
||||
// Start at the back, easier to move
|
||||
for i := len(moves) - 1; i >= 0; i-- {
|
||||
fmt.Printf("%v\n", moves[i])
|
||||
// fmt.Printf("%v\n", moves[i])
|
||||
// move the bytes
|
||||
copy(msg[moves[i].from+1:], msg[moves[i].from+moves[i].length-1:])
|
||||
// Now set the pointer at moves[i].from and moves[i].from+1
|
||||
fmt.Printf("bits %b\n", moves[i].offset^0xC000)
|
||||
// fmt.Printf("bits %b\n", moves[i].offset^0xC000)
|
||||
msg[moves[i].from], msg[moves[i].from+1] = packUint16(uint16(moves[i].offset ^ 0xC000))
|
||||
saved += moves[i].length // minus something
|
||||
saved += (moves[i].length - 2) // minus something
|
||||
}
|
||||
msg = msg[:len(msg) - saved]
|
||||
return saved
|
||||
msg = msg[:len(msg)-saved]
|
||||
return msg
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue