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:
Eliot the Cougar
2026-10-28 10:15:58 +00:00
committed by GitHub
co-authored by patterniha
parent 1576e79563
commit 3071fbfa25
4 changed files with 110 additions and 1 deletions
+10
View File
@@ -2,6 +2,7 @@ package localdns
import (
"context"
"net/netip"
"syscall"
"time"
@@ -100,6 +101,15 @@ func New() *Client {
if internet.IsSkippedDNSServer(address) {
return nil, errors.New("skipped DNS server ", address)
}
// A socket of the server's IP version only needs that version bound
// to the interface, which a dual-stack one would need both of.
if ap, err := netip.ParseAddrPort(address); err == nil && (network == "udp" || network == "tcp") {
if ap.Addr().Unmap().Is4() {
network += "4"
} else {
network += "6"
}
}
return d.DialContext(ctx, network, address)
},
}