Skip to content

Commit ce55929

Browse files
committed
ping: Fix missing bind for unix socket
1 parent 144683d commit ce55929

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ping/socket_unix.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/sagernet/sing/common/control"
1313
E "github.com/sagernet/sing/common/exceptions"
1414
M "github.com/sagernet/sing/common/metadata"
15-
1615
"golang.org/x/sys/unix"
1716
)
1817

@@ -74,6 +73,17 @@ func connect(privileged bool, controlFunc control.Func, destination netip.Addr)
7473
}
7574
}
7675

76+
var bindAddress netip.Addr
77+
if !destination.Is6() {
78+
bindAddress = netip.AddrFrom4([4]byte{0, 0, 0, 0})
79+
} else {
80+
bindAddress = netip.AddrFrom16([16]byte{})
81+
}
82+
err = unix.Bind(fd, M.AddrPortToSockaddr(netip.AddrPortFrom(bindAddress, 0)))
83+
if err != nil {
84+
return nil, err
85+
}
86+
7787
err = unix.Connect(fd, M.AddrPortToSockaddr(netip.AddrPortFrom(destination, 0)))
7888
if err != nil {
7989
return nil, E.Cause(err, "connect()")

0 commit comments

Comments
 (0)