mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-29 22:46:58 +00:00
Sockopt: Handle single-family interface binding on Windows, including TUN inbound's autoOutboundsInterface (#7214)
And https://github.com/XTLS/Xray-core/pull/7214#issuecomment-6329118637 https://github.com/XTLS/Xray-core/pull/7201#issuecomment-6314453444 Fixes https://github.com/XTLS/Xray-core/issues/7160#issuecomment-6246944012 --------- Co-authored-by: patterniha <71074308+patterniha@users.noreply.github.com>
This commit is contained in:
co-authored by
patterniha
parent
1576e79563
commit
3071fbfa25
@@ -2,6 +2,8 @@ package internet
|
||||
|
||||
import (
|
||||
"context"
|
||||
go_errors "errors"
|
||||
"runtime"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -92,6 +94,16 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
|
||||
}
|
||||
}
|
||||
packetConn, err := lc.ListenPacket(ctx, srcAddr.Network(), srcAddr.String())
|
||||
var bindErr *BindError
|
||||
if err != nil && runtime.GOOS == "windows" && go_errors.As(err, &bindErr) {
|
||||
// Keep dual-stack UDP when possible. If the interface cannot bind both
|
||||
// families, retry a socket that cannot send on the unbound family.
|
||||
network := "udp6"
|
||||
if destAddr.IP.To4() != nil {
|
||||
network = "udp4"
|
||||
}
|
||||
packetConn, err = lc.ListenPacket(ctx, network, srcAddr.String())
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user