File tree 2 files changed +9
-2
lines changed
2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -239,7 +239,11 @@ func parse(buf *bytes.Buffer) (types.DNSpacket, bool) {
239
239
labels [nlabels - 1 ] = string (label )
240
240
}
241
241
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
+ }
243
247
packet .Qsection [0 ].Qtype , ok = readShortInteger (buf )
244
248
if ! ok {
245
249
return packet , false
Original file line number Diff line number Diff line change @@ -143,7 +143,10 @@ func Encode(name string) []byte {
143
143
var (
144
144
totalresult []byte
145
145
)
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
+ }
147
150
totallength := 0
148
151
totalresult = make ([]byte , 256 ) // TODO what a waste
149
152
for _ , label := range labels {
You can’t perform that action at this time.
0 commit comments