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: Listen("tcp", ":port") fails in an AF_INET6-only environment #12510

Closed
pmarks-net opened this issue Sep 5, 2015 · 1 comment

Comments

Projects
None yet
3 participants
@pmarks-net
Copy link
Contributor

commented Sep 5, 2015

Given a hacked-up IPv6-only Linux kernel:

  • socket(AF_INET6) ok
  • setsockopt(IPV6_V6ONLY, 0) fails
  • socket(AF_INET) fails

The following program:

package main

import (
        "net"
        "fmt"
        "flag"
)

var port = flag.Int("port", 8080, "XXX")

func main() {
        flag.Parse()
        ln, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
        if err != nil {
                fmt.Printf("FAIL: %v\n", err)
                return
        }
        fmt.Printf("Listening on %v; sleeping.\n", ln.Addr())
        select{}
}

Does not work:

$ ./listen 
FAIL: listen tcp :8080: socket: address family not supported by protocol

The problem is, favoriteAddrFamily sees that it can't use dual-stack sockets, and falls back to AF_INET without first checking supportsIPv4.

You can use "[::]:port" as a workaround, but ":port" ought to work. I'm preparing a patch for this.

@gopherbot

This comment has been minimized.

Copy link

commented Sep 5, 2015

CL https://golang.org/cl/14334 mentions this issue.

@gopherbot gopherbot closed this in 5a3ff6c Sep 5, 2015

@mikioh mikioh changed the title net.Listen("tcp", ":port") fails in an AF_INET6-only environment net: Listen("tcp", ":port") fails in an AF_INET6-only environment Sep 26, 2015

@mikioh mikioh added this to the Go1.6 milestone Sep 26, 2015

@golang golang locked and limited conversation to collaborators Sep 27, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.