mirror of
https://github.com/ccding/go-stun.git
synced 2025-09-26 21:15:52 +08:00
fix: add option to use fixed port for BehaviorTest (#48)
This commit is contained in:
@@ -126,7 +126,14 @@ func (c *Client) BehaviorTest() (*NATBehavior, error) {
|
||||
// create a connection and close it at the end.
|
||||
conn := c.conn
|
||||
if conn == nil {
|
||||
conn, err = net.ListenUDP("udp", nil)
|
||||
var laddr *net.UDPAddr
|
||||
if c.localPort != 0 {
|
||||
laddr, err = net.ResolveUDPAddr("udp", fmt.Sprintf(":%d", c.localPort))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
conn, err = net.ListenUDP("udp", laddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user