-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
What version of Go are you using (go version
)?
go version go1.7.3 linux/amd64
What operating system and processor architecture are you using (go env
)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/lib/google-golang"
GOTOOLDIR="/usr/lib/google-golang/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build668040631=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
What did you do?
package main
import (
"fmt"
"net"
)
func main() {
if cname, err := net.LookupCNAME("www.google.com"); err != nil {
fmt.Printf("lookup failed: %q\n", err)
} else {
fmt.Printf("lookup success: %s\n", cname)
}
}
What did you expect to see?
The documentation says "LookupCNAME returns the canonical DNS host for the given name." To me, this means that it returns the canonical name as provided by the POSIX getaddrinfo()
function when given the AI_CANONNAME
flag. So I expected the following:
lookup success: www.google.com
What did you see instead?
lookup failed: "lookup www.google.com on 127.0.1.1:53: no such host"
It turns out that LookupCNAME
simply resolves CNAME records, it does NOT return the canonical DNS host for the given name as documented.
Proposed change
Ideally LookupCNAME
would return the canonical hostname as provided by the POSIX getaddrinfo()
function.
If the intention of the LookupCNAME
function is to only resolve CNAME records, then replace the first sentence of the documentation with:
LookupCNAME resolves the CNAME DNS record for the given name. It is an error if the given hostname does not have a CNAME record.