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: net.Listen("tcp", "0.0.0.0:1234") also listens on IPv6 #17615

Closed
mikioh opened this issue Oct 26, 2016 · 4 comments
Closed

net: net.Listen("tcp", "0.0.0.0:1234") also listens on IPv6 #17615

mikioh opened this issue Oct 26, 2016 · 4 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mikioh
Copy link
Contributor

mikioh commented Oct 26, 2016

I was asked several times on golang-nuts, golang-dev or golang-codereviews like the following:
https://groups.google.com/d/msg/golang-dev/MvAlef3CTqk/DGs5sLBcCgAJ

@bradfitz
Copy link
Contributor

Please make bug reports self-contained. Don't link off to other threads for the majority of the information.

For the record:

Audrius Butkevicius asked:

Maybe I am completely missing out something, but here it goes:

I understand that net.Listen("tcp", ":1234") - is v4 and v6, as the stack is unspecified.
But why on earth is net.Listen("tcp", "0.0.0.0:1234") listening on v6 [::]:1234?
Yet why is net.Listen("tcp", "192.168.1.2:1234") only listening on v4, even if the same interface has a v6 address?

Most of the software I used (nginx for example) listens only on v4 when given 0.0.0.0, which I think makes perfect sense, as that means all v4 interfaces.
Same way it only listens to v6 when [::]:80 is specified.

This complicates matters, as I am making an application where the user can specify a listen address I either have to add -tcp4 or -tcp6 flags to work out the stack the user is interested in, or do a bunch of .IsIP4()/.isIP6() to work out the users actual intent from the provided 0.0.0.0 address.

Can someone shed some light on this?

Thanks.

@quentinmit quentinmit changed the title net: no docs about the behavior of announcing or listening on IP dual stack net: net.Listen("tcp", "0.0.0.0:1234") also listens on IPv6 Nov 1, 2016
@quentinmit quentinmit added NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. and removed Documentation labels Nov 1, 2016
@quentinmit quentinmit added this to the Go1.9 milestone Nov 1, 2016
@quentinmit
Copy link
Contributor

/cc @rsc

I think there is an implementation bug here; an IPv4 address should cause an IPv4 listener to be created, even if it's 0.0.0.0

That said... I can't imagine many users actually care about listening on all v4 interfaces but not v6 interfaces. They almost certainly want :1234 instead.

@mikioh
Copy link
Contributor Author

mikioh commented Nov 17, 2016

@quentinmit,

I don't think it's a good idea to mix two issues here. I just wanted to update documentation. Can you please open a new issue for the new behavior?

@bradfitz bradfitz added Documentation NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Jun 14, 2017
@gopherbot
Copy link

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

gopherbot pushed a commit that referenced this issue Jun 22, 2017
This change clarifies the documentation on Listen and ListenPacket to
avoid unnecessary confusion about how the arguments for the connection
setup functions are used to make connections.

Also replaces "name" or "hostname" with "host name" when the term
implies the use of DNS.

Updates #17613.
Updates #17614.
Updates #17615.
Fixes #17616.
Updates #17738.
Updates #17956.

Change-Id: I0bad2e143207666f2358d397fc076548ee6c3ae9
Reviewed-on: https://go-review.googlesource.com/34876
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@golang golang locked and limited conversation to collaborators Jun 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants