-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
Go version
go version go1.24.1 windows/amd64
Output of go env in your module/workspace:
set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=1
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOAMD64=v1
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\mikhail\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\mikhail\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\mikhail\AppData\Local\Temp\go-build1405411102=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=NUL
set GOMODCACHE=C:\Users\mikhail\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\mikhail\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\mikhail\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.1
set GOWORK=
set PKG_CONFIG=pkg-configWhat did you do?
There is a handler that handles HTTP requests:
func (h *handler) report(w http.ResponseWriter, r *http.Request) {
...
remoteTcpAddr, err := net.ResolveTCPAddr("tcp", r.RemoteAddr)
...
}
I had 2 hosts on virtual machines connected to a local network network having link-local IPv4 addresses assigned.
I sent a HTTP request from a Linux machine with IP 169.254.100.101 to my Windows machine 169.254.100.102, where the HTTP handler (see above) was executed.
What did you see happen?
In this case r.RemoteAddr was equal to "169.254.100.101%Ethernet 3:34018". For link-local addresses, it contains zone (network adapter) name, which was "Ethernet 3" in my case.
net.ResolveTCPAddr() failed with an error.
err.Error() ="lookup 169.254.100.101%Ethernet 3: no such host".
It worked fine with link-local IPv6 addresses. It worked fine with non link-local IPv4 and IPv6 addresses, which did not have a zone specified. net.ResolveTCPAddr() behaves the same way on Ubuntu Linux as well at the same Go version. I checked that with a unit test, where input "169.254.100.101%Ethernet 3:34018" was hard coded.
What did you expect to see?
I expected net.ResolveTCPAddr() to return: a *TCPAddr having IP="169.254.100.101", Zone="Ethernet 3", Port="34018". The error was expected to be nil.