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:
18
testing/servers/udp/port.go
Normal file
18
testing/servers/udp/port.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user