From 698bb3d702192eefd5a2c95713352a54673c4566 Mon Sep 17 00:00:00 2001 From: Cuthead <183076078+Cuthead@users.noreply.github.com> Date: Tue, 21 Apr 2026 09:44:36 +0000 Subject: [PATCH] fixup! Auto dual-stack. --- phantomtcp/phantom.go | 31 ++++++++++++++++--------------- phantomtcp/tcp.go | 2 +- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/phantomtcp/phantom.go b/phantomtcp/phantom.go index 5aa06ab..c6f2948 100755 --- a/phantomtcp/phantom.go +++ b/phantomtcp/phantom.go @@ -988,27 +988,28 @@ func CreateOutbounds(Outbounds []OutboundConfig) []string { } } } - - if outbound.Device != "" && Hint&HINT_IPV4 == 0 && Hint&HINT_IPV6 == 0 { - ip6, _ := GetLocalTCPAddr(outbound.Device, true) - if ip6 != nil { - Hint |= HINT_IPV6 - } - ip4, _ := GetLocalTCPAddr(outbound.Device, false) - if ip4 != nil { - Hint |= HINT_IPV4 - } - } - - if Hint&HINT_IPV4 == 0 && Hint&HINT_IPV6 == 0 { - Hint |= HINT_IPV4 - } _, ok := OutboundsMap[outbound.Device] if !ok && !contains(devices, outbound.Device) { devices = append(devices, outbound.Device) } } + + if outbound.Device != "" && Hint&HINT_IPV4 == 0 && Hint&HINT_IPV6 == 0 { + ip6, _ := GetLocalTCPAddr(outbound.Device, true) + if ip6 != nil { + outbound.Hint |= HINT_IPV6 + } + ip4, _ := GetLocalTCPAddr(outbound.Device, false) + if ip4 != nil { + outbound.Hint |= HINT_IPV4 + } + } + + if Hint&HINT_IPV4 == 0 && Hint&HINT_IPV6 == 0 { + outbound.Hint |= HINT_IPV4 + } + } default_outbound, ok := OutboundsMap["default"] diff --git a/phantomtcp/tcp.go b/phantomtcp/tcp.go index f769172..2062609 100755 --- a/phantomtcp/tcp.go +++ b/phantomtcp/tcp.go @@ -75,7 +75,7 @@ func GetLocalTCPAddr(name string, ipv6 bool) (*net.TCPAddr, error) { if !ok || len(localAddr.IP) != 16{ continue } - if localAddr.IP[0] != 0 && (localAddr.IP[0] != 0xfe && localAddr.IP[1]&0xc0 == 0x80) { + if localAddr.IP[0] != 0 && !localAddr.IP.IsLinkLocalUnicast() { ip := make([]byte, 16) copy(ip[:16], localAddr.IP) addr6 = &net.TCPAddr{IP: ip[:], Port: 0}