mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-09-26 20:51:13 +08:00
ping: Fix missing bind for unix socket
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/sagernet/sing/common/control"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
@@ -74,6 +73,17 @@ func connect(privileged bool, controlFunc control.Func, destination netip.Addr)
|
||||
}
|
||||
}
|
||||
|
||||
var bindAddress netip.Addr
|
||||
if !destination.Is6() {
|
||||
bindAddress = netip.AddrFrom4([4]byte{0, 0, 0, 0})
|
||||
} else {
|
||||
bindAddress = netip.AddrFrom16([16]byte{})
|
||||
}
|
||||
err = unix.Bind(fd, M.AddrPortToSockaddr(netip.AddrPortFrom(bindAddress, 0)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = unix.Connect(fd, M.AddrPortToSockaddr(netip.AddrPortFrom(destination, 0)))
|
||||
if err != nil {
|
||||
return nil, E.Cause(err, "connect()")
|
||||
|
Reference in New Issue
Block a user