Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: LookupAddr returns a zero length slice when looking up its own IP address on a Windows DNS server #29600

Closed
jftuga opened this issue Jan 7, 2019 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@jftuga
Copy link

jftuga commented Jan 7, 2019

What version of Go are you using (go version)?

go version go1.11.4 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\jftuga\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\jftuga\go
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\jftuga\AppData\Local\Temp\go-build308914574=/tmp/go-build -gno-record-gcc-switches

What did you do?

// dnstest.go
package main
import "fmt"
import "net"
import "os"

func main() {
    	ip := os.Args[1]
    	fmt.Println("LookupAddr on ", ip)
    	addresses, err := net.LookupAddr(ip)
        if err != nil {
    		fmt.Println("error:", err)
    		return
        }
    	if len(addresses) == 0 {
    		fmt.Printf("error: addresses has a length of zero")
    		return
    	}
    	fmt.Println("results:",addresses)
}
192.168.1.2 is a Active Directory server running DNS
This program is running on 192.168.1.2 and the bug is only seen in this situation.

What did you expect to see?

  • Windows Server 2008 R2 Enterprise

  • Windows Server 2016 Enterprise

  • 192.168.1.2 is a Active Directory server running DNS

    dnstest.exe 192.168.1.2
    LookupAddr on 192.168.1.2
    results: [dns1.example.com.]

What did you see instead?

If I run this program on the DNS server itself, this is the result:

dnstest.exe 192.168.1.2
LookupAddr on  192.168.1.2
error: addresses has a length of zero

This problem only occurs when:

1. Windows OS, this does not occur under Linux
2. This program is running on the DNS server itself
3. It is looking up it's own IP address

In essence, this program does not return any hostnames when looking up it's own IP address when running on a DNS server under Windows. Instead, it returns a zero length slice. In this situation, err is nil.

Can someone else reproduce this?

Also, should err be set when len(addresses) == 0?

@julieqiu julieqiu changed the title net.LookupAddr returns a zero length slice when looking up it's own IP address on a Windows DNS server net: net.LookupAddr returns a zero length slice when looking up it's own IP address on a Windows DNS server Jan 8, 2019
@julieqiu julieqiu changed the title net: net.LookupAddr returns a zero length slice when looking up it's own IP address on a Windows DNS server net: LookupAddr returns a zero length slice when looking up it's own IP address on a Windows DNS server Jan 8, 2019
@julieqiu julieqiu added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 8, 2019
@julieqiu
Copy link
Member

julieqiu commented Jan 8, 2019

/cc @mikioh @bradfitz

@bradfitz bradfitz changed the title net: LookupAddr returns a zero length slice when looking up it's own IP address on a Windows DNS server net: LookupAddr returns a zero length slice when looking up its own IP address on a Windows DNS server Jan 8, 2019
@bradfitz bradfitz added this to the Go1.13 milestone Jan 8, 2019
@iwdgo
Copy link
Contributor

iwdgo commented Mar 3, 2019

https://golang.org/pkg/net/#InterfaceAddrs mentions

On Windows, the resolver always uses C library functions, such as GetAddrInfo and DnsQuery.

When no C compiler is installed, net.LookupAddr() is not reporting the unavailability of C like the usual exec: "gcc": executable file not found in %PATH%. Setting GODEBUG as documented does not change this behavior.

@alexbrainman
Copy link
Member

When no C compiler is installed, net.LookupAddr() is not reporting the unavailability of C

You do not need C compiler to use net.LookupAddr on Windows.

Alex

@iwdgo
Copy link
Contributor

iwdgo commented Mar 10, 2019

The behavior of net.LookupAddr can be reproduced independently using the Powershell instruction Resolve-DnsName -Name 113.17.217.172.in-addr.arpa -Type 6 called here DNSQuery

Type 6 does not return a value when not registered in a public DNS in line with the in-addr domain definition rfc1035.

Using the nslookup command like in the tests of the net package resolves 192. values.

const ipname = "192.168.1.2"

func ExampleNslookupIP() {
	var out bytes.Buffer
	var err bytes.Buffer
	cmd := exec.Command("nslookup", ipname)
	cmd.Stdout = &out
	cmd.Stderr = &err
	if err := cmd.Run(); err != nil {
		log.Fatal(err)
	}
	r := strings.ReplaceAll(out.String(), "\r\n", "\n")
	// nslookup stderr output contains also debug information such as
	// "Non-authoritative answer" and it doesn't return the correct errcode
	if strings.Contains(err.String(), "can't find") {
		log.Fatal(err)
	}
	fmt.Println(r)
	// Output: <your server name>
}

@gopherbot
Copy link

Change https://golang.org/cl/178701 mentions this issue: net/lookup: fix resolving local windows machine ptr

@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
tomocy pushed a commit to tomocy/go that referenced this issue Sep 1, 2019
Fixes golang#29600

Change-Id: Ie60b5c8f8356dfc16b3ef6d3cee520b9ce6a61aa
GitHub-Last-Rev: 76cbdb9
GitHub-Pull-Request: golang#32214
Reviewed-on: https://go-review.googlesource.com/c/go/+/178701
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
t4n6a1ka pushed a commit to t4n6a1ka/go that referenced this issue Sep 5, 2019
Fixes golang#29600

Change-Id: Ie60b5c8f8356dfc16b3ef6d3cee520b9ce6a61aa
GitHub-Last-Rev: 76cbdb9
GitHub-Pull-Request: golang#32214
Reviewed-on: https://go-review.googlesource.com/c/go/+/178701
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
@golang golang locked and limited conversation to collaborators Aug 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants