mirror of
https://github.com/golang/go
synced 2024-11-22 22:20:03 -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.
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user