Skip to content

Commit 86b287f

Browse files
committed
Handle the root in a specific way (see issue #4)
1 parent 9e8e08b commit 86b287f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

server.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,11 @@ func parse(buf *bytes.Buffer) (types.DNSpacket, bool) {
239239
labels[nlabels-1] = string(label)
240240
}
241241
packet.Qsection = make([]types.Qentry, packet.Qdcount)
242-
packet.Qsection[0].Qname = strings.Join(labels, ".")
242+
if len(labels) == 0 { // A special case, the root (see issue #4)
243+
packet.Qsection[0].Qname = "."
244+
} else {
245+
packet.Qsection[0].Qname = strings.Join(labels, ".")
246+
}
243247
packet.Qsection[0].Qtype, ok = readShortInteger(buf)
244248
if !ok {
245249
return packet, false

types.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ func Encode(name string) []byte {
143143
var (
144144
totalresult []byte
145145
)
146-
labels := strings.Split(name, ".", -1)
146+
labels := make([]string, 0)
147+
if name != "." { // The root is a special case. See issue #4
148+
labels = strings.Split(name, ".", -1)
149+
}
147150
totallength := 0
148151
totalresult = make([]byte, 256) // TODO what a waste
149152
for _, label := range labels {

0 commit comments

Comments
 (0)