<p dir="auto"><a href="https://github.com/golang/go/blob/master/src/net/ipsock.go#L204">https://github.com/golang/go/blob/master/src/net/ipsock.go#L204</a></p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="type addrList []Addr
func internetAddrList(net, addr string, deadline time.Time) (addrList, error)"><pre class="notranslate"><span class="pl-k">type</span> <span class="pl-smi">addrList</span> []<span class="pl-smi">Addr</span>
<span class="pl-k">func</span> <span class="pl-en">internetAddrList</span>(<span class="pl-s1">net</span>, <span class="pl-s1">addr</span> <span class="pl-smi">string</span>, <span class="pl-s1">deadline</span> time.<span class="pl-smi">Time</span>) (<span class="pl-smi">addrList</span>, <span class="pl-smi">error</span>)</pre></div>
<p dir="auto">However the internetAddrList only return one valid address.<br>
I proposal split addr string by "," and return REAL addrList.</p>
<p dir="auto">The following example program:</p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="package main

import (
        &quot;net&quot;
)

func main() {
        net.Listen(&quot;tcp&quot;, &quot;localhost:8080&quot;)
        select{}
}"><pre class="notranslate"><span class="pl-k">package</span> main

<span class="pl-k">import</span> (
        <span class="pl-s">"net"</span>
)

<span class="pl-k">func</span> <span class="pl-en">main</span>() {
        <span class="pl-s1">net</span>.<span class="pl-en">Listen</span>(<span class="pl-s">"tcp"</span>, <span class="pl-s">"localhost:8080"</span>)
        <span class="pl-k">select</span>{}
}</pre></div>
<p dir="auto">Currently yields this result:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ netstat -nl | grep 8080
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN"><pre class="notranslate"><code class="notranslate">$ netstat -nl | grep 8080
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN
</code></pre></div>
<p dir="auto">While the following result would be optimal:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ netstat -nl | grep 8080
tcp6       0      0 127.0.0.1:8080          :::*                    LISTEN
tcp6       0      0 ::1:8080                :::*                    LISTEN"><pre class="notranslate"><code class="notranslate">$ netstat -nl | grep 8080
tcp6       0      0 127.0.0.1:8080          :::*                    LISTEN
tcp6       0      0 ::1:8080                :::*                    LISTEN
</code></pre></div>
<p dir="auto">(Note that the first socket is actually dualstack, and bound to ::ffff:127.0.0.1, but that's less critical than adding the second socket bound to ::1.)</p>
<p dir="auto">More generally, when you call <code class="notranslate">net.Listen()</code> on a hostname which resolves to multiple IPv4/IPv6 addresses, only the first IPv4 address is selected.  An analogous problem occurs if you <code class="notranslate">Listen("tcp", ":8080")</code> on an operating system that doesn't support dualstack sockets: instead of returning a pair of sockets bound to <code class="notranslate">[::]:8080</code> and <code class="notranslate">0.0.0.0:80</code>, you only get IPv4.</p>
<p dir="auto">The fundamental flaw is that <code class="notranslate">Listen()</code> assumes a single socket, which is a leaky abstraction that's inappropriate for high-level things like example servers, e.g.:<br>
<a href="http://golang.org/pkg/net/#pkg-overview" rel="nofollow">http://golang.org/pkg/net/#pkg-overview</a></p>
<p dir="auto">Go should either adapt the <code class="notranslate">Listen()</code> API to support multiple sockets, or if that's not feasible, a new multi-socket API should be introduced, which deprecates <code class="notranslate">Listen()</code> for all cases except simple non-wildcard addresses.</p>