fix: fix bindIfaceToListenConfig() in windows force bind to an ipv4 address

This commit is contained in:
wwqgtxx
2022-12-13 11:18:32 +08:00
parent f87144f84b
commit 88acf8e098
9 changed files with 34 additions and 30 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt"
"net"
"net/netip"
"runtime"
"strings"
"sync"
@ -24,6 +25,17 @@ var (
ErrorDisableIPv6 = errors.New("IPv6 is disabled, dialer cancel")
)
func ParseNetwork(network string, addr netip.Addr) string {
if runtime.GOOS == "windows" { // fix bindIfaceToListenConfig() in windows force bind to an ipv4 address
if !strings.HasSuffix(network, "4") &&
!strings.HasSuffix(network, "6") &&
addr.Unmap().Is6() {
network += "6"
}
}
return network
}
func ApplyOptions(options ...Option) *option {
opt := &option{
interfaceName: DefaultInterface.Load(),