mirror of
https://git.zx2c4.com/wireguard-go
synced 2024-11-15 01:05:15 +01:00
conn: use local ipvN vars in StdNetBind.Open
This makes it clearer that they are fresh on each attempt, and avoids the bookkeeping required to clearing them on failure. Also, remove an unnecessary err != nil. Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
parent
822f5a6d70
commit
204140016a
@ -91,30 +91,28 @@ func (bind *StdNetBind) Open(uport uint16) (uint16, error) {
|
||||
|
||||
again:
|
||||
port := int(uport)
|
||||
var ipv4, ipv6 *net.UDPConn
|
||||
|
||||
bind.ipv4, port, err = listenNet("udp4", port)
|
||||
ipv4, port, err = listenNet("udp4", port)
|
||||
if err != nil && !errors.Is(err, syscall.EAFNOSUPPORT) {
|
||||
bind.ipv4 = nil
|
||||
return 0, err
|
||||
}
|
||||
|
||||
bind.ipv6, port, err = listenNet("udp6", port)
|
||||
if uport == 0 && err != nil && errors.Is(err, syscall.EADDRINUSE) && tries < 100 {
|
||||
bind.ipv4.Close()
|
||||
bind.ipv4 = nil
|
||||
bind.ipv6 = nil
|
||||
ipv6, port, err = listenNet("udp6", port)
|
||||
if uport == 0 && errors.Is(err, syscall.EADDRINUSE) && tries < 100 {
|
||||
ipv4.Close()
|
||||
tries++
|
||||
goto again
|
||||
}
|
||||
if err != nil && !errors.Is(err, syscall.EAFNOSUPPORT) {
|
||||
bind.ipv4.Close()
|
||||
bind.ipv4 = nil
|
||||
bind.ipv6 = nil
|
||||
ipv4.Close()
|
||||
return 0, err
|
||||
}
|
||||
if bind.ipv4 == nil && bind.ipv6 == nil {
|
||||
if ipv4 == nil && ipv6 == nil {
|
||||
return 0, syscall.EAFNOSUPPORT
|
||||
}
|
||||
bind.ipv4 = ipv4
|
||||
bind.ipv6 = ipv6
|
||||
return uint16(port), nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user