1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-03-16 19:35:31 -04:00

move port allocation to udp package

This commit is contained in:
Darien Raymond
2017-11-14 23:45:07 +01:00
parent 268d7264e8
commit a430e2065a
4 changed files with 22 additions and 15 deletions

View File

@@ -0,0 +1,18 @@
package udp
import (
"v2ray.com/core/common"
"v2ray.com/core/common/net"
)
func PickPort() net.Port {
conn, err := net.ListenUDP("udp4", &net.UDPAddr{
IP: net.LocalHostIP.IP(),
Port: 0,
})
common.Must(err)
defer conn.Close()
addr := conn.LocalAddr().(*net.UDPAddr)
return net.Port(addr.Port)
}