Skip to content

Commit 9cd9768

Browse files
committed
syscall: make LoadConnectEx not IPv4-specific on Windows
Fixes #29759
1 parent 3f94f3d commit 9cd9768

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/syscall/syscall_windows.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"internal/oserror"
1515
"internal/race"
1616
"internal/strconv"
17+
strings "internal/stringslite"
1718
"sync"
1819
"unsafe"
1920
)
@@ -1097,7 +1098,21 @@ var connectExFunc struct {
10971098

10981099
func LoadConnectEx() error {
10991100
connectExFunc.once.Do(func() {
1100-
var s Handle
1101+
var (
1102+
s Handle
1103+
err error
1104+
)
1105+
s, err = Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
1106+
if err != nil {
1107+
// This can occur when IPv4 is disabled. See https://go.dev/issue/29759.
1108+
if strings.Index(err.Error(), "address incompatible with the requested protocol was used") >= 0 {
1109+
s, err = Socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP)
1110+
}
1111+
connectExFunc.err = err
1112+
if err != nil {
1113+
return
1114+
}
1115+
}
11011116
s, connectExFunc.err = Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
11021117
if connectExFunc.err != nil {
11031118
return

0 commit comments

Comments
 (0)