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.Dial fails with an ip6 addres - connect: invalid argument #43950

Closed
krasi-georgiev opened this issue Jan 27, 2021 · 4 comments
Closed

net.Dial fails with an ip6 addres - connect: invalid argument #43950

krasi-georgiev opened this issue Jan 27, 2021 · 4 comments

Comments

@krasi-georgiev
Copy link

go version
go version go1.15.5 linux/amd64
go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/krasi/.cache/go-build"
GOENV="/home/krasi/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/krasi/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/krasi"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/krasi/src/github.com/arribada/i360/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build769533656=/tmp/go-build -gno-record-gcc-switches"

running the code below results in

2021/01/27 11:13:51 dial tcp [fe80::42:f1ff:feef:7dc8]:8080: connect: invalid argument
exit status 1

I tried all sort of combination but any ip6 address returns with an error invalid argument (except [::]:8080

package main

import (
	"bufio"
	"fmt"
	"log"
	"net"
	"time"
)

func main() {

	go func() {
		ln, err := net.Listen("tcp", ":8080")
		if err != nil {
			log.Print(err)
			// handle error
		}
		for {
			conn, err := ln.Accept()
			if err != nil {
				log.Print(err)
				// handle error
			}
			fmt.Println("conn", conn)
			// go handleConnection(conn)
		}
	}()

	time.Sleep(100 * time.Millisecond)

	conn, err := net.Dial("tcp", "[fe80::42:f1ff:feef:7dc8]:8080")
	if err != nil {
		log.Fatal(err)
		// handle error
	}
	fmt.Fprintf(conn, "GET / HTTP/1.0\r\n\r\n")
	status, err := bufio.NewReader(conn).ReadString('\n')
	log.Print(err.Error())
	fmt.Println("status", status)
}
 ifconfig

wlp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.105  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::7fef:8789:78f1:aeda  prefixlen 64  scopeid 0x20<link>
        ether d4:25:8b:b6:6a:e8  txqueuelen 1000  (Ethernet)
        RX packets 438123553  bytes 317785644433 (317.7 GB)
        RX errors 0  dropped 2  overruns 0  frame 0
        TX packets 474445465  bytes 191400554283 (191.4 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
@seankhliao
Copy link
Member

For questions please refer to https://github.com/golang/go/wiki/Questions

@krasi-georgiev
Copy link
Author

Why did you think it is a question?
I am following the official docs and I would either consider the docs incorrect or there is a bug.

@seankhliao
Copy link
Member

the address you used is link local and requires an interface name, which would've been apparent if you tried to search for the error

@krasi-georgiev
Copy link
Author

krasi-georgiev commented Jan 27, 2021

yes I did search quite a bit, but apparently overlooked this detail.
Sorry for the noise and for anyone else coming to the same issue here is the answer
conn, err := net.Dial("tcp", "[fe80::42:f1ff:feef:7dc8%wlp4s0]:8080")

@golang golang locked and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants