Unfortunately, net.Listen and net.ListenTCP accept IPv6 IPv4-mapped
literal addresses/wire formats from its first public release.
Moreover, the net package will probably support more funky
literals/wire formats when necessary. Until now, the package handles
any unspecified address as unspecified/wildcard one for avoiding
failing to listen to unspecified addresses on either v6only=1 or
v6only=0 platforms.
For example, when you run
https://github.com/mikioh/-stdyng/blob/master/cmd/dstklstnr/main.go on
the platform which supports v6only=1, you may see:
string: "",
0.0.0.0:51100
string: "0.0.0.0",
0.0.0.0:51102
string: "::ffff:0.0.0.0",
0.0.0.0:51104
string: "::ffff:0:0",
0.0.0.0:51106
string: "::", [::]:51108
net.IP: <nil>,
0.0.0.0:51110
net.IP: 0.0.0.0,
0.0.0.0:51112
net.IP: 0.0.0.0,
0.0.0.0:51114
net.IP: ::, [::]:51116
and on the platform w/ v6only=0:
string: "", [::]:44866
string: "0.0.0.0", [::]:44961
string: "::ffff:0.0.0.0", [::]:43029
string: "::ffff:0:0", [::]:45798
string: "::", [::]:41708
net.IP: <nil>, [::]:42962
net.IP: 0.0.0.0, [::]:40105
net.IP: 0.0.0.0, [::]:32980
net.IP: ::, [::]:41915
If you have a suggestion, like "we should distinguish both IPv4 and
IPv6 unspecified address literals/wire formats from the entire
unspecified IP literals/wire formats for the benefit of X even though
it has the disadvantage of Y and the future disadvantage of Z ",
please file a new issue as a proposal:
https://github.com/golang/proposal.
For what it's worth, there are various platforms with regard to Pv6
IPv4-mapped address-related functionality:
- Darwin, FreeBSD, Linux, NetBSD, Windows; they are optimistic v6only
support kernels and still allow customer applications to configure
IPv6 IPv4-mapped address-related functionality,
- OpenBSD, DragonFly BSD; they never allow to use Pv6 IPv4-mapped
address-related functionality.