Commit 2899be81 authored by Mikio Hara's avatar Mikio Hara

net: avoid unnecessary conversion in address selection

Change-Id: I0d940810b493249bc092cd38bdb434f7fa67cafb
Reviewed-on: https://go-review.googlesource.com/12341Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent cc8f5441
......@@ -40,13 +40,16 @@ func sortByRFC6724withSrcs(addrs []IPAddr, srcs []IP) {
// number is irrelevant.
func srcAddrs(addrs []IPAddr) []IP {
srcs := make([]IP, len(addrs))
dst := UDPAddr{Port: 9}
for i := range addrs {
conn, err := Dial("udp", JoinHostPort(addrs[i].IP.String(), "1234"))
dst.IP = addrs[i].IP
dst.Zone = addrs[i].Zone
c, err := DialUDP("udp", nil, &dst)
if err == nil {
if ua, ok := conn.LocalAddr().(*UDPAddr); ok {
srcs[i] = ua.IP
if src, ok := c.LocalAddr().(*UDPAddr); ok {
srcs[i] = src.IP
}
conn.Close()
c.Close()
}
}
return srcs
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment