Skip to content

Commit 1744b71

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

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/syscall/syscall_windows.go

Lines changed: 11 additions & 4 deletions
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,10 +1098,16 @@ var connectExFunc struct {
10971098

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

0 commit comments

Comments
 (0)