dns

DNS client and server implementations using the Go project's dnsmessage package
Log | Files | Refs | README | LICENSE

commit c245affd0ab63714b15dc1e6bd67307059e8da4f
parent fcbc0eaeb5ac159cd2b10e70e5deaae703cf5189
Author: Oliver Lowe <o@olowe.co>
Date:   Fri, 19 Nov 2021 13:35:11 +1100

read the entire DNS message over TCP, handle EOF

we were just reading 1024 bytes may or may not have contained the
whole message. And before we weren't even handling EOF from the
underlying connection. Now the io package handles it for us.

Diffstat:
Mdns.go | 9+++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/dns.go b/dns.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "errors" "fmt" + "io" "net" "golang.org/x/net/dns/dnsmessage" @@ -86,13 +87,9 @@ func dnsStreamExchange(b []byte, conn net.Conn) ([]byte, error) { if _, err := conn.Write(m); err != nil { return nil, err } - buf := make([]byte, 1024) - n, err := conn.Read(buf) + buf, err := io.ReadAll(conn) if err != nil { return nil, err } - if n == 0 { - return nil, fmt.Errorf("empty response") - } - return buf[2:n], nil + return buf[2:], nil }