Skip to content

Commit

Permalink
Fix for changed API in miekg/dns (miekg#6)
Browse files Browse the repository at this point in the history
PackStruct was removed; instead, the resolve code now recreates RRs by
writing the RR header information manually into a buffer.
  • Loading branch information
tjeb authored and miekg committed Jun 13, 2016
1 parent 5a94647 commit 0a62612
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions unbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import "C"

import (
"github.com/miekg/dns"
"encoding/binary"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -244,12 +245,23 @@ func (u *Unbound) Resolve(name string, rrtype, rrclass uint16) (*Result, error)
r.Rr = make([]dns.RR, 0)
b := C.GoBytes(unsafe.Pointer(C.array_elem_char(res.data, C.int(j))), C.array_elem_int(res.len, C.int(j)))
for len(b) != 0 {
// Create the RR
// Create the RR; write out the header details and
// the rdata to a buffer, and unpack it again into an
// actual RR
h.Rdlength = uint16(len(b))
msg := make([]byte, 20+len(h.Name)) // Long enough
off, _ := dns.PackStruct(&h, msg, 0)
msg = msg[:off]

msg := make([]byte, len(h.Name) + 11)
off, _ := dns.PackDomainName(h.Name, msg, 0, nil, false)
binary.BigEndian.PutUint16(msg[off:], h.Rrtype)
off += 2
binary.BigEndian.PutUint16(msg[off:], h.Class)
off += 2
binary.BigEndian.PutUint32(msg[off:], h.Ttl)
off += 4
binary.BigEndian.PutUint16(msg[off:], h.Rdlength)
off += 2
rrbuf := append(msg, b...)

rr, _, err := dns.UnpackRR(rrbuf, 0)
if err == nil {
r.Rr = append(r.Rr, rr)
Expand Down

0 comments on commit 0a62612

Please sign in to comment.