mirror of
https://github.com/golang/go
synced 2024-11-26 20:21:25 -07:00
net: avoid unnecessary conversion in address selection
Change-Id: I0d940810b493249bc092cd38bdb434f7fa67cafb Reviewed-on: https://go-review.googlesource.com/12341 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
cc8f544198
commit
2899be8120
@ -40,13 +40,16 @@ func sortByRFC6724withSrcs(addrs []IPAddr, srcs []IP) {
|
|||||||
// number is irrelevant.
|
// number is irrelevant.
|
||||||
func srcAddrs(addrs []IPAddr) []IP {
|
func srcAddrs(addrs []IPAddr) []IP {
|
||||||
srcs := make([]IP, len(addrs))
|
srcs := make([]IP, len(addrs))
|
||||||
|
dst := UDPAddr{Port: 9}
|
||||||
for i := range addrs {
|
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 err == nil {
|
||||||
if ua, ok := conn.LocalAddr().(*UDPAddr); ok {
|
if src, ok := c.LocalAddr().(*UDPAddr); ok {
|
||||||
srcs[i] = ua.IP
|
srcs[i] = src.IP
|
||||||
}
|
}
|
||||||
conn.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return srcs
|
return srcs
|
||||||
|
Loading…
Reference in New Issue
Block a user